From 5fd56b5d917b715e68d525d6fb86fcf5f2ed4632 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Wed, 23 Jan 2013 13:04:45 +0100 Subject: [PATCH] monitoring I18N translations --- app/build.xml | 2 +- app/test/processing/app/I18NTest.java | 82 +++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 app/test/processing/app/I18NTest.java diff --git a/app/build.xml b/app/build.xml index 82a959c8b..1cb7fb12b 100644 --- a/app/build.xml +++ b/app/build.xml @@ -76,7 +76,7 @@ - + diff --git a/app/test/processing/app/I18NTest.java b/app/test/processing/app/I18NTest.java new file mode 100644 index 000000000..d4c48f016 --- /dev/null +++ b/app/test/processing/app/I18NTest.java @@ -0,0 +1,82 @@ +package processing.app; + +import org.junit.Test; + +import java.io.*; +import java.util.*; + +import static org.junit.Assert.assertTrue; + +public class I18NTest { + + private Set loadAllI18NKeys() throws IOException { + Properties properties = new Properties(); + for (File file : listPropertiesFiles()) { + properties.putAll(loadProperties(file)); + } + Set keys = new HashSet(); + for (Object key : properties.keySet()) { + keys.add(key.toString()); + } + return keys; + } + + private File[] listPropertiesFiles() { + return new File(I18NTest.class.getResource(".").getFile()).listFiles(new FileFilter() { + @Override + public boolean accept(File file) { + return file.isFile() && file.getName().endsWith(".properties"); + } + }); + } + + private Properties loadProperties(File file) throws IOException { + Properties properties = new Properties(); + InputStream is = null; + try { + is = new FileInputStream(file); + properties.load(is); + } finally { + if (is != null) { + is.close(); + } + } + return properties; + } + + @Test + public void ensureEveryTranslationIsComplete() throws Exception { + Set keys = loadAllI18NKeys(); + + Map> missingTranslationsPerFile = new HashMap>(); + + for (File file : listPropertiesFiles()) { + Properties properties = loadProperties(file); + for (String key : keys) { + if (!properties.containsKey(key) || properties.get(key).equals("")) { + addMissingTranslation(missingTranslationsPerFile, file, key); + } + } + } + + if (!missingTranslationsPerFile.isEmpty()) { + for (Map.Entry> entry : missingTranslationsPerFile.entrySet()) { + System.out.println("Following translations in file " + entry.getKey() + " are missing:"); + for (String key : entry.getValue()) { + System.out.println("==> '" + key + "'"); + } + System.out.println(); + } + assertTrue(false); + } + } + + private void addMissingTranslation(Map> missingTranslationsPerFile, File file, String key) { + if (!missingTranslationsPerFile.containsKey(file.getName())) { + missingTranslationsPerFile.put(file.getName(), new LinkedList()); + } + + missingTranslationsPerFile.get(file.getName()).add(key); + } + +}