Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / i18n / IsStringMissingInPlugin.groovy @ 1000

History | View | Annotate | Download (1.6 kB)

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