Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / i18n / GetStringsFromPropertiesFile.groovy @ 345

History | View | Annotate | Download (1.8 kB)

1
package org.txm.scripts.i18n;
2

    
3
import java.io.BufferedReader;
4
import java.io.File;
5
import java.io.FileInputStream;
6
import java.io.InputStreamReader;
7
import java.util.LinkedList;
8

    
9
import org.txm.utils.io.IOUtils;
10

    
11
File newProjectMessagesPackage= new File(System.getProperty("user.home"), "workspace079/org.txm.concordance.core/src/org/txm/concordances/messages");
12
File oldProjectMessagesPackage= new File(System.getProperty("user.home"), "workspace079/org.txm.core/src/java/org/txm/core/messages")
13
File newNLSClassFile = new File(newProjectMessagesPackage, "ConcordanceMessages.java");
14
File oldNLSClassFile = new File(oldProjectMessagesPackage, "TBXMessages.java");
15
def langs = ["_fr", "", "_ru"]
16
for (def lang : langs) {
17
        println "LANG=$lang"
18
        Properties oldProperties = new Properties();
19
        File oldMessageFile = new File(oldProjectMessagesPackage, "messages${lang}.properties")
20
        oldProperties.load(IOUtils.getReader(oldMessageFile, "UTF-8"));
21
        Properties newProperties = new Properties();
22
        File newMessageFile = new File(newProjectMessagesPackage, "messages${lang}.properties")
23
        if (newMessageFile.exists())
24
                newProperties.load(IOUtils.getReader(newMessageFile, "UTF-8"));
25
                
26
        newNLSClassFile.getText("UTF-8").findAll("public static String [^;]+;") { key ->
27
                key = key.substring(21, key.length()-1)
28
                
29
                if (oldProperties.get(key) == null) {
30
                        println "Key $key is missing from old messages file: "+oldMessageFile.getName()
31
                        newProperties.put(key, "MISSING")
32
                } else {
33
                        if (newProperties.get(key) != null) {
34
                                println "update $key = "+oldProperties.get(key)
35
                        } else {
36
                                println "add $key = "+oldProperties.get(key)
37
                        }
38
                        newProperties.put(key, oldProperties.get(key))
39
                }
40
        }
41
        newProperties.store(IOUtils.getWriter(newMessageFile, "UTF-8"), "created/updated with GetStringsFromPropertiesFile.groovy")
42
        println "Done"                
43
}