Skip to content

Commit 5fd56b5

Browse files
committed
monitoring I18N translations
1 parent 763ed07 commit 5fd56b5

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

app/build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<fileset dir="test" includes="**/*.txt" />
7777
</copy>
7878

79-
<junit printsummary="yes" haltonfailure="yes">
79+
<junit printsummary="yes">
8080
<classpath>
8181
<pathelement location="bin"/>
8282
<pathelement location="test-bin"/>

app/test/processing/app/I18NTest.java

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package processing.app;
2+
3+
import org.junit.Test;
4+
5+
import java.io.*;
6+
import java.util.*;
7+
8+
import static org.junit.Assert.assertTrue;
9+
10+
public class I18NTest {
11+
12+
private Set<String> loadAllI18NKeys() throws IOException {
13+
Properties properties = new Properties();
14+
for (File file : listPropertiesFiles()) {
15+
properties.putAll(loadProperties(file));
16+
}
17+
Set<String> keys = new HashSet<String>();
18+
for (Object key : properties.keySet()) {
19+
keys.add(key.toString());
20+
}
21+
return keys;
22+
}
23+
24+
private File[] listPropertiesFiles() {
25+
return new File(I18NTest.class.getResource(".").getFile()).listFiles(new FileFilter() {
26+
@Override
27+
public boolean accept(File file) {
28+
return file.isFile() && file.getName().endsWith(".properties");
29+
}
30+
});
31+
}
32+
33+
private Properties loadProperties(File file) throws IOException {
34+
Properties properties = new Properties();
35+
InputStream is = null;
36+
try {
37+
is = new FileInputStream(file);
38+
properties.load(is);
39+
} finally {
40+
if (is != null) {
41+
is.close();
42+
}
43+
}
44+
return properties;
45+
}
46+
47+
@Test
48+
public void ensureEveryTranslationIsComplete() throws Exception {
49+
Set<String> keys = loadAllI18NKeys();
50+
51+
Map<String, List<String>> missingTranslationsPerFile = new HashMap<String, List<String>>();
52+
53+
for (File file : listPropertiesFiles()) {
54+
Properties properties = loadProperties(file);
55+
for (String key : keys) {
56+
if (!properties.containsKey(key) || properties.get(key).equals("")) {
57+
addMissingTranslation(missingTranslationsPerFile, file, key);
58+
}
59+
}
60+
}
61+
62+
if (!missingTranslationsPerFile.isEmpty()) {
63+
for (Map.Entry<String, List<String>> entry : missingTranslationsPerFile.entrySet()) {
64+
System.out.println("Following translations in file " + entry.getKey() + " are missing:");
65+
for (String key : entry.getValue()) {
66+
System.out.println("==> '" + key + "'");
67+
}
68+
System.out.println();
69+
}
70+
assertTrue(false);
71+
}
72+
}
73+
74+
private void addMissingTranslation(Map<String, List<String>> missingTranslationsPerFile, File file, String key) {
75+
if (!missingTranslationsPerFile.containsKey(file.getName())) {
76+
missingTranslationsPerFile.put(file.getName(), new LinkedList<String>());
77+
}
78+
79+
missingTranslationsPerFile.get(file.getName()).add(key);
80+
}
81+
82+
}

0 commit comments

Comments
 (0)