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