Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / setup / MessagesToArchMessages.groovy @ 1000

History | View | Annotate | Download (5.8 kB)

1
package org.txm.scripts.setup
2
rootDir = new File("/home/mdecorde/paquets")
3
linuxMessagesDir = new File(rootDir, "shared/debian/DEBIAN")
4
windowsMessagesDir = new File(rootDir, "archs/win")
5
macMessagesDir = new File(rootDir, "shared/mac")
6

    
7
windowsMessages = ";START OF LANG MESSAGES\n"
8
win_langs = ["en": "ENGLISH" , "fr":"FRENCH"]
9

    
10
needed_keys = [
11
        "InfosTitle", "InfosText", "WelcomeTitle", "WelcomeText",
12
        "InstallRLibrariesTitle", "InstallRLibrariesText", "FinishTitle",
13
        "FinishTextWindows", "FinishTextLinux", "FinishTextMac",
14
        "ErrorArch32", "ErrorArch64", "UninstallWindows", "InstallTreeTagger"]
15

    
16
if (!(writeLangFiles("en") && writeLangFiles("fr"))) {
17
        println "Stoping process"
18
        return;
19
} 
20

    
21
windowsMessages += ";END OF LANG MESSAGES\n"
22

    
23
File nsis32 = new File(windowsMessagesDir, "32bit/txm.nsi")
24
File nsis64 = new File(windowsMessagesDir, "64bit/txm.nsi")
25

    
26
if (!(patchNSIS(nsis32) && patchNSIS(nsis64))) {
27
        println "Error while patching nsis files"
28
}
29

    
30
def patchNSIS(File nsis) {
31
        String text = nsis.getText("Windows-1252")
32
        boolean startReplacing = false;
33
        nsis.withWriter("Windows-1252") { writer ->
34
                for (String line : text.split("\n")) {
35
                        if (";START OF LANG MESSAGES" == line.trim()) {
36
                                startReplacing = true
37
                                line = windowsMessages
38
                                writer.println line
39
                        }
40
                        if (";END OF LANG MESSAGES" == line.trim())  {
41
                                startReplacing = false
42
                                continue
43
                        }
44

    
45
                        if (!startReplacing) {
46
                                writer.println line
47
                        }
48
                }
49
        }
50
        return true;
51
}
52
def checkProps(def props) {
53
        def missing = []
54
        for (String prop : needed_keys)
55
                if (!props.containsKey(prop))
56
                        missing << prop
57
        return missing
58
}
59

    
60
def writeLangFiles(String lang) {
61
        println "Writing lang files for $lang"
62
        File propFile = new File(rootDir, "SetupMessages_${lang}.properties")
63

    
64
        Properties props = new Properties()
65
        InputStreamReader input = new InputStreamReader(new FileInputStream(propFile) , "UTF-8")
66
        props.load(input)
67
        input.close()
68

    
69
        def missingProps = checkProps(props)
70
        if (missingProps.size() > 0) {
71
                println "Error missings keys $lang: "+missingProps
72
                return false;
73
        }
74

    
75
        String ext = ""
76
        if (lang.length() > 0) ext = "."+lang
77

    
78
        // LINUX
79
        File template = new File(linuxMessagesDir, "templates"+ext)
80
        template.withWriter("UTF-8") { writer ->
81
                writer.println(
82
"""Template: TXM/showinfos
83
Type: note
84
Description:"""+props.get("InfosTitle"))
85
                writer.println(
86
                                " .\n  "+props.get("InfosText").replaceAll("\n\n", '\n .\n').replaceAll("\n([^ ])", '\n  $1').replaceAll("\n", '\n '))
87
                writer.println()
88
                writer.println(
89
"""Template: TXM/showwelcome
90
Type: note
91
Description:"""+props.get("WelcomeTitle"))
92
                writer.println(
93
                                " .\n  "+props.get("WelcomeText").replaceAll("\n\n", '\n .\n').replaceAll("\n([^ ])", '\n  $1').replaceAll("\n", '\n '))
94
                writer.println()
95
                writer.println(
96
"""Template: TXM/askr
97
Type: boolean
98
Default: true
99
Description:"""+props.get("InstallRLibrariesTitle"))
100
                writer.println(
101
                                " .\n  "+props.get("InstallRLibrariesText").replaceAll("\n\n", '\n .\n').replaceAll("\n([^ ])", '\n  $1').replaceAll("\n", '\n '))
102
                writer.println()
103
                writer.println(
104
"""Template: TXM/finish
105
Type: note
106
Description:"""+props.get("FinishTitle"))
107
        writer.println(
108
                " .\n  "+props.get("FinishTextLinux").replaceAll("\n\n", '\n .\n').replaceAll("\n([^ ])", '\n  $1').replaceAll("\n", '\n '))
109
        writer.println(
110
                " .\n  "+props.get("InstallTreeTagger").replaceAll("\n\n", '\n .\n').replaceAll("\n([^ ])", '\n  $1').replaceAll("\n", '\n '))
111
        }
112

    
113
        //WINDOWS NSIS
114
        if (lang.length() > 0) ext = "_"+lang
115

    
116
        StringWriter swriter = new StringWriter();
117
        swriter.println(";Lang Strings "+win_langs[lang])
118
        swriter.println('LangString InfosTitleMessage ${LANG_'+win_langs[lang]+'} "'+props.get("InfosTitle").replaceAll("\"", "'")+'"')
119
        swriter.println('LangString InfosTextMessage ${LANG_'+win_langs[lang]+'} "'+props.get("InfosText").replaceAll("\n", '\\$\\\\n').replaceAll("\"", "'")+'"')
120
        swriter.println('LangString WelcomeTitleMessage ${LANG_'+win_langs[lang]+'} "'+props.get("WelcomeTitle").replaceAll("\"", "'")+'"')
121
        swriter.println('LangString WelcomeTextMessage ${LANG_'+win_langs[lang]+'} "'+props.get("WelcomeText").replaceAll("\n", '\\$\\\\n').replaceAll("\"", "'")+'"')
122
        // no R libs question
123
        swriter.println('LangString FinishTitleMessage ${LANG_'+win_langs[lang]+'} "'+props.get("FinishTitle".replaceAll("\"", "'"))+'"')
124
        swriter.println('LangString FinishTextMessage ${LANG_'+win_langs[lang]+'} "'+(props.get("FinishTextWindows") + '$\\n' + props.get("InstallTreeTagger")).replaceAll("\n", '\\$\\\\n').replaceAll("\"", "'")+'"')
125
        // Windows specific messages
126
        swriter.println('LangString ErrorArch32Message ${LANG_'+win_langs[lang]+'} "'+props.get("ErrorArch32").replaceAll("\"", "'")+'"')
127
        swriter.println('LangString ErrorArch64Message ${LANG_'+win_langs[lang]+'} "'+props.get("ErrorArch64").replaceAll("\"", "'")+'"')
128
        swriter.println('LangString UninstallWindowsMessage ${LANG_'+win_langs[lang]+'} "'+props.get("UninstallWindows").replaceAll("\n", '\\$\\\\n').replaceAll("\"", "'")+'"')
129
        swriter.close();
130

    
131
        windowsMessages += "\n"+swriter.toString()+"\n"
132

    
133
        //MAC 3 FILES : Intro, ReadMe and Finish
134
        File intromac = new File(macMessagesDir, "intro${ext}.txt")
135
        intromac.withWriter("x-MacRoman") { writer ->
136
                writer.println("")
137
                writer.println(props.get("InfosText"))
138
        }
139
        File readmemac = new File(macMessagesDir, "readme${ext}.txt")
140
        readmemac.withWriter("x-MacRoman") { writer ->
141
                writer.println("")
142
                writer.println(props.get("WelcomeText"))
143
        }
144
        File rlibsmac = new File(macMessagesDir, "rlibs${ext}.txt")
145
        rlibsmac.withWriter("x-MacRoman") { writer ->
146
                writer.println(props.get("InstallRLibrariesTitle"))
147
                writer.println(props.get("InstallRLibrariesText"))
148
        }
149
        File finishmac = new File(macMessagesDir, "finish${ext}.txt")
150
        finishmac.withWriter("x-MacRoman") { writer ->
151
                writer.println("")
152
                writer.println(props.get("FinishTextMac"))
153
                writer.println("")
154
                writer.println(props.get("InstallTreeTagger"))
155
        }
156
        
157
        return true;
158
}
159

    
160

    
161

    
162