@Override public Key createKey(String name) { return new Key(name); } }
@Override public Key createKey(String name, String comment, boolean outdated) { Key key = new Key(); key.setEntityId(name); key.setComment(comment); key.setOutdated(outdated); return key; }
@Override public Key createKey(String name) { Key key = new Key(); key.setEntityId(name); return key; }
@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()); } }
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; }
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 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 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 boolean translationHasChanged(Key targetKey, String localeCode, String translationValue) { Translation translation = targetKey.getTranslation(localeCode); return translation == null || !translation.getValue().equals(translationValue); } }
private void addTranslation(Map<String, Translation> translations, Key key, String locale) { Translation source = this.translations.get(locale); if (source == null) { source = new Translation(new TranslationId(key.entityId, locale), key, "", false, false); } translations.put(locale, source); }
/** * Saves or updates the translation for the specified locale. * If the key was outdated, checks if the key is still outdated. * * @param locale specified the translation locale * @param value translation value * @return the new translation * @throws java.lang.IllegalArgumentException if the locale is null or empty * or contains other characters than letters and "-". */ public Translation addTranslation(String locale, String value) { return addTranslation(locale, value, false); }
/** * Checks if the key has outdated translation * and then update the outdated indicator of the key. */ public void updateOutdated() { outdated = false; for (Translation translation : translations.values()) { if (translation.isOutdated()) { outdated = true; } } }
Translation getTranslationWithFallBack(Key loadedKey, List<ULocale> localeIterator) { Translation translation = null; for (ULocale uLocale : localeIterator) { translation = loadedKey.getTranslation(uLocale.getBaseName()); if (translation != null) { break; } } return translation; }
@Override public void clear() { logger.info("Clearing all i18n keys"); keyRepository.clear(); }
/** * Marks the key and all its translations as outdated. */ public void setOutdated() { this.outdated = true; for (Translation translation : this.translations.values()) { translation.setOutdated(); } }
@Override public boolean isInitialized() { return !keyRepository.isEmpty(); }
@Override public boolean isInitialized() { boolean initialized = keyRepository.count() != 0; if(initialized) { LOGGER.info("i18n keys already initialized"); } else { LOGGER.info("i18n keys not initialized"); } return initialized; }
private boolean translationHasChanged(Key key, String locale, String newTranslation) { Translation translation = key.getTranslation(locale); return translation == null || !newTranslation.equals(translation.getValue()); }
private void addDefaultTranslation(KeyRepresentation keyRepresentation, Key key) { String defaultLocale = keyRepresentation.getDefaultLocale(); String translation = keyRepresentation.getTranslation(); boolean approx = keyRepresentation.isApprox(); key.addTranslation(defaultLocale, translation, approx); }