Statistics
| Revision:

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

History | View | Annotate | Download (2 kB)

1
package org.txm.scripts.i18n
2

    
3
import java.io.File;
4
import java.util.HashMap;
5
/**
6
 * Display a diff of 2 message files
7
 * 
8
 * @author mdecorde
9
 *
10
 */
11
class I18nDiff {
12
        Properties values1, values2;
13
        File file1;
14
        File file2;
15

    
16
        def notInValues1, notInValues2
17
        I18nDiff(File file1, File file2) {
18
                this.file1 = file1
19
                this.file2 = file2
20
                values1 = getValues(file1)
21
                values2 = getValues(file2)
22

    
23
                def inter = values1.keySet().intersect(values2.keySet());
24
                notInValues1 = values2.keySet().minus(values1.keySet());
25
                notInValues2 = values1.keySet().minus(values2.keySet());
26

    
27
                println "not in $file1"
28
                for(String key : notInValues1)
29
                        if (key.trim().length() > 0)
30
                                println key+" = "+values2.get(key)
31

    
32
                println "not in $file2"
33
                for(String key : notInValues2)
34
                        if (key.trim().length() > 0)
35
                                println key+" = "+values1.get(key)
36

    
37
                //                println "values diff"
38
                //
39
                //                for(String key : inter ) {
40
                //                        if(values1.get(key) != values2.get(key))
41
                //                                println key+" = "+values1.get(key)+" != "+values2.get(key)
42
                //                }
43
        }
44

    
45
        public void synchronizeFromF1toF2() {
46
                
47
                for(String key : notInValues2) {
48
                        if (key.trim().length() > 0)
49
                                values2.setProperty(key, "NA_"+values1.get(key));
50
                }
51
                
52
                for(String key : notInValues1)
53
                        if (key.trim().length() > 0)
54
                                values2.remove(key)
55
                                
56
                file2.withWriter("iso-8859-1") { writer ->
57
                        values2.store(writer, "")
58
                }
59
        }
60

    
61
        /**
62
         * Gets the values.
63
         *
64
         * @param file the file
65
         * @return the values
66
         */
67
        public Properties getValues(File file) {
68
                Properties props = new Properties();
69
                file.withReader("iso-8859-1") { input->
70
                        props.load(input);
71
                        input.close()
72
                }
73
                return props;
74
        }
75

    
76
        public static void main(String[] args) {
77
                String userhome = System.getProperty("user.home");
78
                File f1 = new File(userhome, "workspace43/org.txm.rcp/OSGI-INF/l10n/bundle.properties")
79
                File f2 = new File(userhome, "workspace43/org.txm.rcp/OSGI-INF/l10n/bundle_fr.properties")
80
                
81
                I18nDiff diff = new I18nDiff(f1, f2);
82
                diff.synchronizeFromF1toF2()
83
        }
84
}