Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / scripts / i18n / IsStringUsedInPlugin.groovy @ 187

History | View | Annotate | Download (1.5 kB)

1
package org.txm.scripts.i18n
2

    
3
/**
4
 * Display the String and key not used in the plugin messages
5
 * @author mdecorde
6
 *
7
 */
8
class IsStringUsedInPlugin {
9
        Properties props;
10

    
11
        public boolean scan(File propertyFile, File pluginFile) {
12
                if(!(propertyFile.exists() && propertyFile.canRead() && propertyFile.canWrite() && propertyFile.isFile()))
13
                {
14
                        println "error file : "+propertyFile
15
                        return false;
16
                }
17

    
18
                props = new Properties();
19
                propertyFile.withReader("iso-8859-1") { input->
20
                        props.load(input);
21
                        input.close()
22
                }
23

    
24
                String content = pluginFile.getText();
25
                def toRemove = [];
26
                for(def key : props.keySet()) {
27
                        if (!content.contains("\"%"+key+"\"")) {
28
                                println "not used $key "+props.get(key);
29
                                toRemove << key
30
                        }
31
                }
32

    
33
                for(String key : toRemove) {
34
                        props.remove(key);
35
                }
36

    
37

    
38
                if (toRemove == 0) {
39
                        println "nothing to do"
40
                        return false;
41
                }
42
                return true
43
        }
44

    
45
        public boolean writeFixes(File propertyFile) {
46
                if (props == null) return false;
47
                propertyFile.withWriter("iso-8859-1") { output ->
48
                        props.store(output, "")
49
                }
50
                return true;
51
        }
52

    
53
        public static void main(String[] args) {
54
                String userhome = System.getProperty("user.home")
55
                File propertyFile = new File(userhome, "workspace43/org.txm.rcp/OSGI-INF/l10n/bundle.properties");
56
                File pluginFile = new File(userhome, "workspace43/org.txm.rcp/plugin.xml");
57
                IsStringUsedInPlugin fixer = new IsStringUsedInPlugin();
58
                //uncomment to remove unused Strings
59
                if (fixer.scan(propertyFile, pluginFile)) {
60
                        fixer.writeFixes(propertyFile)
61
                }
62
        }
63
}