private boolean translationHasChanged(Key targetKey, String localeCode, String translationValue) { Translation translation = targetKey.getTranslation(localeCode); return translation == null || !translation.getValue().equals(translationValue); } }
private boolean translationHasChanged(Key key, String locale, String newTranslation) { Translation translation = key.getTranslation(locale); return translation == null || !newTranslation.equals(translation.getValue()); }
@Override protected void doAssembleDtoFromAggregate(CSVRepresentation targetDto, Key sourceEntity) { targetDto.setKey(sourceEntity.getId()); Map<String, String> translations = new HashMap<>(); for (Map.Entry<String, Translation> entry : sourceEntity.getTranslations().entrySet()) { translations.put(entry.getKey(), entry.getValue().getValue()); } targetDto.setValue(translations); }
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(); }
@Override public Map<String, String> getTranslationsForLocale(String locale) { ICUBasedLocalizationService icuBasedLocalizationService = (ICUBasedLocalizationService) localizationService; Map<String, String> translations = new HashMap<String, String>(); List<ULocale> localeIterator = icuBasedLocalizationService.getParentLocale(new ULocale(locale)); for (Key key : keyRepository.loadAll()) { Translation translation = icuBasedLocalizationService.getTranslationWithFallBack(key, localeIterator); if (translation != null) { translations.put(key.getEntityId(), translation.getValue()); } } return translations; } }
@Override public String localize(String locale, String key, Object... args) { ULocale closestLocale = localeService.getClosestULocale(locale); Key loadedKey = keyRepository.load(key); String localizedString; if (loadedKey == null) { localizedString = '[' + key + ']'; } else { // TODO business logic to search in other locales List<ULocale> localeIterator = getParentLocale(closestLocale); Translation translation = getTranslationWithFallBack(loadedKey, localeIterator); if (translation == null) { localizedString = '[' + key + ']'; } else if (ArrayUtils.isEmpty(args)) { localizedString = translation.getValue(); } else { MessageFormat mf = new MessageFormat(translation.getValue(), closestLocale); localizedString = mf.format(args); } } return localizedString; }
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); } } }
.getId()); if (translation != null && StringUtils.isNotBlank(translation.getValue())) { translatedCount++;
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()); } } } }
private TranslationValueRepresentation assembleTranslation(Key key, String locale) { TranslationValueRepresentation source = new TranslationValueRepresentation(); source.setLocale(locale); Translation translation = key.getTranslation(locale); source.setTranslation(translation.getValue()); source.setApprox(translation.isApproximate()); source.setOutdated(translation.isOutdated()); return source; }
@Override public void mergeAggregateIntoDto(Key sourceAggregate, KeyDTO targetDto) { targetDto.setName(sourceAggregate.getId()); targetDto.setComment(sourceAggregate.getComment()); targetDto.setOutdated(sourceAggregate.isOutdated()); for (Translation tln : sourceAggregate.getTranslations().values()) { targetDto.addTranslationDTO(tln.getId().getLocale(), tln.getValue(), tln.isOutdated(), tln.isApproximate()); } }
@Override protected void doAssembleDtoFromAggregate(KeyDTO targetDto, Key sourceEntity) { targetDto.setName(sourceEntity.getEntityId()); targetDto.setComment(sourceEntity.getComment()); targetDto.setOutdated(sourceEntity.isOutdated()); for (Translation tln : sourceEntity.getTranslations().values()) { targetDto.addTranslationDTO(tln.getEntityId().getLocale(), tln.getValue(), tln.isOutdated(), tln.isApproximate()); } }