@Override public List<TranslationRepresentation> findTranslations(String localeId) { return translationLocaleAssembler.assemble(keyRepository.loadAll(), localeId); }
@Override public Iterator<KeyDTO> exportData() { return fluentAssembler.assemble(keyRepository.loadAll()).to(KeyDTO.class).iterator(); } }
/** * Streams a CSV file with all keys with their translations. * * @return an i18n.csv file */ @GET @Produces(MediaType.TEXT_PLAIN) @RequiresPermissions(I18nPermissions.KEY_READ) public Response exportTranslations() { final List<Key> keys = keyRepository.loadAll(); return Response.ok(new StreamingOutput() { private boolean isFirstLine = true; @Override public void write(OutputStream os) throws IOException { Writer writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); for (Key key : keys) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); renderer.render(byteArrayOutputStream, key, APPLICATION_CSV, printHeader(isFirstLine)); writer.write(byteArrayOutputStream.toString("UTF-8")); isFirstLine = false; } writer.flush(); } }).header(CONTENT_DISPOSITION, ATTACHMENT_FILENAME_I18N_CSV).build(); }
@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 public void commit(boolean clear) { if (clear) { LOGGER.info("Clear i18n key repository"); for (Key key : keyRepository.loadAll()) { keyRepository.delete(key); } } LOGGER.info("staging size: " + staging.size()); for (KeyDTO keyDTO : staging) { try { Key key = fluentAssembler.merge(keyDTO).into(Key.class).fromFactory(); keyRepository.persist(key); } catch (RuntimeException e) { LOGGER.error(e.getMessage(), e); throw e; } } LOGGER.info("Import of i18n key completed"); staging.clear(); }
@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; } }
.getCode()) .orElseThrow(() -> new IllegalArgumentException("Locale not found " + localeRepresentation.getCode())); List<Key> keys = keyRepository.loadAll(); if (keys != null) { int translatedCount = 0;