Statistics
| Revision:

root / tmp / org.txm.translate.rcp / src / org / txm / rcp / translate / i18n / IsStringMissingInPlugin.groovy @ 1326

History | View | Annotate | Download (1.6 kB)

1 1223 mdecorde
package org.txm.rcp.translate.i18n
2 1223 mdecorde
3 1223 mdecorde
/**
4 1223 mdecorde
 * Display the missing i18n keys of the plugin.xml file
5 1223 mdecorde
 *
6 1223 mdecorde
 * @author mdecorde
7 1223 mdecorde
 *
8 1223 mdecorde
 */
9 1223 mdecorde
class IsStringMissingInPlugin {
10 1223 mdecorde
11 1223 mdecorde
        public static void main(String[] args) {
12 1223 mdecorde
                String userhome = System.getProperty("user.home")
13 1223 mdecorde
                File propertyFile = new File(userhome, "workspace43/org.txm.rcp/OSGI-INF/l10n/bundle_fr.properties");
14 1223 mdecorde
                File copyFile = new File(userhome, "workspace43/org.txm.rcp/OSGI-INF/l10n/bundle_copy.properties");
15 1223 mdecorde
                File pluginFile = new File(userhome, "workspace43/org.txm.rcp/plugin.xml");
16 1223 mdecorde
                if (!(propertyFile.exists() && propertyFile.canRead() && propertyFile.canWrite() && propertyFile.isFile()))
17 1223 mdecorde
                {
18 1223 mdecorde
                        println "error file : "+propertyFile
19 1223 mdecorde
                        return
20 1223 mdecorde
                }
21 1223 mdecorde
22 1223 mdecorde
                println "Get properties of "+propertyFile
23 1223 mdecorde
                Properties props = new Properties();
24 1223 mdecorde
                propertyFile.withReader("iso-8859-1") { input->
25 1223 mdecorde
                        props.load(input);
26 1223 mdecorde
                        input.close()
27 1223 mdecorde
                }
28 1223 mdecorde
29 1223 mdecorde
30 1223 mdecorde
                String pluginXMLcontent = pluginFile.getText();
31 1223 mdecorde
                def pluginKeys = [];
32 1223 mdecorde
                def matcher = pluginXMLcontent =~ /"%([.A-Za-z0-9]+)+"/ // %key.of.the.field
33 1223 mdecorde
                println "Comparing keys "+matcher.pattern() +" of "+pluginFile+" with those declared"
34 1223 mdecorde
                matcher.each { // iterates of %key in the plugin.xml content
35 1223 mdecorde
                        def key = it[1]
36 1223 mdecorde
                        pluginKeys << key
37 1223 mdecorde
                        if (!props.containsKey(key)) {
38 1223 mdecorde
                                println "Prop file does not contains the key: $key"
39 1223 mdecorde
                                //println " adding default value."
40 1223 mdecorde
                                props.setProperty(key, "NA")
41 1223 mdecorde
                        }
42 1223 mdecorde
                }
43 1223 mdecorde
44 1223 mdecorde
                for (String key : props.keySet()) {
45 1223 mdecorde
                        if (!pluginKeys.contains(key)) {
46 1223 mdecorde
                                println "plugin.xml does not use the key: "+key
47 1223 mdecorde
                        }
48 1223 mdecorde
                }
49 1223 mdecorde
50 1223 mdecorde
                propertyFile.withWriter("iso-8859-1") { output ->
51 1223 mdecorde
                        props.store(output, "")
52 1223 mdecorde
                }
53 1223 mdecorde
        }
54 1223 mdecorde
}