public boolean isTranslated(String locale) { return translations.get(new TranslationId(entityId, locale)) != null; }
/** * Returns the translation set. * * @return the translations */ public Map<String, Translation> getTranslations() { Map<String, Translation> map = new HashMap<>(); for (Map.Entry<TranslationId, Translation> translationEntry : translations.entrySet()) { map.put(translationEntry.getKey().getLocale(), translationEntry.getValue()); } return map; }
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); }
@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 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; }
@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()); } }
/** * 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 * @param approximate translation approximate indicator * @param outdated translation outdated indicator * @throws java.lang.IllegalArgumentException if locale is blank */ public void addTranslation(String locale, String value, boolean approximate, boolean outdated) { Preconditions.checkArgument(StringUtils.isNotBlank(locale)); // If exists, get the translation for the given locale Translation translation = this.translations.get(locale); if (translation == null) { translation = new Translation(); translation.setEntityId(new TranslationId(entityId, locale)); } translation.setValue(value); translation.setApproximate(approximate); translation.setOutdated(outdated); translation.setKey(this); translations.put(locale, translation); updateOutdated(); }