private Optional<String> getTranslationWithFallback(String locale, Key key) { for (String parentLocale : getParentLocalesFor(new ULocale(locale))) { if (key.isTranslated(parentLocale)) { return Optional.of(key.getTranslation(parentLocale).getValue()); } } if (i18nConfig.isTranslationFallback()) { String defaultLocale = localeService.getDefaultLocale(); if (key.isTranslated(defaultLocale)) { return Optional.of(key.getTranslation(defaultLocale).getValue()); } } return Optional.empty(); }
private void assembleSourceTranslation(TranslationRepresentation representation, Key key) { String defaultLocale = localeService.getDefaultLocale(); if (defaultLocale != null && key.isTranslated(defaultLocale)) { TranslationValueRepresentation source = assembleTranslation(key, defaultLocale); representation.setSource(source); } }
private void assembleTargetTranslation(TranslationRepresentation representation, Key key, String locale) { if (key.isTranslated(locale)) { TranslationValueRepresentation source = assembleTranslation(key, locale); representation.setTarget(source); } else { representation.setMissing(true); } }
private Translation createOrUpdateTranslation(String locale, String value, boolean isApproximate) { Translation translation; if (isTranslated(locale)) { translation = this.translations.get(new TranslationId(entityId, locale)); translation.updateValue(value); } else { translation = new Translation(new TranslationId(entityId, locale), value); } translation.setApproximate(isApproximate); translations.put(new TranslationId(entityId, locale), translation); return translation; }
private void assembleDefaultTranslation(Key key, KeyRepresentation keyRepresentation, String defaultLocale) { if (key.isTranslated(defaultLocale)) { Translation translation = key.getTranslation(defaultLocale); keyRepresentation.setTranslation(translation.getValue()); keyRepresentation.setApprox(translation.isApproximate()); } else { keyRepresentation.setMissing(true); } } }
private void addKeyWithTranslationsToFile(Key key, CSVRowWriter csvRowWriter) { for (String columnName : csvRowWriter.getColumnNames()) { if (isColumnKey(columnName)) { csvRowWriter.addColumnValue(I18nCSVTemplateLoader.KEY, key.getId()); } else { if (key.isTranslated(columnName)) { csvRowWriter.addColumnValue(columnName, key.getTranslation(columnName).getValue()); } } } }