4 * Copyright 2010 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #ifdef HAVE_LIBGETTEXTPO
30 #include <gettext-po.h>
41 #include "wine/list.h"
43 static resource_t
*new_top
, *new_tail
;
48 unsigned int revision
;
50 unsigned int msgid_off
;
51 unsigned int msgstr_off
;
52 /* ... rest of file data here */
55 static int is_english( language_t lan
)
57 return lan
== MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
);
60 static int is_rtl_language( language_t lan
)
62 return PRIMARYLANGID(lan
) == LANG_ARABIC
||
63 PRIMARYLANGID(lan
) == LANG_HEBREW
||
64 PRIMARYLANGID(lan
) == LANG_PERSIAN
;
67 static int uses_larger_font( language_t lan
)
69 return PRIMARYLANGID(lan
) == LANG_CHINESE
||
70 PRIMARYLANGID(lan
) == LANG_JAPANESE
||
71 PRIMARYLANGID(lan
) == LANG_KOREAN
;
74 static language_t
get_default_sublang( language_t lan
)
76 if (SUBLANGID(lan
) != SUBLANG_NEUTRAL
) return lan
;
78 switch (PRIMARYLANGID(lan
))
81 return MAKELANGID( LANG_SPANISH
, SUBLANG_SPANISH_MODERN
);
83 return MAKELANGID( LANG_CHINESE
, SUBLANG_CHINESE_SIMPLIFIED
);
85 return MAKELANGID( PRIMARYLANGID(lan
), SUBLANG_DEFAULT
);
89 static version_t
get_dup_version( language_t lang
)
91 /* English "translations" take precedence over the original rc contents */
92 return is_english( lang
) ? 1 : -1;
95 static name_id_t
*dup_name_id( name_id_t
*id
)
99 if (!id
|| id
->type
!= name_str
) return id
;
102 new->name
.s_name
= convert_string_unicode( id
->name
.s_name
, 1252 );
106 static char *convert_msgid_ascii( const string_t
*str
, int error_on_invalid_char
)
109 char *buffer
= xmalloc( str
->size
+ 1 );
111 for (i
= 0; i
< str
->size
; i
++)
113 WCHAR ch
= (str
->type
== str_unicode
? str
->str
.wstr
[i
] : (unsigned char)str
->str
.cstr
[i
]);
115 if (ch
>= 32 && ch
<= 127) continue;
116 if (ch
== '\t' || ch
== '\n') continue;
117 if (error_on_invalid_char
)
119 print_location( &str
->loc
);
120 error( "Invalid character %04x in source string\n", ch
);
129 static char *get_message_context( char **msgid
)
131 static const char magic
[] = "#msgctxt#";
134 if (strncmp( *msgid
, magic
, sizeof(magic
) - 1 )) return NULL
;
135 context
= *msgid
+ sizeof(magic
) - 1;
136 if (!(id
= strchr( context
, '#' ))) return NULL
;
142 static int control_has_title( const control_t
*ctrl
)
144 if (!ctrl
->title
) return FALSE
;
145 if (ctrl
->title
->type
!= name_str
) return FALSE
;
146 /* check for text static control */
147 if (ctrl
->ctlclass
&& ctrl
->ctlclass
->type
== name_ord
&& ctrl
->ctlclass
->name
.i_name
== CT_STATIC
)
149 switch (ctrl
->style
->or_mask
& SS_TYPEMASK
)
162 static resource_t
*dup_resource( resource_t
*res
, language_t lang
)
164 resource_t
*new = xmalloc( sizeof(*new) );
168 new->next
= new->prev
= NULL
;
169 new->name
= dup_name_id( res
->name
);
174 new->res
.acc
= xmalloc( sizeof(*(new)->res
.acc
) );
175 *new->res
.acc
= *res
->res
.acc
;
176 new->res
.acc
->lvc
.language
= lang
;
177 new->res
.acc
->lvc
.version
= get_dup_version( lang
);
180 new->res
.dlg
= xmalloc( sizeof(*(new)->res
.dlg
) );
181 *new->res
.dlg
= *res
->res
.dlg
;
182 new->res
.dlg
->lvc
.language
= lang
;
183 new->res
.dlg
->lvc
.version
= get_dup_version( lang
);
186 new->res
.men
= xmalloc( sizeof(*(new)->res
.men
) );
187 *new->res
.men
= *res
->res
.men
;
188 new->res
.men
->lvc
.language
= lang
;
189 new->res
.men
->lvc
.version
= get_dup_version( lang
);
192 new->res
.stt
= xmalloc( sizeof(*(new)->res
.stt
) );
193 *new->res
.stt
= *res
->res
.stt
;
194 new->res
.stt
->lvc
.language
= lang
;
195 new->res
.stt
->lvc
.version
= get_dup_version( lang
);
198 new->res
.ver
= xmalloc( sizeof(*(new)->res
.ver
) );
199 *new->res
.ver
= *res
->res
.ver
;
200 new->res
.ver
->lvc
.language
= lang
;
201 new->res
.ver
->lvc
.version
= get_dup_version( lang
);
211 unsigned int id
, sub
;
215 { LANG_AFRIKAANS
, SUBLANG_NEUTRAL
, "af" },
216 { LANG_AFRIKAANS
, SUBLANG_AFRIKAANS_SOUTH_AFRICA
, "af_ZA" },
217 { LANG_ALBANIAN
, SUBLANG_NEUTRAL
, "sq" },
218 { LANG_ALBANIAN
, SUBLANG_ALBANIAN_ALBANIA
, "sq_AL" },
219 { LANG_AMHARIC
, SUBLANG_NEUTRAL
, "am" },
220 { LANG_AMHARIC
, SUBLANG_AMHARIC_ETHIOPIA
, "am_ET" },
221 { LANG_ARABIC
, SUBLANG_NEUTRAL
, "ar" },
222 { LANG_ARABIC
, SUBLANG_ARABIC_SAUDI_ARABIA
, "ar_SA" },
223 { LANG_ARABIC
, SUBLANG_ARABIC_IRAQ
, "ar_IQ" },
224 { LANG_ARABIC
, SUBLANG_ARABIC_EGYPT
, "ar_EG" },
225 { LANG_ARABIC
, SUBLANG_ARABIC_LIBYA
, "ar_LY" },
226 { LANG_ARABIC
, SUBLANG_ARABIC_ALGERIA
, "ar_DZ" },
227 { LANG_ARABIC
, SUBLANG_ARABIC_MOROCCO
, "ar_MA" },
228 { LANG_ARABIC
, SUBLANG_ARABIC_TUNISIA
, "ar_TN" },
229 { LANG_ARABIC
, SUBLANG_ARABIC_OMAN
, "ar_OM" },
230 { LANG_ARABIC
, SUBLANG_ARABIC_YEMEN
, "ar_YE" },
231 { LANG_ARABIC
, SUBLANG_ARABIC_SYRIA
, "ar_SY" },
232 { LANG_ARABIC
, SUBLANG_ARABIC_JORDAN
, "ar_JO" },
233 { LANG_ARABIC
, SUBLANG_ARABIC_LEBANON
, "ar_LB" },
234 { LANG_ARABIC
, SUBLANG_ARABIC_KUWAIT
, "ar_KW" },
235 { LANG_ARABIC
, SUBLANG_ARABIC_UAE
, "ar_AE" },
236 { LANG_ARABIC
, SUBLANG_ARABIC_BAHRAIN
, "ar_BH" },
237 { LANG_ARABIC
, SUBLANG_ARABIC_QATAR
, "ar_QA" },
238 { LANG_ARMENIAN
, SUBLANG_NEUTRAL
, "hy" },
239 { LANG_ARMENIAN
, SUBLANG_ARMENIAN_ARMENIA
, "hy_AM" },
240 { LANG_ASSAMESE
, SUBLANG_NEUTRAL
, "as" },
241 { LANG_ASSAMESE
, SUBLANG_ASSAMESE_INDIA
, "as_IN" },
242 { LANG_ASTURIAN
, SUBLANG_NEUTRAL
, "ast" },
243 { LANG_ASTURIAN
, SUBLANG_DEFAULT
, "ast_ES" },
244 { LANG_AZERBAIJANI
, SUBLANG_NEUTRAL
, "az" },
245 { LANG_AZERBAIJANI
, SUBLANG_AZERBAIJANI_AZERBAIJAN_LATIN
,"az_AZ@latin" },
246 { LANG_AZERBAIJANI
, SUBLANG_AZERBAIJANI_AZERBAIJAN_CYRILLIC
, "az_AZ@cyrillic" },
247 { LANG_BASQUE
, SUBLANG_NEUTRAL
, "eu" },
248 { LANG_BASQUE
, SUBLANG_BASQUE_BASQUE
, "eu_ES" },
249 { LANG_BELARUSIAN
, SUBLANG_NEUTRAL
, "be" },
250 { LANG_BELARUSIAN
, SUBLANG_BELARUSIAN_BELARUS
, "be_BY" },
251 { LANG_BENGALI
, SUBLANG_NEUTRAL
, "bn" },
252 { LANG_BENGALI
, SUBLANG_BENGALI_INDIA
, "bn_IN" },
253 { LANG_BENGALI
, SUBLANG_BENGALI_BANGLADESH
, "bn_BD" },
254 { LANG_BRETON
, SUBLANG_NEUTRAL
, "br" },
255 { LANG_BRETON
, SUBLANG_BRETON_FRANCE
, "br_FR" },
256 { LANG_BULGARIAN
, SUBLANG_NEUTRAL
, "bg" },
257 { LANG_BULGARIAN
, SUBLANG_BULGARIAN_BULGARIA
, "bg_BG" },
258 { LANG_CATALAN
, SUBLANG_NEUTRAL
, "ca" },
259 { LANG_CATALAN
, SUBLANG_CATALAN_CATALAN
, "ca_ES" },
260 { LANG_CHINESE
, SUBLANG_NEUTRAL
, "zh" },
261 { LANG_CHINESE
, SUBLANG_CHINESE_TRADITIONAL
, "zh_TW" },
262 { LANG_CHINESE
, SUBLANG_CHINESE_SIMPLIFIED
, "zh_CN" },
263 { LANG_CHINESE
, SUBLANG_CHINESE_HONGKONG
, "zh_HK" },
264 { LANG_CHINESE
, SUBLANG_CHINESE_SINGAPORE
, "zh_SG" },
265 { LANG_CHINESE
, SUBLANG_CHINESE_MACAU
, "zh_MO" },
266 { LANG_CZECH
, SUBLANG_NEUTRAL
, "cs" },
267 { LANG_CZECH
, SUBLANG_CZECH_CZECH_REPUBLIC
, "cs_CZ" },
268 { LANG_DANISH
, SUBLANG_NEUTRAL
, "da" },
269 { LANG_DANISH
, SUBLANG_DANISH_DENMARK
, "da_DK" },
270 { LANG_DIVEHI
, SUBLANG_NEUTRAL
, "dv" },
271 { LANG_DIVEHI
, SUBLANG_DIVEHI_MALDIVES
, "dv_MV" },
272 { LANG_DUTCH
, SUBLANG_NEUTRAL
, "nl" },
273 { LANG_DUTCH
, SUBLANG_DUTCH
, "nl_NL" },
274 { LANG_DUTCH
, SUBLANG_DUTCH_BELGIAN
, "nl_BE" },
275 { LANG_DUTCH
, SUBLANG_DUTCH_SURINAM
, "nl_SR" },
276 { LANG_ENGLISH
, SUBLANG_NEUTRAL
, "en" },
277 { LANG_ENGLISH
, SUBLANG_ENGLISH_US
, "en_US" },
278 { LANG_ENGLISH
, SUBLANG_ENGLISH_UK
, "en_GB" },
279 { LANG_ENGLISH
, SUBLANG_ENGLISH_AUS
, "en_AU" },
280 { LANG_ENGLISH
, SUBLANG_ENGLISH_CAN
, "en_CA" },
281 { LANG_ENGLISH
, SUBLANG_ENGLISH_NZ
, "en_NZ" },
282 { LANG_ENGLISH
, SUBLANG_ENGLISH_EIRE
, "en_IE" },
283 { LANG_ENGLISH
, SUBLANG_ENGLISH_SOUTH_AFRICA
, "en_ZA" },
284 { LANG_ENGLISH
, SUBLANG_ENGLISH_JAMAICA
, "en_JM" },
285 { LANG_ENGLISH
, SUBLANG_ENGLISH_CARIBBEAN
, "en_CB" },
286 { LANG_ENGLISH
, SUBLANG_ENGLISH_BELIZE
, "en_BZ" },
287 { LANG_ENGLISH
, SUBLANG_ENGLISH_TRINIDAD
, "en_TT" },
288 { LANG_ENGLISH
, SUBLANG_ENGLISH_ZIMBABWE
, "en_ZW" },
289 { LANG_ENGLISH
, SUBLANG_ENGLISH_PHILIPPINES
, "en_PH" },
290 { LANG_ENGLISH
, SUBLANG_ENGLISH_INDIA
, "en_IN" },
291 { LANG_ENGLISH
, SUBLANG_ENGLISH_MALAYSIA
, "en_MY" },
292 { LANG_ENGLISH
, SUBLANG_ENGLISH_SINGAPORE
, "en_SG" },
293 { LANG_ESTONIAN
, SUBLANG_NEUTRAL
, "et" },
294 { LANG_ESTONIAN
, SUBLANG_ESTONIAN_ESTONIA
, "et_EE" },
295 { LANG_FAEROESE
, SUBLANG_NEUTRAL
, "fo" },
296 { LANG_FAEROESE
, SUBLANG_FAEROESE_FAROE_ISLANDS
, "fo_FO" },
297 { LANG_FILIPINO
, SUBLANG_NEUTRAL
, "fil" },
298 { LANG_FILIPINO
, SUBLANG_FILIPINO_PHILIPPINES
, "fil_PH" },
299 { LANG_FINNISH
, SUBLANG_NEUTRAL
, "fi" },
300 { LANG_FINNISH
, SUBLANG_FINNISH_FINLAND
, "fi_FI" },
301 { LANG_FRENCH
, SUBLANG_NEUTRAL
, "fr" },
302 { LANG_FRENCH
, SUBLANG_FRENCH
, "fr_FR" },
303 { LANG_FRENCH
, SUBLANG_FRENCH_BELGIAN
, "fr_BE" },
304 { LANG_FRENCH
, SUBLANG_FRENCH_CANADIAN
, "fr_CA" },
305 { LANG_FRENCH
, SUBLANG_FRENCH_SWISS
, "fr_CH" },
306 { LANG_FRENCH
, SUBLANG_FRENCH_LUXEMBOURG
, "fr_LU" },
307 { LANG_FRENCH
, SUBLANG_FRENCH_MONACO
, "fr_MC" },
308 { LANG_GALICIAN
, SUBLANG_NEUTRAL
, "gl" },
309 { LANG_GALICIAN
, SUBLANG_GALICIAN_GALICIAN
, "gl_ES" },
310 { LANG_GEORGIAN
, SUBLANG_NEUTRAL
, "ka" },
311 { LANG_GEORGIAN
, SUBLANG_GEORGIAN_GEORGIA
, "ka_GE" },
312 { LANG_GERMAN
, SUBLANG_NEUTRAL
, "de" },
313 { LANG_GERMAN
, SUBLANG_GERMAN
, "de_DE" },
314 { LANG_GERMAN
, SUBLANG_GERMAN_SWISS
, "de_CH" },
315 { LANG_GERMAN
, SUBLANG_GERMAN_AUSTRIAN
, "de_AT" },
316 { LANG_GERMAN
, SUBLANG_GERMAN_LUXEMBOURG
, "de_LU" },
317 { LANG_GERMAN
, SUBLANG_GERMAN_LIECHTENSTEIN
, "de_LI" },
318 { LANG_GREEK
, SUBLANG_NEUTRAL
, "el" },
319 { LANG_GREEK
, SUBLANG_GREEK_GREECE
, "el_GR" },
320 { LANG_GUJARATI
, SUBLANG_NEUTRAL
, "gu" },
321 { LANG_GUJARATI
, SUBLANG_GUJARATI_INDIA
, "gu_IN" },
322 { LANG_HAUSA
, SUBLANG_NEUTRAL
, "ha" },
323 { LANG_HAUSA
, SUBLANG_HAUSA_NIGERIA
, "ha_NG" },
324 { LANG_HAWAIIAN
, SUBLANG_NEUTRAL
, "haw" },
325 { LANG_HAWAIIAN
, SUBLANG_HAWAIIAN_US
, "haw_US" },
326 { LANG_HEBREW
, SUBLANG_NEUTRAL
, "he" },
327 { LANG_HEBREW
, SUBLANG_HEBREW_ISRAEL
, "he_IL" },
328 { LANG_HINDI
, SUBLANG_NEUTRAL
, "hi" },
329 { LANG_HINDI
, SUBLANG_HINDI_INDIA
, "hi_IN" },
330 { LANG_HUNGARIAN
, SUBLANG_NEUTRAL
, "hu" },
331 { LANG_HUNGARIAN
, SUBLANG_HUNGARIAN_HUNGARY
, "hu_HU" },
332 { LANG_ICELANDIC
, SUBLANG_NEUTRAL
, "is" },
333 { LANG_ICELANDIC
, SUBLANG_ICELANDIC_ICELAND
, "is_IS" },
334 { LANG_IGBO
, SUBLANG_NEUTRAL
, "ig" },
335 { LANG_IGBO
, SUBLANG_IGBO_NIGERIA
, "ig_NG" },
336 { LANG_INDONESIAN
, SUBLANG_NEUTRAL
, "id" },
337 { LANG_INDONESIAN
, SUBLANG_INDONESIAN_INDONESIA
, "id_ID" },
338 { LANG_INUKTITUT
, SUBLANG_NEUTRAL
, "iu" },
339 { LANG_INUKTITUT
, SUBLANG_INUKTITUT_CANADA
, "iu_CA" },
340 { LANG_IRISH
, SUBLANG_NEUTRAL
, "ga" },
341 { LANG_IRISH
, SUBLANG_IRISH_IRELAND
, "ga_IE" },
342 { LANG_ITALIAN
, SUBLANG_NEUTRAL
, "it" },
343 { LANG_ITALIAN
, SUBLANG_ITALIAN
, "it_IT" },
344 { LANG_ITALIAN
, SUBLANG_ITALIAN_SWISS
, "it_CH" },
345 { LANG_JAPANESE
, SUBLANG_NEUTRAL
, "ja" },
346 { LANG_JAPANESE
, SUBLANG_JAPANESE_JAPAN
, "ja_JP" },
347 { LANG_KANNADA
, SUBLANG_NEUTRAL
, "kn" },
348 { LANG_KANNADA
, SUBLANG_KANNADA_INDIA
, "kn_IN" },
349 { LANG_KAZAK
, SUBLANG_NEUTRAL
, "kk" },
350 { LANG_KAZAK
, SUBLANG_KAZAK_KAZAKHSTAN
, "kk_KZ" },
351 { LANG_KHMER
, SUBLANG_NEUTRAL
, "km" },
352 { LANG_KHMER
, SUBLANG_KHMER_CAMBODIA
, "km_KH" },
353 { LANG_KINYARWANDA
, SUBLANG_NEUTRAL
, "rw" },
354 { LANG_KINYARWANDA
, SUBLANG_KINYARWANDA_RWANDA
, "rw_RW" },
355 { LANG_KONKANI
, SUBLANG_NEUTRAL
, "kok" },
356 { LANG_KONKANI
, SUBLANG_KONKANI_INDIA
, "kok_IN" },
357 { LANG_KOREAN
, SUBLANG_NEUTRAL
, "ko" },
358 { LANG_KOREAN
, SUBLANG_KOREAN
, "ko_KR" },
359 { LANG_KYRGYZ
, SUBLANG_NEUTRAL
, "ky" },
360 { LANG_KYRGYZ
, SUBLANG_KYRGYZ_KYRGYZSTAN
, "ky_KG" },
361 { LANG_LAO
, SUBLANG_NEUTRAL
, "lo" },
362 { LANG_LAO
, SUBLANG_LAO_LAO
, "lo_LA" },
363 { LANG_LATVIAN
, SUBLANG_NEUTRAL
, "lv" },
364 { LANG_LATVIAN
, SUBLANG_LATVIAN_LATVIA
, "lv_LV" },
365 { LANG_LITHUANIAN
, SUBLANG_NEUTRAL
, "lt" },
366 { LANG_LITHUANIAN
, SUBLANG_LITHUANIAN
, "lt_LT" },
367 { LANG_MACEDONIAN
, SUBLANG_NEUTRAL
, "mk" },
368 { LANG_MACEDONIAN
, SUBLANG_MACEDONIAN_MACEDONIA
, "mk_MK" },
369 { LANG_MALAY
, SUBLANG_NEUTRAL
, "ms" },
370 { LANG_MALAY
, SUBLANG_MALAY_MALAYSIA
, "ms_MY" },
371 { LANG_MALAY
, SUBLANG_MALAY_BRUNEI_DARUSSALAM
, "ms_BN" },
372 { LANG_MALAYALAM
, SUBLANG_NEUTRAL
, "ml" },
373 { LANG_MALAYALAM
, SUBLANG_MALAYALAM_INDIA
, "ml_IN" },
374 { LANG_MALTESE
, SUBLANG_NEUTRAL
, "mt" },
375 { LANG_MALTESE
, SUBLANG_MALTESE_MALTA
, "mt_MT" },
376 { LANG_MARATHI
, SUBLANG_NEUTRAL
, "mr" },
377 { LANG_MARATHI
, SUBLANG_MARATHI_INDIA
, "mr_IN" },
378 { LANG_MONGOLIAN
, SUBLANG_NEUTRAL
, "mn" },
379 { LANG_MONGOLIAN
, SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA
, "mn_MN" },
380 { LANG_MONGOLIAN
, SUBLANG_MONGOLIAN_PRC
, "mn_CN" },
381 { LANG_NEPALI
, SUBLANG_NEUTRAL
, "ne" },
382 { LANG_NEPALI
, SUBLANG_NEPALI_NEPAL
, "ne_NP" },
383 { LANG_NEPALI
, SUBLANG_NEPALI_INDIA
, "ne_IN" },
384 { LANG_NORWEGIAN
, SUBLANG_NORWEGIAN_BOKMAL
, "nb_NO" },
385 { LANG_NORWEGIAN
, SUBLANG_NORWEGIAN_NYNORSK
, "nn_NO" },
386 { LANG_ODIA
, SUBLANG_NEUTRAL
, "or" },
387 { LANG_ODIA
, SUBLANG_ODIA_INDIA
, "or_IN" },
388 { LANG_PASHTO
, SUBLANG_NEUTRAL
, "ps" },
389 { LANG_PASHTO
, SUBLANG_PASHTO_AFGHANISTAN
, "ps_AF" },
390 { LANG_PERSIAN
, SUBLANG_NEUTRAL
, "fa" },
391 { LANG_PERSIAN
, SUBLANG_PERSIAN_IRAN
, "fa_IR" },
392 { LANG_POLISH
, SUBLANG_NEUTRAL
, "pl" },
393 { LANG_POLISH
, SUBLANG_POLISH_POLAND
, "pl_PL" },
394 { LANG_PORTUGUESE
, SUBLANG_NEUTRAL
, "pt" },
395 { LANG_PORTUGUESE
, SUBLANG_PORTUGUESE_BRAZILIAN
, "pt_BR" },
396 { LANG_PORTUGUESE
, SUBLANG_PORTUGUESE_PORTUGAL
, "pt_PT" },
397 { LANG_PUNJABI
, SUBLANG_NEUTRAL
, "pa" },
398 { LANG_PUNJABI
, SUBLANG_PUNJABI_INDIA
, "pa_IN" },
399 { LANG_PUNJABI
, SUBLANG_PUNJABI_PAKISTAN
, "pa_PK" },
400 { LANG_ROMANIAN
, SUBLANG_NEUTRAL
, "ro" },
401 { LANG_ROMANIAN
, SUBLANG_ROMANIAN_ROMANIA
, "ro_RO" },
402 { LANG_ROMANSH
, SUBLANG_NEUTRAL
, "rm" },
403 { LANG_ROMANSH
, SUBLANG_ROMANSH_SWITZERLAND
, "rm_CH" },
404 { LANG_RUSSIAN
, SUBLANG_NEUTRAL
, "ru" },
405 { LANG_RUSSIAN
, SUBLANG_RUSSIAN_RUSSIA
, "ru_RU" },
406 { LANG_SAMI
, SUBLANG_NEUTRAL
, "se" },
407 { LANG_SAMI
, SUBLANG_SAMI_NORTHERN_NORWAY
, "se_NO" },
408 { LANG_SAMI
, SUBLANG_SAMI_NORTHERN_SWEDEN
, "se_SE" },
409 { LANG_SAMI
, SUBLANG_SAMI_NORTHERN_FINLAND
, "se_FI" },
410 { LANG_SANSKRIT
, SUBLANG_NEUTRAL
, "sa" },
411 { LANG_SANSKRIT
, SUBLANG_SANSKRIT_INDIA
, "sa_IN" },
412 { LANG_SCOTTISH_GAELIC
,SUBLANG_NEUTRAL
, "gd" },
413 { LANG_SCOTTISH_GAELIC
,SUBLANG_SCOTTISH_GAELIC
, "gd_GB" },
414 /* LANG_SERBIAN/LANG_CROATIAN/LANG_BOSNIAN are the same */
415 { LANG_SERBIAN
, SUBLANG_NEUTRAL
, "hr" },
416 { LANG_SERBIAN
, SUBLANG_SERBIAN_CROATIA
, "hr_HR" },
417 { LANG_SERBIAN
, SUBLANG_SERBIAN_LATIN
, "sr_RS@latin" },
418 { LANG_SERBIAN
, SUBLANG_SERBIAN_CYRILLIC
, "sr_RS@cyrillic" },
419 { LANG_SERBIAN
, SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN
, "hr_BA@latin" },
420 { LANG_SERBIAN
, SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN
, "bs_BA@latin" },
421 { LANG_SERBIAN
, SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_LATIN
, "sr_BA@latin" },
422 { LANG_SERBIAN
, SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_CYRILLIC
, "sr_BA@cyrillic" },
423 { LANG_SERBIAN
, SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC
, "bs_BA@cyrillic" },
424 { LANG_SERBIAN
, SUBLANG_SERBIAN_SERBIA_LATIN
, "sr_RS@latin" },
425 { LANG_SERBIAN
, SUBLANG_SERBIAN_SERBIA_CYRILLIC
, "sr_RS@cyrillic" },
426 { LANG_SERBIAN
, SUBLANG_SERBIAN_MONTENEGRO_LATIN
, "sr_ME@latin" },
427 { LANG_SERBIAN
, SUBLANG_SERBIAN_MONTENEGRO_CYRILLIC
, "sr_ME@cyrillic" },
428 { LANG_SINHALESE
, SUBLANG_NEUTRAL
, "si" },
429 { LANG_SINHALESE
, SUBLANG_SINHALESE_SRI_LANKA
, "si_LK" },
430 { LANG_SLOVAK
, SUBLANG_NEUTRAL
, "sk" },
431 { LANG_SLOVAK
, SUBLANG_SLOVAK_SLOVAKIA
, "sk_SK" },
432 { LANG_SLOVENIAN
, SUBLANG_NEUTRAL
, "sl" },
433 { LANG_SLOVENIAN
, SUBLANG_SLOVENIAN_SLOVENIA
, "sl_SI" },
434 { LANG_SOTHO
, SUBLANG_NEUTRAL
, "nso" },
435 { LANG_SOTHO
, SUBLANG_SOTHO_NORTHERN_SOUTH_AFRICA
, "nso_ZA" },
436 { LANG_SPANISH
, SUBLANG_NEUTRAL
, "es" },
437 { LANG_SPANISH
, SUBLANG_SPANISH
, "es_ES" },
438 { LANG_SPANISH
, SUBLANG_SPANISH_MEXICAN
, "es_MX" },
439 { LANG_SPANISH
, SUBLANG_SPANISH_MODERN
, "es_ES_modern" },
440 { LANG_SPANISH
, SUBLANG_SPANISH_GUATEMALA
, "es_GT" },
441 { LANG_SPANISH
, SUBLANG_SPANISH_COSTA_RICA
, "es_CR" },
442 { LANG_SPANISH
, SUBLANG_SPANISH_PANAMA
, "es_PA" },
443 { LANG_SPANISH
, SUBLANG_SPANISH_DOMINICAN_REPUBLIC
, "es_DO" },
444 { LANG_SPANISH
, SUBLANG_SPANISH_VENEZUELA
, "es_VE" },
445 { LANG_SPANISH
, SUBLANG_SPANISH_COLOMBIA
, "es_CO" },
446 { LANG_SPANISH
, SUBLANG_SPANISH_PERU
, "es_PE" },
447 { LANG_SPANISH
, SUBLANG_SPANISH_ARGENTINA
, "es_AR" },
448 { LANG_SPANISH
, SUBLANG_SPANISH_ECUADOR
, "es_EC" },
449 { LANG_SPANISH
, SUBLANG_SPANISH_CHILE
, "es_CL" },
450 { LANG_SPANISH
, SUBLANG_SPANISH_URUGUAY
, "es_UY" },
451 { LANG_SPANISH
, SUBLANG_SPANISH_PARAGUAY
, "es_PY" },
452 { LANG_SPANISH
, SUBLANG_SPANISH_BOLIVIA
, "es_BO" },
453 { LANG_SPANISH
, SUBLANG_SPANISH_EL_SALVADOR
, "es_SV" },
454 { LANG_SPANISH
, SUBLANG_SPANISH_HONDURAS
, "es_HN" },
455 { LANG_SPANISH
, SUBLANG_SPANISH_NICARAGUA
, "es_NI" },
456 { LANG_SPANISH
, SUBLANG_SPANISH_PUERTO_RICO
, "es_PR" },
457 { LANG_SPANISH
, SUBLANG_SPANISH_US
, "es_US" },
458 { LANG_SWAHILI
, SUBLANG_NEUTRAL
, "sw" },
459 { LANG_SWAHILI
, SUBLANG_SWAHILI_KENYA
, "sw_KE" },
460 { LANG_SWEDISH
, SUBLANG_NEUTRAL
, "sv" },
461 { LANG_SWEDISH
, SUBLANG_SWEDISH_SWEDEN
, "sv_SE" },
462 { LANG_SWEDISH
, SUBLANG_SWEDISH_FINLAND
, "sv_FI" },
463 { LANG_SYRIAC
, SUBLANG_NEUTRAL
, "syr" },
464 { LANG_SYRIAC
, SUBLANG_SYRIAC_SYRIA
, "syr_SY" },
465 { LANG_TAJIK
, SUBLANG_NEUTRAL
, "tg" },
466 { LANG_TAJIK
, SUBLANG_TAJIK_TAJIKISTAN
, "tg_TJ" },
467 { LANG_TAMIL
, SUBLANG_NEUTRAL
, "ta" },
468 { LANG_TAMIL
, SUBLANG_TAMIL_INDIA
, "ta_IN" },
469 { LANG_TATAR
, SUBLANG_NEUTRAL
, "tt" },
470 { LANG_TATAR
, SUBLANG_TATAR_RUSSIA
, "tt_TA" },
471 { LANG_TELUGU
, SUBLANG_NEUTRAL
, "te" },
472 { LANG_TELUGU
, SUBLANG_TELUGU_INDIA
, "te_IN" },
473 { LANG_THAI
, SUBLANG_NEUTRAL
, "th" },
474 { LANG_THAI
, SUBLANG_THAI_THAILAND
, "th_TH" },
475 { LANG_TIGRINYA
, SUBLANG_NEUTRAL
, "ti" },
476 { LANG_TIGRINYA
, SUBLANG_TIGRINYA_ETHIOPIA
, "ti_ET" },
477 { LANG_TIGRINYA
, SUBLANG_TIGRINYA_ERITREA
, "ti_ER" },
478 { LANG_TSWANA
, SUBLANG_NEUTRAL
, "tn" },
479 { LANG_TSWANA
, SUBLANG_TSWANA_SOUTH_AFRICA
, "tn_ZA" },
480 { LANG_TURKISH
, SUBLANG_NEUTRAL
, "tr" },
481 { LANG_TURKISH
, SUBLANG_TURKISH_TURKEY
, "tr_TR" },
482 { LANG_UIGHUR
, SUBLANG_NEUTRAL
, "ug" },
483 { LANG_UIGHUR
, SUBLANG_UIGHUR_PRC
, "ug_CN" },
484 { LANG_UKRAINIAN
, SUBLANG_NEUTRAL
, "uk" },
485 { LANG_UKRAINIAN
, SUBLANG_UKRAINIAN_UKRAINE
, "uk_UA" },
486 { LANG_URDU
, SUBLANG_NEUTRAL
, "ur" },
487 { LANG_URDU
, SUBLANG_URDU_PAKISTAN
, "ur_PK" },
488 { LANG_URDU
, SUBLANG_URDU_INDIA
, "ur_IN" },
489 { LANG_UZBEK
, SUBLANG_NEUTRAL
, "uz" },
490 { LANG_UZBEK
, SUBLANG_UZBEK_LATIN
, "uz_UZ@latin" },
491 { LANG_UZBEK
, SUBLANG_UZBEK_CYRILLIC
, "uz_UZ@cyrillic" },
492 { LANG_VIETNAMESE
, SUBLANG_NEUTRAL
, "vi" },
493 { LANG_VIETNAMESE
, SUBLANG_VIETNAMESE_VIETNAM
, "vi_VN" },
494 { LANG_WELSH
, SUBLANG_NEUTRAL
, "cy" },
495 { LANG_WELSH
, SUBLANG_WELSH_UNITED_KINGDOM
, "cy_GB" },
496 { LANG_WOLOF
, SUBLANG_NEUTRAL
, "wo" },
497 { LANG_WOLOF
, SUBLANG_WOLOF_SENEGAL
, "wo_SN" },
498 { LANG_XHOSA
, SUBLANG_NEUTRAL
, "xh" },
499 { LANG_XHOSA
, SUBLANG_XHOSA_SOUTH_AFRICA
, "xh_ZA" },
500 { LANG_YORUBA
, SUBLANG_NEUTRAL
, "yo" },
501 { LANG_YORUBA
, SUBLANG_YORUBA_NIGERIA
, "yo_NG" },
502 { LANG_ZULU
, SUBLANG_NEUTRAL
, "zu" },
503 { LANG_ZULU
, SUBLANG_ZULU_SOUTH_AFRICA
, "zu_ZA" },
505 #ifdef LANG_ESPERANTO
506 { LANG_ESPERANTO
, SUBLANG_DEFAULT
, "eo" },
509 { LANG_WALON
, SUBLANG_NEUTRAL
, "wa" },
510 { LANG_WALON
, SUBLANG_DEFAULT
, "wa_BE" },
513 { LANG_CORNISH
, SUBLANG_NEUTRAL
, "kw" },
514 { LANG_CORNISH
, SUBLANG_DEFAULT
, "kw_GB" },
516 #ifdef LANG_MANX_GAELIC
517 { LANG_MANX_GAELIC
, SUBLANG_MANX_GAELIC
, "gv_GB" },
521 #ifndef HAVE_LIBGETTEXTPO
523 void write_pot_file( const char *outname
)
525 error( "PO files not supported in this wrc build\n" );
528 void write_po_files( const char *outname
)
530 error( "PO files not supported in this wrc build\n" );
533 #else /* HAVE_LIBGETTEXTPO */
535 static void po_xerror( int severity
, po_message_t message
,
536 const char *filename
, size_t lineno
, size_t column
,
537 int multiline_p
, const char *message_text
)
539 fprintf( stderr
, "%s:%u:%u: %s\n",
540 filename
, (unsigned int)lineno
, (unsigned int)column
, message_text
);
541 if (severity
) exit(1);
544 static void po_xerror2( int severity
, po_message_t message1
,
545 const char *filename1
, size_t lineno1
, size_t column1
,
546 int multiline_p1
, const char *message_text1
,
547 po_message_t message2
,
548 const char *filename2
, size_t lineno2
, size_t column2
,
549 int multiline_p2
, const char *message_text2
)
551 fprintf( stderr
, "%s:%u:%u: %s\n",
552 filename1
, (unsigned int)lineno1
, (unsigned int)column1
, message_text1
);
553 fprintf( stderr
, "%s:%u:%u: %s\n",
554 filename2
, (unsigned int)lineno2
, (unsigned int)column2
, message_text2
);
555 if (severity
) exit(1);
558 static const struct po_xerror_handler po_xerror_handler
= { po_xerror
, po_xerror2
};
560 static po_message_t
find_message( po_file_t po
, const char *msgid
, const char *msgctxt
,
561 po_message_iterator_t
*iterator
)
566 *iterator
= po_message_iterator( po
, NULL
);
567 while ((msg
= po_next_message( *iterator
)))
569 if (strcmp( po_message_msgid( msg
), msgid
)) continue;
571 if (!(context
= po_message_msgctxt( msg
))) continue;
572 if (!strcmp( context
, msgctxt
)) break;
577 static void add_po_string( po_file_t po
, const string_t
*msgid
, const string_t
*msgstr
, language_t lang
)
579 static const char dnt
[] = "do not translate";
581 po_message_iterator_t iterator
;
583 char *id
, *id_buffer
, *context
, *str
= NULL
, *str_buffer
= NULL
;
585 if (!msgid
->size
) return;
587 id_buffer
= id
= convert_msgid_ascii( msgid
, 1 );
588 context
= get_message_context( &id
);
589 if (context
&& strcmp(context
, dnt
) == 0)
591 /* This string should not be translated */
598 codepage
= get_language_codepage( lang
);
599 str
= str_buffer
= convert_string_utf8( msgstr
, codepage
);
600 if (is_english( lang
)) get_message_context( &str
);
602 if (!(msg
= find_message( po
, id
, context
, &iterator
)))
604 msg
= po_message_create();
605 po_message_set_msgid( msg
, id
);
606 po_message_set_msgstr( msg
, str
? str
: "" );
607 if (context
) po_message_set_msgctxt( msg
, context
);
608 po_message_insert( iterator
, msg
);
610 if (msgid
->loc
.file
) po_message_add_filepos( msg
, msgid
->loc
.file
, msgid
->loc
.line
);
611 po_message_iterator_free( iterator
);
623 static struct list po_file_langs
= LIST_INIT( po_file_langs
);
625 static po_file_t
create_po_file(void)
629 po_message_iterator_t iterator
;
631 po
= po_file_create();
632 iterator
= po_message_iterator( po
, NULL
);
633 msg
= po_message_create();
634 po_message_set_msgid( msg
, "" );
635 po_message_set_msgstr( msg
,
636 "Project-Id-Version: Wine\n"
637 "Report-Msgid-Bugs-To: https://bugs.winehq.org\n"
638 "POT-Creation-Date: N/A\n"
639 "PO-Revision-Date: N/A\n"
640 "Last-Translator: Automatically generated\n"
641 "Language-Team: none\n"
642 "MIME-Version: 1.0\n"
643 "Content-Type: text/plain; charset=UTF-8\n"
644 "Content-Transfer-Encoding: 8bit\n" );
645 po_message_insert( iterator
, msg
);
646 po_message_iterator_free( iterator
);
650 static po_file_t
get_po_file( language_t lang
)
652 struct po_file_lang
*po_file
;
654 LIST_FOR_EACH_ENTRY( po_file
, &po_file_langs
, struct po_file_lang
, entry
)
655 if (po_file
->lang
== lang
) return po_file
->po
;
657 /* create a new one */
658 po_file
= xmalloc( sizeof(*po_file
) );
659 po_file
->lang
= lang
;
660 po_file
->po
= create_po_file();
661 list_add_tail( &po_file_langs
, &po_file
->entry
);
665 static const char *get_language_name( language_t lang
)
667 static char name
[20];
670 for (i
= 0; i
< ARRAY_SIZE(languages
); i
++)
671 if (MAKELANGID( languages
[i
].id
, languages
[i
].sub
) == lang
)
672 return languages
[i
].name
;
674 sprintf( name
, "%04x", lang
);
678 static char *get_po_file_name( language_t lang
)
680 return strmake( "%s.po", get_language_name( lang
) );
683 static unsigned int flush_po_files( const char *output_name
)
685 struct po_file_lang
*po_file
, *next
;
686 unsigned int count
= 0;
688 LIST_FOR_EACH_ENTRY_SAFE( po_file
, next
, &po_file_langs
, struct po_file_lang
, entry
)
690 char *name
= get_po_file_name( po_file
->lang
);
693 if (!strcmp( get_basename(output_name
), name
))
695 po_file_write( po_file
->po
, name
, &po_xerror_handler
);
699 else /* no specified output name, output a file for every language found */
701 po_file_write( po_file
->po
, name
, &po_xerror_handler
);
703 fprintf( stderr
, "created %s\n", name
);
705 po_file_free( po_file
->po
);
706 list_remove( &po_file
->entry
);
713 static void add_pot_stringtable( po_file_t po
, const resource_t
*res
)
715 const stringtable_t
*stt
= res
->res
.stt
;
720 for (i
= 0; i
< stt
->nentries
; i
++)
721 if (stt
->entries
[i
].str
) add_po_string( po
, stt
->entries
[i
].str
, NULL
, 0 );
726 static void add_po_stringtable( const resource_t
*english
, const resource_t
*res
)
728 const stringtable_t
*english_stt
= english
->res
.stt
;
729 const stringtable_t
*stt
= res
->res
.stt
;
730 po_file_t po
= get_po_file( stt
->lvc
.language
);
733 while (english_stt
&& stt
)
735 for (i
= 0; i
< stt
->nentries
; i
++)
736 if (english_stt
->entries
[i
].str
&& stt
->entries
[i
].str
)
737 add_po_string( po
, english_stt
->entries
[i
].str
, stt
->entries
[i
].str
, stt
->lvc
.language
);
739 english_stt
= english_stt
->next
;
743 static void add_pot_dialog_controls( po_file_t po
, const control_t
*ctrl
)
747 if (control_has_title( ctrl
)) add_po_string( po
, ctrl
->title
->name
.s_name
, NULL
, 0 );
752 static void add_pot_dialog( po_file_t po
, const resource_t
*res
)
754 const dialog_t
*dlg
= res
->res
.dlg
;
756 if (dlg
->title
) add_po_string( po
, dlg
->title
, NULL
, 0 );
757 add_pot_dialog_controls( po
, dlg
->controls
);
760 static void compare_dialogs( const dialog_t
*english_dlg
, const dialog_t
*dlg
)
762 const control_t
*english_ctrl
, *ctrl
;
763 unsigned int style
= 0, exstyle
= 0, english_style
= 0, english_exstyle
= 0;
765 char *title
= english_dlg
->title
? convert_msgid_ascii( english_dlg
->title
, 0 ) : xstrdup("??");
767 if (english_dlg
->width
!= dlg
->width
|| english_dlg
->height
!= dlg
->height
)
768 warning( "%s: dialog %s doesn't have the same size (%d,%d vs %d,%d)\n",
769 get_language_name( dlg
->lvc
.language
), title
, dlg
->width
, dlg
->height
,
770 english_dlg
->width
, english_dlg
->height
);
772 if (dlg
->gotstyle
) style
= dlg
->style
->or_mask
;
773 if (dlg
->gotexstyle
) exstyle
= dlg
->exstyle
->or_mask
;
774 if (english_dlg
->gotstyle
) english_style
= english_dlg
->style
->or_mask
;
775 if (english_dlg
->gotexstyle
) english_exstyle
= english_dlg
->exstyle
->or_mask
;
776 if (is_rtl_language( dlg
->lvc
.language
)) english_exstyle
|= WS_EX_LAYOUTRTL
;
778 if (english_style
!= style
)
779 warning( "%s: dialog %s doesn't have the same style (%08x vs %08x)\n",
780 get_language_name( dlg
->lvc
.language
), title
, style
, english_style
);
781 if (english_exstyle
!= exstyle
)
782 warning( "%s: dialog %s doesn't have the same exstyle (%08x vs %08x)\n",
783 get_language_name( dlg
->lvc
.language
), title
, exstyle
, english_exstyle
);
785 if (english_dlg
->font
|| dlg
->font
)
787 int size
= 0, english_size
= 0;
788 char *font
= NULL
, *english_font
= NULL
;
790 if (english_dlg
->font
)
792 english_font
= convert_msgid_ascii( english_dlg
->font
->name
, 0 );
793 english_size
= english_dlg
->font
->size
;
797 font
= convert_msgid_ascii( dlg
->font
->name
, 0 );
798 size
= dlg
->font
->size
;
800 if (uses_larger_font( dlg
->lvc
.language
)) english_size
++;
802 if (!english_font
|| !font
|| strcasecmp( english_font
, font
) || english_size
!= size
)
803 warning( "%s: dialog %s doesn't have the same font (%s %u vs %s %u)\n",
804 get_language_name(dlg
->lvc
.language
), title
,
805 english_font
? english_font
: "default", english_size
,
806 font
? font
: "default", size
);
808 free( english_font
);
810 english_ctrl
= english_dlg
->controls
;
811 ctrl
= dlg
->controls
;
812 for ( ; english_ctrl
&& ctrl
; ctrl
= ctrl
->next
, english_ctrl
= english_ctrl
->next
)
814 if (control_has_title( english_ctrl
))
815 name
= convert_msgid_ascii( english_ctrl
->title
->name
.s_name
, 0 );
817 name
= strmake( "%d", ctrl
->id
);
819 if (english_ctrl
->width
!= ctrl
->width
|| english_ctrl
->height
!= ctrl
->height
)
820 warning( "%s: dialog %s control %s doesn't have the same size (%d,%d vs %d,%d)\n",
821 get_language_name( dlg
->lvc
.language
), title
, name
,
822 ctrl
->width
, ctrl
->height
, english_ctrl
->width
, english_ctrl
->height
);
823 if (english_ctrl
->x
!= ctrl
->x
|| english_ctrl
->y
!= ctrl
->y
)
824 warning( "%s: dialog %s control %s doesn't have the same position (%d,%d vs %d,%d)\n",
825 get_language_name( dlg
->lvc
.language
), title
, name
,
826 ctrl
->x
, ctrl
->y
, english_ctrl
->x
, english_ctrl
->y
);
832 static void add_po_dialog_controls( po_file_t po
, const control_t
*english_ctrl
,
833 const control_t
*ctrl
, language_t lang
)
835 while (english_ctrl
&& ctrl
)
837 if (control_has_title( english_ctrl
) && control_has_title( ctrl
))
838 add_po_string( po
, english_ctrl
->title
->name
.s_name
, ctrl
->title
->name
.s_name
, lang
);
841 english_ctrl
= english_ctrl
->next
;
845 static void add_po_dialog( const resource_t
*english
, const resource_t
*res
)
847 const dialog_t
*english_dlg
= english
->res
.dlg
;
848 const dialog_t
*dlg
= res
->res
.dlg
;
849 po_file_t po
= get_po_file( dlg
->lvc
.language
);
851 compare_dialogs( english_dlg
, dlg
);
853 if (english_dlg
->title
&& dlg
->title
)
854 add_po_string( po
, english_dlg
->title
, dlg
->title
, dlg
->lvc
.language
);
855 add_po_dialog_controls( po
, english_dlg
->controls
, dlg
->controls
, dlg
->lvc
.language
);
858 static void add_pot_menu_items( po_file_t po
, const menu_item_t
*item
)
862 if (item
->name
) add_po_string( po
, item
->name
, NULL
, 0 );
863 if (item
->popup
) add_pot_menu_items( po
, item
->popup
);
868 static void add_pot_menu( po_file_t po
, const resource_t
*res
)
870 add_pot_menu_items( po
, res
->res
.men
->items
);
873 static void add_po_menu_items( po_file_t po
, const menu_item_t
*english_item
,
874 const menu_item_t
*item
, language_t lang
)
876 while (english_item
&& item
)
878 if (english_item
->name
&& item
->name
)
879 add_po_string( po
, english_item
->name
, item
->name
, lang
);
880 if (english_item
->popup
&& item
->popup
)
881 add_po_menu_items( po
, english_item
->popup
, item
->popup
, lang
);
883 english_item
= english_item
->next
;
887 static void add_po_menu( const resource_t
*english
, const resource_t
*res
)
889 const menu_item_t
*english_items
= english
->res
.men
->items
;
890 const menu_item_t
*items
= res
->res
.men
->items
;
891 po_file_t po
= get_po_file( res
->res
.men
->lvc
.language
);
893 add_po_menu_items( po
, english_items
, items
, res
->res
.men
->lvc
.language
);
896 static int string_has_context( const string_t
*str
)
898 char *id
, *id_buffer
, *context
;
900 id_buffer
= id
= convert_msgid_ascii( str
, 1 );
901 context
= get_message_context( &id
);
903 return context
!= NULL
;
906 static void add_pot_accel( po_file_t po
, const resource_t
*res
)
908 event_t
*event
= res
->res
.acc
->events
;
912 /* accelerators without a context don't make sense in po files */
913 if (event
->str
&& string_has_context( event
->str
))
914 add_po_string( po
, event
->str
, NULL
, 0 );
919 static void add_po_accel( const resource_t
*english
, const resource_t
*res
)
921 event_t
*english_event
= english
->res
.acc
->events
;
922 event_t
*event
= res
->res
.acc
->events
;
923 po_file_t po
= get_po_file( res
->res
.acc
->lvc
.language
);
925 while (english_event
&& event
)
927 if (english_event
->str
&& event
->str
&& string_has_context( english_event
->str
))
928 add_po_string( po
, english_event
->str
, event
->str
, res
->res
.acc
->lvc
.language
);
930 english_event
= english_event
->next
;
934 static ver_block_t
*get_version_langcharset_block( ver_block_t
*block
)
936 ver_block_t
*stringfileinfo
= NULL
;
937 char *translation
= NULL
;
940 for (; block
; block
= block
->next
)
943 name
= convert_msgid_ascii( block
->name
, 0 );
944 if (!strcasecmp( name
, "stringfileinfo" ))
945 stringfileinfo
= block
;
946 else if (!strcasecmp( name
, "varfileinfo" ))
948 for (val
= block
->values
; val
; val
= val
->next
)
950 char *key
= convert_msgid_ascii( val
->key
, 0 );
951 if (val
->type
== val_words
&&
952 !strcasecmp( key
, "Translation" ) &&
953 val
->value
.words
->nwords
>= 2)
954 translation
= strmake( "%04x%04x",
955 val
->value
.words
->words
[0],
956 val
->value
.words
->words
[1] );
963 if (!stringfileinfo
|| !translation
) return NULL
;
965 for (val
= stringfileinfo
->values
; val
; val
= val
->next
)
968 if (val
->type
!= val_block
) continue;
969 block_name
= convert_msgid_ascii( val
->value
.block
->name
, 0 );
970 if (!strcasecmp( block_name
, translation
))
974 return val
->value
.block
;
982 static int version_value_needs_translation( const ver_value_t
*val
)
987 if (val
->type
!= val_str
) return 0;
988 if (!(key
= convert_msgid_ascii( val
->key
, 0 ))) return 0;
990 /* most values contain version numbers or file names, only translate a few specific ones */
991 ret
= (!strcasecmp( key
, "FileDescription" ) || !strcasecmp( key
, "ProductName" ));
997 static void add_pot_versioninfo( po_file_t po
, const resource_t
*res
)
1000 ver_block_t
*langcharset
= get_version_langcharset_block( res
->res
.ver
->blocks
);
1002 if (!langcharset
) return;
1003 for (val
= langcharset
->values
; val
; val
= val
->next
)
1004 if (version_value_needs_translation( val
))
1005 add_po_string( po
, val
->value
.str
, NULL
, 0 );
1008 static void add_po_versioninfo( const resource_t
*english
, const resource_t
*res
)
1010 const ver_block_t
*langcharset
= get_version_langcharset_block( res
->res
.ver
->blocks
);
1011 const ver_block_t
*english_langcharset
= get_version_langcharset_block( english
->res
.ver
->blocks
);
1012 ver_value_t
*val
, *english_val
;
1013 po_file_t po
= get_po_file( res
->res
.ver
->lvc
.language
);
1015 if (!langcharset
&& !english_langcharset
) return;
1016 val
= langcharset
->values
;
1017 english_val
= english_langcharset
->values
;
1018 while (english_val
&& val
)
1020 if (val
->type
== val_str
)
1021 add_po_string( po
, english_val
->value
.str
, val
->value
.str
, res
->res
.ver
->lvc
.language
);
1023 english_val
= english_val
->next
;
1027 static resource_t
*find_english_resource( resource_t
*res
)
1031 for (ptr
= resource_top
; ptr
; ptr
= ptr
->next
)
1033 if (ptr
->type
!= res
->type
) continue;
1034 if (!ptr
->lan
) continue;
1035 if (!is_english( ptr
->lan
)) continue;
1036 if (compare_name_id( ptr
->name
, res
->name
)) continue;
1042 void write_pot_file( const char *outname
)
1045 po_file_t po
= create_po_file();
1047 for (res
= resource_top
; res
; res
= res
->next
)
1049 if (!is_english( res
->lan
)) continue;
1053 case res_acc
: add_pot_accel( po
, res
); break;
1054 case res_dlg
: add_pot_dialog( po
, res
); break;
1055 case res_men
: add_pot_menu( po
, res
); break;
1056 case res_stt
: add_pot_stringtable( po
, res
); break;
1057 case res_ver
: add_pot_versioninfo( po
, res
); break;
1058 case res_msg
: break; /* FIXME */
1062 po_file_write( po
, outname
, &po_xerror_handler
);
1066 void write_po_files( const char *outname
)
1068 resource_t
*res
, *english
;
1070 for (res
= resource_top
; res
; res
= res
->next
)
1072 if (!(english
= find_english_resource( res
))) continue;
1075 case res_acc
: add_po_accel( english
, res
); break;
1076 case res_dlg
: add_po_dialog( english
, res
); break;
1077 case res_men
: add_po_menu( english
, res
); break;
1078 case res_stt
: add_po_stringtable( english
, res
); break;
1079 case res_ver
: add_po_versioninfo( english
, res
); break;
1080 case res_msg
: break; /* FIXME */
1084 if (!flush_po_files( outname
))
1086 if (outname
) error( "No translations found for %s\n", outname
);
1087 else error( "No translations found\n" );
1091 #endif /* HAVE_LIBGETTEXTPO */
1093 static struct mo_file
*mo_file
;
1095 static void byteswap( unsigned int *data
, unsigned int count
)
1099 for (i
= 0; i
< count
; i
++)
1100 data
[i
] = data
[i
] >> 24 | (data
[i
] >> 8 & 0xff00) | (data
[i
] << 8 & 0xff0000) | data
[i
] << 24;
1103 static void load_mo_file( const char *name
)
1107 if (!(mo_file
= read_file( name
, &size
))) fatal_perror( "Failed to read %s", name
);
1111 if (size
< sizeof(*mo_file
))
1112 error( "%s is not a valid .mo file\n", name
);
1113 if (mo_file
->magic
== 0xde120495)
1114 byteswap( &mo_file
->revision
, 4 );
1115 else if (mo_file
->magic
!= 0x950412de)
1116 error( "%s is not a valid .mo file\n", name
);
1117 if ((mo_file
->revision
>> 16) > 1)
1118 error( "%s: unsupported file version %x\n", name
, mo_file
->revision
);
1119 if (mo_file
->msgid_off
>= size
||
1120 mo_file
->msgstr_off
>= size
||
1121 size
< sizeof(*mo_file
) + 2 * 8 * mo_file
->count
)
1122 error( "%s: corrupted file\n", name
);
1124 if (mo_file
->magic
== 0xde120495)
1126 byteswap( (unsigned int *)((char *)mo_file
+ mo_file
->msgid_off
), 2 * mo_file
->count
);
1127 byteswap( (unsigned int *)((char *)mo_file
+ mo_file
->msgstr_off
), 2 * mo_file
->count
);
1131 static void free_mo_file(void)
1137 static inline const char *get_mo_msgid( int index
)
1139 const char *base
= (const char *)mo_file
;
1140 const unsigned int *offsets
= (const unsigned int *)(base
+ mo_file
->msgid_off
);
1141 return base
+ offsets
[2 * index
+ 1];
1144 static inline const char *get_mo_msgstr( int index
)
1146 const char *base
= (const char *)mo_file
;
1147 const unsigned int *offsets
= (const unsigned int *)(base
+ mo_file
->msgstr_off
);
1148 return base
+ offsets
[2 * index
+ 1];
1151 static const char *get_msgstr( const char *msgid
, const char *context
, int *found
)
1153 int pos
, res
, min
, max
;
1154 const char *ret
= msgid
;
1157 if (!mo_file
) /* strings containing a context still need to be transformed */
1159 if (context
) (*found
)++;
1163 if (context
) id
= strmake( "%s%c%s", context
, 4, msgid
);
1165 max
= mo_file
->count
- 1;
1168 pos
= (min
+ max
) / 2;
1169 res
= strcmp( get_mo_msgid(pos
), id
? id
: msgid
);
1172 const char *str
= get_mo_msgstr( pos
);
1173 if (str
[0]) /* ignore empty strings */
1180 if (res
> 0) max
= pos
- 1;
1187 static string_t
*translate_string( string_t
*str
, int *found
)
1189 string_t ustr
, *new;
1191 char *buffer
, *msgid
, *context
;
1193 if (!str
->size
|| !(buffer
= convert_msgid_ascii( str
, 0 )))
1194 return convert_string_unicode( str
, 1252 );
1197 context
= get_message_context( &msgid
);
1198 transl
= get_msgstr( msgid
, context
, found
);
1200 ustr
.type
= str_char
;
1201 ustr
.size
= strlen( transl
);
1202 ustr
.str
.cstr
= (char *)transl
;
1203 ustr
.loc
= str
->loc
;
1205 new = convert_string_unicode( &ustr
, CP_UTF8
);
1210 static control_t
*translate_controls( control_t
*ctrl
, int *found
)
1212 control_t
*new, *head
= NULL
, *tail
= NULL
;
1216 new = xmalloc( sizeof(*new) );
1218 if (control_has_title( ctrl
))
1220 new->title
= new_name_id();
1221 *new->title
= *ctrl
->title
;
1222 new->title
->name
.s_name
= translate_string( ctrl
->title
->name
.s_name
, found
);
1224 else new->title
= dup_name_id( ctrl
->title
);
1225 new->ctlclass
= dup_name_id( ctrl
->ctlclass
);
1226 if (tail
) tail
->next
= new;
1236 static menu_item_t
*translate_items( menu_item_t
*item
, int *found
)
1238 menu_item_t
*new, *head
= NULL
, *tail
= NULL
;
1242 new = xmalloc( sizeof(*new) );
1244 if (item
->name
) new->name
= translate_string( item
->name
, found
);
1245 if (item
->popup
) new->popup
= translate_items( item
->popup
, found
);
1246 if (tail
) tail
->next
= new;
1256 static stringtable_t
*translate_stringtable( stringtable_t
*stt
, language_t lang
, int *found
)
1258 stringtable_t
*new, *head
= NULL
, *tail
= NULL
;
1263 new = xmalloc( sizeof(*new) );
1265 new->lvc
.language
= lang
;
1266 new->lvc
.version
= get_dup_version( lang
);
1267 new->entries
= xmalloc( new->nentries
* sizeof(*new->entries
) );
1268 memcpy( new->entries
, stt
->entries
, new->nentries
* sizeof(*new->entries
) );
1269 for (i
= 0; i
< stt
->nentries
; i
++)
1270 if (stt
->entries
[i
].str
)
1271 new->entries
[i
].str
= translate_string( stt
->entries
[i
].str
, found
);
1273 if (tail
) tail
->next
= new;
1283 static void translate_dialog( dialog_t
*dlg
, dialog_t
*new, int *found
)
1285 if (dlg
->title
) new->title
= translate_string( dlg
->title
, found
);
1286 if (is_rtl_language( new->lvc
.language
))
1288 new->gotexstyle
= TRUE
;
1289 if (dlg
->gotexstyle
)
1290 new->exstyle
= new_style( dlg
->exstyle
->or_mask
| WS_EX_LAYOUTRTL
, dlg
->exstyle
->and_mask
);
1292 new->exstyle
= new_style( WS_EX_LAYOUTRTL
, 0 );
1296 new->font
= xmalloc( sizeof(*dlg
->font
) );
1297 *new->font
= *dlg
->font
;
1298 if (uses_larger_font( new->lvc
.language
)) new->font
->size
++;
1299 new->font
->name
= convert_string_unicode( dlg
->font
->name
, 1252 );
1301 new->controls
= translate_controls( dlg
->controls
, found
);
1304 static event_t
*translate_accel( accelerator_t
*acc
, accelerator_t
*new, int *found
)
1306 event_t
*event
, *new_ev
, *head
= NULL
, *tail
= NULL
;
1308 event
= acc
->events
;
1311 new_ev
= new_event();
1313 if (event
->str
) new_ev
->str
= translate_string( event
->str
, found
);
1314 if (tail
) tail
->next
= new_ev
;
1316 new_ev
->next
= NULL
;
1317 new_ev
->prev
= tail
;
1319 event
= event
->next
;
1324 static ver_value_t
*translate_langcharset_values( ver_value_t
*val
, language_t lang
, int *found
)
1326 ver_value_t
*new_val
, *head
= NULL
, *tail
= NULL
;
1329 new_val
= new_ver_value();
1331 if (val
->type
== val_str
)
1332 new_val
->value
.str
= translate_string( val
->value
.str
, found
);
1333 if (tail
) tail
->next
= new_val
;
1334 else head
= new_val
;
1335 new_val
->next
= NULL
;
1336 new_val
->prev
= tail
;
1343 static ver_value_t
*translate_stringfileinfo( ver_value_t
*val
, language_t lang
, int *found
)
1346 ver_value_t
*new_val
, *head
= NULL
, *tail
= NULL
;
1347 const char *english_block_name
[2] = { "040904b0", "040904e4" };
1348 char *block_name
[2];
1349 language_t langid
= get_default_sublang( lang
);
1351 block_name
[0] = strmake( "%04x%04x", langid
, 1200 );
1352 block_name
[1] = strmake( "%04x%04x", langid
, get_language_codepage( lang
));
1356 new_val
= new_ver_value();
1358 if (val
->type
== val_block
)
1360 ver_block_t
*blk
, *blk_head
= NULL
, *blk_tail
= NULL
;
1361 for (blk
= val
->value
.block
; blk
; blk
= blk
->next
)
1363 ver_block_t
*new_blk
;
1365 new_blk
= new_ver_block();
1367 name
= convert_msgid_ascii( blk
->name
, 0 );
1368 for (i
= 0; i
< ARRAY_SIZE(block_name
); i
++)
1370 if (!strcasecmp( name
, english_block_name
[i
] ))
1373 str
.type
= str_char
;
1374 str
.size
= strlen( block_name
[i
] ) + 1;
1375 str
.str
.cstr
= block_name
[i
];
1376 str
.loc
= blk
->name
->loc
;
1377 new_blk
->name
= convert_string_unicode( &str
, CP_UTF8
);
1378 new_blk
->values
= translate_langcharset_values( blk
->values
, lang
, found
);
1382 if (blk_tail
) blk_tail
->next
= new_blk
;
1383 else blk_head
= new_blk
;
1384 new_blk
->next
= NULL
;
1385 new_blk
->prev
= blk_tail
;
1388 new_val
->value
.block
= blk_head
;
1390 if (tail
) tail
->next
= new_val
;
1391 else head
= new_val
;
1392 new_val
->next
= NULL
;
1393 new_val
->prev
= tail
;
1398 for (i
= 0; i
< ARRAY_SIZE(block_name
); i
++)
1399 free( block_name
[i
] );
1403 static ver_value_t
*translate_varfileinfo( ver_value_t
*val
, language_t lang
)
1405 ver_value_t
*new_val
, *head
= NULL
, *tail
= NULL
;
1409 new_val
= new_ver_value();
1411 if (val
->type
== val_words
)
1413 char *key
= convert_msgid_ascii( val
->key
, 0 );
1414 if (!strcasecmp( key
, "Translation" ) &&
1415 val
->value
.words
->nwords
== 2 &&
1416 val
->value
.words
->words
[0] == MAKELANGID( LANG_ENGLISH
, SUBLANG_ENGLISH_US
))
1418 ver_words_t
*new_words
;
1420 language_t langid
= get_default_sublang( lang
);
1421 new_words
= new_ver_words( langid
);
1422 if (val
->value
.words
->words
[1] == 1200)
1425 codepage
= get_language_codepage( lang
);
1426 new_val
->value
.words
= add_ver_words( new_words
, codepage
);
1430 if (tail
) tail
->next
= new_val
;
1431 else head
= new_val
;
1432 new_val
->next
= NULL
;
1433 new_val
->prev
= tail
;
1440 static ver_block_t
*translate_versioninfo( ver_block_t
*blk
, language_t lang
, int *found
)
1442 ver_block_t
*new_blk
, *head
= NULL
, *tail
= NULL
;
1447 new_blk
= new_ver_block();
1449 name
= convert_msgid_ascii( blk
->name
, 0 );
1450 if (!strcasecmp( name
, "stringfileinfo" ))
1451 new_blk
->values
= translate_stringfileinfo( blk
->values
, lang
, found
);
1452 else if (!strcasecmp( name
, "varfileinfo" ))
1453 new_blk
->values
= translate_varfileinfo( blk
->values
, lang
);
1455 if (tail
) tail
->next
= new_blk
;
1456 else head
= new_blk
;
1457 new_blk
->next
= NULL
;
1458 new_blk
->prev
= tail
;
1465 static void translate_resources( language_t lang
)
1469 for (res
= resource_top
; res
; res
= res
->next
)
1471 resource_t
*new = NULL
;
1474 if (!is_english( res
->lan
)) continue;
1479 new = dup_resource( res
, lang
);
1480 new->res
.acc
->events
= translate_accel( res
->res
.acc
, new->res
.acc
, &found
);
1483 new = dup_resource( res
, lang
);
1484 translate_dialog( res
->res
.dlg
, new->res
.dlg
, &found
);
1487 new = dup_resource( res
, lang
);
1488 new->res
.men
->items
= translate_items( res
->res
.men
->items
, &found
);
1491 new = dup_resource( res
, lang
);
1492 new->res
.stt
= translate_stringtable( res
->res
.stt
, lang
, &found
);
1495 new = dup_resource( res
, lang
);
1496 new->res
.ver
->blocks
= translate_versioninfo( res
->res
.ver
->blocks
, lang
, &found
);
1507 if (new_tail
) new_tail
->next
= new;
1509 new->prev
= new_tail
;
1515 void add_translations( const char *po_dir
)
1519 char *p
, *tok
, *name
;
1523 /* first check if we have English resources to translate */
1524 for (res
= resource_top
; res
; res
= res
->next
) if (is_english( res
->lan
)) break;
1527 if (!po_dir
) /* run through the translation process to remove msg contexts */
1529 translate_resources( MAKELANGID( LANG_ENGLISH
, SUBLANG_DEFAULT
));
1533 new_top
= new_tail
= NULL
;
1535 name
= strmake( "%s/LINGUAS", po_dir
);
1536 if (!(f
= fopen( name
, "r" )))
1542 while (fgets( buffer
, sizeof(buffer
), f
))
1544 if ((p
= strchr( buffer
, '#' ))) *p
= 0;
1545 for (tok
= strtok( buffer
, " \t\r\n" ); tok
; tok
= strtok( NULL
, " \t\r\n" ))
1547 for (i
= 0; i
< ARRAY_SIZE(languages
); i
++)
1548 if (!strcmp( tok
, languages
[i
].name
)) break;
1550 if (i
== ARRAY_SIZE(languages
))
1551 error( "unknown language '%s'\n", tok
);
1553 name
= strmake( "%s/%s.mo", po_dir
, tok
);
1554 load_mo_file( name
);
1555 translate_resources( MAKELANGID( languages
[i
].id
, languages
[i
].sub
));
1563 /* prepend the translated resources to the global list */
1566 new_tail
->next
= resource_top
;
1567 resource_top
->prev
= new_tail
;
1568 resource_top
= new_top
;