Mercurial > pidgin.yaz
comparison pidgin/win32/nsis/create_nsis_translations.pl @ 30388:69c70c40baea
Add unmodified create_nsis_translations.pl script from the gcompris project.
This is from:
http://git.gnome.org/browse/gcompris/tree/tools/create_nsis_translations.pl
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Tue, 18 May 2010 01:07:55 +0000 |
parents | |
children | f4c8b3ba3ef1 |
comparison
equal
deleted
inserted
replaced
30387:1722c55f3f06 | 30388:69c70c40baea |
---|---|
1 #!/usr/bin/perl | |
2 # | |
3 # create_nsis_translations.pl | |
4 # | |
5 # Copyright (C) 2000-2009 Bruno Coudoin | |
6 # | |
7 # This program is free software; you can redistribute it and/or modify | |
8 # it under the terms of the GNU General Public License as published by | |
9 # the Free Software Foundation; either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 # | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU General Public License for more details. | |
16 # | |
17 # You should have received a copy of the GNU General Public License | |
18 # along with this program; if not, see <http://www.gnu.org/licenses/>. | |
19 # | |
20 | |
21 use strict; | |
22 | |
23 sub usage { | |
24 print 'create_nsis_translations.pl translations installer tmp_dir | |
25 translations | |
26 This is an input file that contains all the | |
27 translated strings. If must be formated as a GNU/Linux | |
28 desktop file and contains multiple strings entry. | |
29 For example you must have: | |
30 toBe=To be or not to be | |
31 toBe[fr]=Etre ou ne pas etre | |
32 | |
33 installer | |
34 This is your nsis installer source file. You must include | |
35 in it the marker @INSERT_TRANSLATIONS@ before you use any | |
36 translation string. | |
37 After that you can use the variable $(toBe) in your file. | |
38 | |
39 tmp_dir | |
40 This is a directory in which temporary files needed for | |
41 the translation system. | |
42 It will be created if non existant. | |
43 You can remove it once you have created your installer. | |
44 '; | |
45 } | |
46 | |
47 my $translations; | |
48 if (! $ARGV[0] || ! -f $ARGV[0]) | |
49 { | |
50 usage(); | |
51 } | |
52 else | |
53 { | |
54 $translations = $ARGV[0]; | |
55 } | |
56 | |
57 shift; | |
58 my $installer; | |
59 if (! $ARGV[0] || ! -f $ARGV[0]) | |
60 { | |
61 usage(); | |
62 } | |
63 else | |
64 { | |
65 $installer = $ARGV[0]; | |
66 } | |
67 | |
68 shift; | |
69 my $tmp_dir; | |
70 if (! $ARGV[0] ) | |
71 { | |
72 usage(); | |
73 } | |
74 else | |
75 { | |
76 $tmp_dir = $ARGV[0]; | |
77 | |
78 if ( ! -d $tmp_dir ) | |
79 { | |
80 mkdir $tmp_dir or die "ERROR: '$tmp_dir' $!\n"; | |
81 } | |
82 } | |
83 | |
84 print "Processing translation file '$translations'\n"; | |
85 print " NSIS source file '$installer'\n"; | |
86 print " Working dir '$tmp_dir'\n"; | |
87 | |
88 # Commented out locales that are not available in nsis | |
89 my %localeNames = ( | |
90 "af" => ["Afrikaans", "UTF-8"], | |
91 # "am" => ["Amharic", "UTF-8"], | |
92 "ar" => ["Arabic", "WINDOWS-1256"], | |
93 "bg" => ["Bulgarian", "WINDOWS-1251"], | |
94 "br" => ["Breton", "WINDOWS-1252"], | |
95 "ca" => ["Catalan", "WINDOWS-1252"], | |
96 "cs" => ["Czech", "WINDOWS-1250"], | |
97 "da" => ["Danish", "WINDOWS-1252"], | |
98 "de" => ["German", "WINDOWS-1252"], | |
99 # "dz" => ["Dzongkha", "UTF-8"], | |
100 "el" => ["Greek", "WINDOWS-1253"], | |
101 "en" => ["English", "WINDOWS-1252"], | |
102 "es" => ["Spanish", "WINDOWS-1252"], | |
103 "eu" => ["Basque", "WINDOWS-1252"], | |
104 # "fa" => ["Persian", "UTF-8"], | |
105 "fi" => ["Finnish", "WINDOWS-1252"], | |
106 "fr" => ["French", "WINDOWS-1252"], | |
107 "ga" => ["Irish", "WINDOWS-1252"], | |
108 # "gu" => ["Gujarati", "UTF-8"], | |
109 "he" => ["Hebrew", "WINDOWS-1255"], | |
110 # "hi" => ["Hindi", "UTF-8"], | |
111 "hr" => ["Croatian", "WINDOWS-1250"], | |
112 "hu" => ["Hungarian", "WINDOWS-1250"], | |
113 "id" => ["Indonesian", "WINDOWS-1252"], | |
114 "it" => ["Italian", "WINDOWS-1252"], | |
115 "ja" => ["Japanese", "CP932"], | |
116 # "ka" => ["Georgian", "UTF-8"], | |
117 "ko" => ["Korean", "MSCP949"], | |
118 "lt" => ["Lithuanian", "WINDOWS-1257"], | |
119 "mk" => ["Macedonian", "WINDOWS-1251"], | |
120 # "ml" => ["Malayalam", "UTF-8"], | |
121 # "mr" => ["Marathi", "UTF-8"], | |
122 "ms" => ["Malay", "WINDOWS-1252"], | |
123 "nb" => ["Norwegian", "WINDOWS-1252"], | |
124 # "ne" => ["Nepal", "UTF-8"], | |
125 "nl" => ["Dutch", "WINDOWS-1252"], | |
126 "nn" => ["NorwegianNynorsk", "UTF-8"], | |
127 # "oc" => ["Occitan", "WINDOWS-1252"], | |
128 # "pa" => ["Punjabi", "UTF-8"], | |
129 "pl" => ["Polish", "WINDOWS-1250"], | |
130 "pt" => ["Portuguese", "WINDOWS-1252"], | |
131 "pt_BR" => ["PortugueseBR", "WINDOWS-1252"], | |
132 "ro" => ["Romanian", "WINDOWS-1250"], | |
133 "ru" => ["Russian", "WINDOWS-1251"], | |
134 # "rw" => ["Kinyarwanda", "UTF-8"], | |
135 "sk" => ["Slovak", "WINDOWS-1250"], | |
136 "sl" => ["Slovenian", "WINDOWS-1250"], | |
137 # "so" => ["Somali", "UTF-8"], | |
138 "sq" => ["Albanian", "WINDOWS-1252"], | |
139 "sr" => ["Serbian", "WINDOWS-1250"], | |
140 "sv" => ["Swedish", "WINDOWS-1252"], | |
141 # "ta" => ["Tamil", "UTF-8"], | |
142 "th" => ["Thai", "WINDOWS-874"], | |
143 "tr" => ["Turkish", "WINDOWS-1254"], | |
144 "uk" => ["Ukrainian", "WINDOWS-1251"], | |
145 # "ur" => ["Urdu", "UTF-8"], | |
146 # "vi" => ["Vietnamese", "WINDOWS-1258"], | |
147 # "wa" => ["Walloon", "WINDOWS-1252"], | |
148 "zh" => ["SimpChinese", "WINDOWS-936"], | |
149 "zh" => ["TradChinese", "CP950"], | |
150 ); | |
151 | |
152 my @localeKeys = keys(%localeNames); | |
153 | |
154 # Create the holder for the results | |
155 # %result{"locale"}{"stringname"} = result line | |
156 print "Parsing nsis_translations.desktop\n"; | |
157 my %result; | |
158 | |
159 # Create a hash of the keys to translate | |
160 open (MYFILE, $translations); | |
161 while (<MYFILE>) { | |
162 chomp $_; | |
163 if ($_ =~ /Encoding=UTF-8/) | |
164 { | |
165 next; | |
166 } | |
167 elsif ($_ =~ /^(\w+)=(.*)/) | |
168 { | |
169 my $line = "!define $1 \"$2\"\n"; | |
170 $result{"en"}{"$1"} = $line; | |
171 } | |
172 elsif ($_ =~ /^(\w+)\[(\w+)\]=(.*)/) | |
173 { | |
174 my $line = "!define $1 \"$3\"\n"; | |
175 $result{"$2"}{"$1"} = $line; | |
176 } | |
177 } | |
178 close (MYFILE); | |
179 | |
180 # Lets insert the default languages | |
181 # in the installer file which means replacing: | |
182 # @INSERTMACRO_MUI_LANGUAGE@ | |
183 # By the list of locales: | |
184 # !insertmacro MUI_LANGUAGE "French" | |
185 | |
186 my $muiLanguages; | |
187 $muiLanguages = ' | |
188 ;; English goes first because its the default. The rest are | |
189 ;; in alphabetical order (at least the strings actually displayed | |
190 ;; will be). | |
191 !insertmacro MUI_LANGUAGE "English" | |
192 '; | |
193 | |
194 foreach my $lang (@localeKeys) { | |
195 if ( $lang eq "en" ) { next; } | |
196 $muiLanguages .= " !insertmacro MUI_LANGUAGE \"$localeNames{$lang}[0]\"\n"; | |
197 } | |
198 | |
199 # The specific GCompris translation for the installer | |
200 # replacing: | |
201 # @GCOMPRIS_MACRO_INCLUDE_LANGFILE@ | |
202 # By the list of locales: | |
203 # !insertmacro GCOMPRIS_MACRO_INCLUDE_LANGFILE "ALBANIAN" "${GCOMPRIS_NSIS_INCLUDE_PATH}\translations\albanian.nsh" | |
204 | |
205 my $gcomprisLanguages; | |
206 | |
207 $gcomprisLanguages .= ' | |
208 ;-------------------------------- | |
209 ;Translations | |
210 !define GCOMPRIS_DEFAULT_LANGFILE "${GCOMPRIS_NSIS_INCLUDE_PATH}\\translations\\en.nsh" | |
211 ;; | |
212 ;; Windows GCompris NSIS installer language macros | |
213 ;; | |
214 | |
215 !macro GCOMPRIS_MACRO_DEFAULT_STRING LABEL VALUE | |
216 !ifndef "${LABEL}" | |
217 !define "${LABEL}" "${VALUE}" | |
218 !ifdef INSERT_DEFAULT | |
219 !warning "${LANG} lang file mising ${LABEL}, using default.." | |
220 !endif | |
221 !endif | |
222 !macroend | |
223 | |
224 !macro GCOMPRIS_MACRO_LANGSTRING_INSERT LABEL LANG | |
225 LangString "${LABEL}" "${LANG_${LANG}}" "${${LABEL}}" | |
226 !undef "${LABEL}" | |
227 !macroend | |
228 | |
229 !macro GCOMPRIS_MACRO_LANGUAGEFILE_BEGIN LANG | |
230 !define CUR_LANG "${LANG}" | |
231 !macroend | |
232 '; | |
233 | |
234 | |
235 # GCOMPRIS_MACRO_LANGUAGEFILE_END | |
236 $gcomprisLanguages .= ' | |
237 !macro GCOMPRIS_MACRO_LANGUAGEFILE_END | |
238 !define INSERT_DEFAULT | |
239 !include "${GCOMPRIS_DEFAULT_LANGFILE}" | |
240 !undef INSERT_DEFAULT | |
241 | |
242 ; String labels should match those from the default language file. | |
243 '; | |
244 | |
245 my $text_en = $result{"en"}; | |
246 foreach my $keyEn (keys(%$text_en)) { | |
247 $gcomprisLanguages .= " !insertmacro GCOMPRIS_MACRO_LANGSTRING_INSERT $keyEn \${CUR_LANG}"; | |
248 $gcomprisLanguages .= "\n"; | |
249 } | |
250 | |
251 $gcomprisLanguages .= ' | |
252 !undef CUR_LANG | |
253 !macroend | |
254 '; | |
255 | |
256 $gcomprisLanguages .= ' | |
257 !macro GCOMPRIS_MACRO_INCLUDE_LANGFILE LANG FILE | |
258 !insertmacro GCOMPRIS_MACRO_LANGUAGEFILE_BEGIN "${LANG}" | |
259 !include "${FILE}" | |
260 !insertmacro GCOMPRIS_MACRO_LANGUAGEFILE_END | |
261 !macroend | |
262 '; | |
263 | |
264 foreach my $lang (@localeKeys) { | |
265 $gcomprisLanguages .= " !insertmacro GCOMPRIS_MACRO_INCLUDE_LANGFILE". | |
266 " \"$localeNames{$lang}[0]\"". | |
267 " \"\${GCOMPRIS_NSIS_INCLUDE_PATH}\\translations\\$lang.nsh\"\n"; | |
268 } | |
269 | |
270 # We have all the data, let's replace it | |
271 my $gcomprisInstaller; | |
272 open (MYFILE, $installer); | |
273 while (<MYFILE>) { | |
274 if ($_ =~ /\@INSERT_TRANSLATIONS\@/) | |
275 { | |
276 print "Processing \@INSERT_TRANSLATIONS\@\n"; | |
277 $gcomprisInstaller .= $muiLanguages; | |
278 $gcomprisInstaller .= $gcomprisLanguages; | |
279 } | |
280 else | |
281 { | |
282 $gcomprisInstaller .= "$_"; | |
283 } | |
284 } | |
285 close (MYFILE); | |
286 | |
287 # Rewrite the file with the replaced data | |
288 open (MYFILE, ">$installer"); | |
289 print MYFILE "$gcomprisInstaller"; | |
290 close (MYFILE); | |
291 | |
292 # | |
293 # Create each nsh translation file | |
294 # | |
295 | |
296 print "Creating the nsh default file\n"; | |
297 open (DESC, ">$tmp_dir/en.nsh"); | |
298 print DESC ";; Auto generated file by create_nsis_translations.pl\n"; | |
299 foreach my $keyEn (keys(%$text_en)) { | |
300 my $line = $result{'en'}{$keyEn}; | |
301 $line =~ s/!define /!insertmacro GCOMPRIS_MACRO_DEFAULT_STRING /; | |
302 print DESC $line; | |
303 } | |
304 close DESC; | |
305 | |
306 # | |
307 # Two pass are needed: | |
308 # - create the utf8 file | |
309 # - transform it to the proper windows locale | |
310 # | |
311 print "Creating the nsh locale files\n"; | |
312 foreach my $lang (@localeKeys) { | |
313 if ( $lang eq "en" ) { next; } | |
314 open (DESC, ">$tmp_dir/$lang.nsh.utf8"); | |
315 print DESC ";; Auto generated file by create_nsis_translations.pl\n"; | |
316 print DESC ";; Code Page: $localeNames{$lang}[1]\n"; | |
317 | |
318 my $text_locale = $result{"$lang"}; | |
319 foreach my $keyEn (keys(%$text_en)) { | |
320 my $found = 0; | |
321 foreach my $keyLocale (keys(%$text_locale)) { | |
322 # Fine, we found a translation | |
323 if ( $keyLocale eq $keyEn ) | |
324 { | |
325 print DESC "$result{$lang}{$keyLocale}"; | |
326 $found = 1; | |
327 last; | |
328 } | |
329 } | |
330 # English keys are the reference. | |
331 # If not found they are inserted | |
332 if ( ! $found ) | |
333 { | |
334 print DESC "$result{'en'}{$keyEn}"; | |
335 } | |
336 } | |
337 close DESC; | |
338 | |
339 # iconv conversion | |
340 system("iconv -f UTF-8 -t $localeNames{$lang}[1] $tmp_dir/$lang.nsh.utf8 -o $tmp_dir/$lang.nsh"); | |
341 if ($? ne 0) | |
342 { | |
343 print("ERROR: Failed to run: iconv -f UTF-8 -t $localeNames{$lang}[1] $lang.nsh.utf8 -o $lang.nsh\n"); | |
344 } | |
345 #`rm $tmp_dir/$lang.nsh.utf8`; | |
346 | |
347 } |