@Test public void testImportXls() throws IOException, URISyntaxException { final Path propertiesRootDirectory= this.tmpFolder.newFolder().toPath(); final FileMatcher fileMatcher= new FileMatcher(propertiesRootDirectory, new String[]{"**/*.properties"}, new String[]{""}); final File xlsFile= new File(Resources.getResource("i18n_expected.xlsx").toURI()); XlsImExporter.importXls(fileMatcher, xlsFile, UTF_8, MissingKeyAction.NOTHING); final Path[] writtenResourceBundleFiles = Files.list(propertiesRootDirectory.resolve("i18n")).toArray(Path[]::new); assertThat(writtenResourceBundleFiles).containsOnly( propertiesRootDirectory.resolve("i18n/messages.properties"), propertiesRootDirectory.resolve("i18n/messages_de.properties") ); assertThat(propertiesRootDirectory.resolve("i18n").resolve("messages.properties").toFile()) .hasSameContentAs(propertiesRootDirectory.resolve("i18n").resolve("messages.properties").toFile()); assertThat(propertiesRootDirectory.resolve("i18n").resolve("messages_de.properties").toFile()) .hasSameContentAs(propertiesRootDirectory.resolve("i18n").resolve("messages_de.properties").toFile()); }
public static void importXls(final FileMatcher fileMatcher, final File xlsFile, final Charset propertyFileEncoding, final MissingKeyAction missingKeyAction) { Require.nonNull(fileMatcher); Require.nonNull(xlsFile); final ApronOptions apronOptions= ApronOptions.create() .with(propertyFileEncoding != null ? propertyFileEncoding : UTF_8) .with(missingKeyAction); final XlsFile xlsFileObject= new XlsFile(xlsFile); final Map<I18nBundleKey, Collection<Translation>> content= xlsFileObject.getContent(); final Map<String, Map<Language, RememberingPropertyFile>> bundleFileMapping= new LinkedHashMap<>(); content.entrySet().forEach((entry) -> { final I18nBundleKey bundleKey= entry.getKey(); final String bundleBasename= bundleKey.getBundleBaseName(); final String propertyKey= bundleKey.getKey(); final Collection<Translation> translations= entry.getValue(); for (final Translation translation : translations) { if (!bundleFileMapping.containsKey(bundleBasename)) { bundleFileMapping.put(bundleBasename, new LinkedHashMap<>()); } if (!bundleFileMapping.get(bundleBasename).containsKey(translation.getLang())) { final File fileForBundle= getFileForBundle(fileMatcher.getRoot().toFile(), bundleBasename, translation.getLang()); if (!fileMatcher.matches(fileForBundle.toPath())) { LOGGER.log(Level.DEBUG, "Skipping import to file {} since it does not match inclusion pattern", fileForBundle); continue; } final PropertyFile propertyFile= new PropertyFile(); bundleFileMapping.get(bundleBasename).put(translation.getLang(), new RememberingPropertyFile(fileForBundle, propertyFile)); } final RememberingPropertyFile rpf= bundleFileMapping.get(bundleBasename).get(translation.getLang()); if ((translation.getValue() != null && !translation.getValue().isEmpty()) || rpf.propertyFile.containsKey(propertyKey)) { rpf.propertyFile.setValue(propertyKey, translation.getValue()); } } }); bundleFileMapping.values().forEach((Map<Language, RememberingPropertyFile> langPropMap) -> { langPropMap.values().forEach((RememberingPropertyFile rpf) -> { if (rpf.propertyFile.propertiesSize()> 0) { rpf.propertyFile.saveTo(rpf.actualFile, apronOptions); } }); }); }
XlsImExporter { public static void importXls(final FileMatcher fileMatcher, final File xlsFile, final Charset propertyFileEncoding, final MissingKeyAction missingKeyAction) { Require.nonNull(fileMatcher); Require.nonNull(xlsFile); final ApronOptions apronOptions= ApronOptions.create() .with(propertyFileEncoding != null ? propertyFileEncoding : UTF_8) .with(missingKeyAction); final XlsFile xlsFileObject= new XlsFile(xlsFile); final Map<I18nBundleKey, Collection<Translation>> content= xlsFileObject.getContent(); final Map<String, Map<Language, RememberingPropertyFile>> bundleFileMapping= new LinkedHashMap<>(); content.entrySet().forEach((entry) -> { final I18nBundleKey bundleKey= entry.getKey(); final String bundleBasename= bundleKey.getBundleBaseName(); final String propertyKey= bundleKey.getKey(); final Collection<Translation> translations= entry.getValue(); for (final Translation translation : translations) { if (!bundleFileMapping.containsKey(bundleBasename)) { bundleFileMapping.put(bundleBasename, new LinkedHashMap<>()); } if (!bundleFileMapping.get(bundleBasename).containsKey(translation.getLang())) { final File fileForBundle= getFileForBundle(fileMatcher.getRoot().toFile(), bundleBasename, translation.getLang()); if (!fileMatcher.matches(fileForBundle.toPath())) { LOGGER.log(Level.DEBUG, "Skipping import to file {} since it does not match inclusion pattern", fileForBundle); continue; } final PropertyFile propertyFile= new PropertyFile(); bundleFileMapping.get(bundleBasename).put(translation.getLang(), new RememberingPropertyFile(fileForBundle, propertyFile)); } final RememberingPropertyFile rpf= bundleFileMapping.get(bundleBasename).get(translation.getLang()); if ((translation.getValue() != null && !translation.getValue().isEmpty()) || rpf.propertyFile.containsKey(propertyKey)) { rpf.propertyFile.setValue(propertyKey, translation.getValue()); } } }); bundleFileMapping.values().forEach((Map<Language, RememberingPropertyFile> langPropMap) -> { langPropMap.values().forEach((RememberingPropertyFile rpf) -> { if (rpf.propertyFile.propertiesSize()> 0) { rpf.propertyFile.saveTo(rpf.actualFile, apronOptions); } }); }); } }
XlsImExporter { public static void importXls(final FileMatcher fileMatcher, final File xlsFile, final Charset propertyFileEncoding, final MissingKeyAction missingKeyAction) { Require.nonNull(fileMatcher); Require.nonNull(xlsFile); final ApronOptions apronOptions= ApronOptions.create() .with(propertyFileEncoding != null ? propertyFileEncoding : UTF_8) .with(missingKeyAction); final XlsFile xlsFileObject= new XlsFile(xlsFile); final Map<I18nBundleKey, Collection<Translation>> content= xlsFileObject.getContent(); final Map<String, Map<Language, RememberingPropertyFile>> bundleFileMapping= new LinkedHashMap<>(); content.entrySet().forEach((entry) -> { final I18nBundleKey bundleKey= entry.getKey(); final String bundleBasename= bundleKey.getBundleBaseName(); final String propertyKey= bundleKey.getKey(); final Collection<Translation> translations= entry.getValue(); for (final Translation translation : translations) { if (!bundleFileMapping.containsKey(bundleBasename)) { bundleFileMapping.put(bundleBasename, new LinkedHashMap<>()); } if (!bundleFileMapping.get(bundleBasename).containsKey(translation.getLang())) { final File fileForBundle= getFileForBundle(fileMatcher.getRoot().toFile(), bundleBasename, translation.getLang()); if (!fileMatcher.matches(fileForBundle.toPath())) { LOGGER.log(Level.DEBUG, "Skipping import to file {} since it does not match inclusion pattern", fileForBundle); continue; } final PropertyFile propertyFile= new PropertyFile(); bundleFileMapping.get(bundleBasename).put(translation.getLang(), new RememberingPropertyFile(fileForBundle, propertyFile)); } final RememberingPropertyFile rpf= bundleFileMapping.get(bundleBasename).get(translation.getLang()); if ((translation.getValue() != null && !translation.getValue().isEmpty()) || rpf.propertyFile.containsKey(propertyKey)) { rpf.propertyFile.setValue(propertyKey, translation.getValue()); } } }); bundleFileMapping.values().forEach((Map<Language, RememberingPropertyFile> langPropMap) -> { langPropMap.values().forEach((RememberingPropertyFile rpf) -> { if (rpf.propertyFile.propertiesSize()> 0) { rpf.propertyFile.saveTo(rpf.actualFile, apronOptions); } }); }); }  }
XlsImExporter { public static void importXls(final FileMatcher fileMatcher, final File xlsFile, final Charset propertyFileEncoding, final MissingKeyAction missingKeyAction) { Require.nonNull(fileMatcher); Require.nonNull(xlsFile); final ApronOptions apronOptions= ApronOptions.create() .with(propertyFileEncoding != null ? propertyFileEncoding : UTF_8) .with(missingKeyAction); final XlsFile xlsFileObject= new XlsFile(xlsFile); final Map<I18nBundleKey, Collection<Translation>> content= xlsFileObject.getContent(); final Map<String, Map<Language, RememberingPropertyFile>> bundleFileMapping= new LinkedHashMap<>(); content.entrySet().forEach((entry) -> { final I18nBundleKey bundleKey= entry.getKey(); final String bundleBasename= bundleKey.getBundleBaseName(); final String propertyKey= bundleKey.getKey(); final Collection<Translation> translations= entry.getValue(); for (final Translation translation : translations) { if (!bundleFileMapping.containsKey(bundleBasename)) { bundleFileMapping.put(bundleBasename, new LinkedHashMap<>()); } if (!bundleFileMapping.get(bundleBasename).containsKey(translation.getLang())) { final File fileForBundle= getFileForBundle(fileMatcher.getRoot().toFile(), bundleBasename, translation.getLang()); if (!fileMatcher.matches(fileForBundle.toPath())) { LOGGER.log(Level.DEBUG, "Skipping import to file {} since it does not match inclusion pattern", fileForBundle); continue; } final PropertyFile propertyFile= new PropertyFile(); bundleFileMapping.get(bundleBasename).put(translation.getLang(), new RememberingPropertyFile(fileForBundle, propertyFile)); } final RememberingPropertyFile rpf= bundleFileMapping.get(bundleBasename).get(translation.getLang()); if ((translation.getValue() != null && !translation.getValue().isEmpty()) || rpf.propertyFile.containsKey(propertyKey)) { rpf.propertyFile.setValue(propertyKey, translation.getValue()); } } }); bundleFileMapping.values().forEach((Map<Language, RememberingPropertyFile> langPropMap) -> { langPropMap.values().forEach((RememberingPropertyFile rpf) -> { if (rpf.propertyFile.propertiesSize()> 0) { rpf.propertyFile.saveTo(rpf.actualFile, apronOptions); } }); }); }  static void importXls(final FileMatcher fileMatcher,
                               final File xlsFile,
                               final Charset propertyFileEncoding,
                               final MissingKeyAction missingKeyAction); static void exportXls(final FileMatcher fileMatcher,
                               final Charset propertyFileEncoding,
                               final File xlsFile); }
XlsImExporter { public static void importXls(final FileMatcher fileMatcher, final File xlsFile, final Charset propertyFileEncoding, final MissingKeyAction missingKeyAction) { Require.nonNull(fileMatcher); Require.nonNull(xlsFile); final ApronOptions apronOptions= ApronOptions.create() .with(propertyFileEncoding != null ? propertyFileEncoding : UTF_8) .with(missingKeyAction); final XlsFile xlsFileObject= new XlsFile(xlsFile); final Map<I18nBundleKey, Collection<Translation>> content= xlsFileObject.getContent(); final Map<String, Map<Language, RememberingPropertyFile>> bundleFileMapping= new LinkedHashMap<>(); content.entrySet().forEach((entry) -> { final I18nBundleKey bundleKey= entry.getKey(); final String bundleBasename= bundleKey.getBundleBaseName(); final String propertyKey= bundleKey.getKey(); final Collection<Translation> translations= entry.getValue(); for (final Translation translation : translations) { if (!bundleFileMapping.containsKey(bundleBasename)) { bundleFileMapping.put(bundleBasename, new LinkedHashMap<>()); } if (!bundleFileMapping.get(bundleBasename).containsKey(translation.getLang())) { final File fileForBundle= getFileForBundle(fileMatcher.getRoot().toFile(), bundleBasename, translation.getLang()); if (!fileMatcher.matches(fileForBundle.toPath())) { LOGGER.log(Level.DEBUG, "Skipping import to file {} since it does not match inclusion pattern", fileForBundle); continue; } final PropertyFile propertyFile= new PropertyFile(); bundleFileMapping.get(bundleBasename).put(translation.getLang(), new RememberingPropertyFile(fileForBundle, propertyFile)); } final RememberingPropertyFile rpf= bundleFileMapping.get(bundleBasename).get(translation.getLang()); if ((translation.getValue() != null && !translation.getValue().isEmpty()) || rpf.propertyFile.containsKey(propertyKey)) { rpf.propertyFile.setValue(propertyKey, translation.getValue()); } } }); bundleFileMapping.values().forEach((Map<Language, RememberingPropertyFile> langPropMap) -> { langPropMap.values().forEach((RememberingPropertyFile rpf) -> { if (rpf.propertyFile.propertiesSize()> 0) { rpf.propertyFile.saveTo(rpf.actualFile, apronOptions); } }); }); }  static void importXls(final FileMatcher fileMatcher,
                               final File xlsFile,
                               final Charset propertyFileEncoding,
                               final MissingKeyAction missingKeyAction); static void exportXls(final FileMatcher fileMatcher,
                               final Charset propertyFileEncoding,
                               final File xlsFile);  }