@Override public Map<String, String> getTranslationsForLocale(String locale) { Map<String, String> translations = new HashMap<>(); for (Key key : keyRepository.loadAll()) { Optional<String> translation = getTranslationWithFallback(locale, key); if (translation.isPresent() || !i18nConfig.isAllowMissingTranslations()) { translations.put(key.getId(), translation.orElse("[" + key.getId() + "]")); } } return translations; }
@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 void assembleKeyInfo(Key key, TranslationRepresentation representation) { representation.setName(key.getId()); representation.setComment(key.getComment()); }
/** * Inserts a key with the translation in the default language. * * @param keyRepresentation key representation * @return 201 if the resource is created, 409 if the resource already existed */ @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @RequiresPermissions(I18nPermissions.KEY_WRITE) public Response createKey(KeyRepresentation keyRepresentation) throws URISyntaxException { WebAssertions.assertNotNull(keyRepresentation, THE_KEY_SHOULD_NOT_BE_NULL); WebAssertions.assertNotBlank(keyRepresentation.getName(), THE_KEY_SHOULD_CONTAINS_A_NAME); WebAssertions.assertNotBlank(keyRepresentation.getDefaultLocale(), THE_KEY_SHOULD_CONTAINS_A_LOCALE); assertKeyDoNotAlreadyExists(keyRepresentation); Key key = factory.createKey(keyRepresentation.getName()); key.setComment(keyRepresentation.getComment()); addDefaultTranslation(keyRepresentation, key); keyRepository.add(key); return Response.created(new URI(uriInfo.getRequestUri() + "/" + key.getId())) .entity(keyFinder.findKeyWithName(key.getId())).build(); }
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()); } } } }
@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 public KeyRepresentation assemble(Key key) { KeyRepresentation keyRepresentation = new KeyRepresentation(); keyRepresentation.setName(key.getId()); keyRepresentation.setComment(key.getComment()); keyRepresentation.setOutdated(key.isOutdated()); String defaultLocale = localeService.getDefaultLocale(); keyRepresentation.setDefaultLocale(defaultLocale); assembleDefaultTranslation(key, keyRepresentation, defaultLocale); return keyRepresentation; }