/** * Returns the translation corresponding to the given locale code. * * @param locale locale code * @return translation * @throws java.lang.IllegalArgumentException if locale is blank */ public Translation getTranslation(String locale) { Preconditions.checkArgument(StringUtils.isNotBlank(locale), "The locale should not be blank"); return this.getTranslations().get(locale); }
/** * Remove the translation corresponding to the given locale code. * * @param locale locale code * @throws java.lang.IllegalArgumentException if locale is blank */ public void removeTranslation(String locale) { Preconditions.checkArgument(StringUtils.isNotBlank(locale)); Translation translation = getTranslation(locale); if (translation != null) { this.getTranslations().remove(translation); } }
/** * Returns the translation corresponding to the given locale code. * * @param locale locale code * @return the translation * @throws java.lang.IllegalArgumentException if the locale is null or empty * or contains other characters than letters and "-". */ public Translation getTranslation(String locale) { LocaleCodeSpecification.assertCode(locale); return this.getTranslations().get(locale); }
@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); }
@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()); } }
@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()); } }