public void testTranslationKeyExistence() throws IOException { // use English version as the reference: final File englishFile = getEnglishTranslationFile(); final Properties enProps = new Properties(); enProps.load(new FileInputStream(englishFile)); final Set<Object> englishKeys = enProps.keySet(); for (Language lang : Language.REAL_LANGUAGES) { if (lang.getShortName().equals("en")) { continue; } final Properties langProps = new Properties(); final File langFile = getTranslationFile(lang); if (!langFile.exists()) { continue; } try (FileInputStream stream = new FileInputStream(langFile)) { langProps.load(stream); final Set<Object> langKeys = langProps.keySet(); for (Object englishKey : englishKeys) { if (!langKeys.contains(englishKey)) { System.err.println("***** No key '" + englishKey + "' in file " + langFile); } } } } }
private File getTranslationFile(Language lang) { final String langCode = lang.getShortName(); final String name = "../languagetool-language-modules/" + langCode + "/src/main/resources/org/languagetool" + "/MessagesBundle_" + langCode + ".properties"; return new File(name.replace("/", File.separator)); }
@Nullable private static MorfologikMultiSpeller getSpeller(Language language) { if (!language.getShortName().equals(Locale.GERMAN.getLanguage())) { throw new RuntimeException("Language is not a variant of German: " + language); } try { String morfoFile = "/de/hunspell/de_" + language.getCountries()[0] + ".dict"; if (JLanguageTool.getDataBroker().resourceExists(morfoFile)) { // spell data will not exist in LibreOffice/OpenOffice context try (InputStream stream = JLanguageTool.getDataBroker() .getFromResourceDirAsStream("/de/hunspell/spelling.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(stream, "utf-8"))) { return new MorfologikMultiSpeller(morfoFile, new ExpandingReader(br), MAX_EDIT_DISTANCE); } } else { return null; } } catch (IOException e) { throw new RuntimeException("Could not set up morfologik spell checker", e); } }