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
22 #include "wine/port.h"
30 #ifdef HAVE_LIBGETTEXTPO
31 #include <gettext-po.h>
42 #include "wine/list.h"
44 static resource_t
*new_top
, *new_tail
;
49 unsigned int revision
;
51 unsigned int msgid_off
;
52 unsigned int msgstr_off
;
53 /* ... rest of file data here */
56 static BOOL
is_english( const language_t
*lan
)
58 return lan
->id
== LANG_ENGLISH
&& lan
->sub
== SUBLANG_DEFAULT
;
61 static BOOL
is_rtl_language( const language_t
*lan
)
63 return lan
->id
== LANG_ARABIC
|| lan
->id
== LANG_HEBREW
|| lan
->id
== LANG_PERSIAN
;
66 static BOOL
uses_larger_font( const language_t
*lan
)
68 return lan
->id
== LANG_CHINESE
|| lan
->id
== LANG_JAPANESE
|| lan
->id
== LANG_KOREAN
;
71 static WORD
get_default_sublang( const language_t
*lan
)
73 if (lan
->sub
!= SUBLANG_NEUTRAL
)
79 return SUBLANG_SPANISH_MODERN
;
81 return SUBLANG_CHINESE_SIMPLIFIED
;
83 return SUBLANG_DEFAULT
;
87 static version_t
*get_dup_version( language_t
*lang
)
89 /* English "translations" take precedence over the original rc contents */
90 return new_version( is_english( lang
) ? 1 : -1 );
93 static name_id_t
*dup_name_id( name_id_t
*id
)
97 if (!id
|| id
->type
!= name_str
) return id
;
100 new->name
.s_name
= convert_string_unicode( id
->name
.s_name
, 1252 );
104 static char *convert_msgid_ascii( const string_t
*str
, int error_on_invalid_char
)
107 char *buffer
= xmalloc( str
->size
+ 1 );
109 for (i
= 0; i
< str
->size
; i
++)
111 WCHAR ch
= (str
->type
== str_unicode
? str
->str
.wstr
[i
] : (unsigned char)str
->str
.cstr
[i
]);
113 if (ch
>= 32 && ch
<= 127) continue;
114 if (ch
== '\t' || ch
== '\n') continue;
115 if (error_on_invalid_char
)
117 print_location( &str
->loc
);
118 error( "Invalid character %04x in source string\n", ch
);
127 static char *get_message_context( char **msgid
)
129 static const char magic
[] = "#msgctxt#";
132 if (strncmp( *msgid
, magic
, sizeof(magic
) - 1 )) return NULL
;
133 context
= *msgid
+ sizeof(magic
) - 1;
134 if (!(id
= strchr( context
, '#' ))) return NULL
;
140 static BOOL
control_has_title( const control_t
*ctrl
)
142 if (!ctrl
->title
) return FALSE
;
143 if (ctrl
->title
->type
!= name_str
) return FALSE
;
144 /* check for text static control */
145 if (ctrl
->ctlclass
&& ctrl
->ctlclass
->type
== name_ord
&& ctrl
->ctlclass
->name
.i_name
== CT_STATIC
)
147 switch (ctrl
->style
->or_mask
& SS_TYPEMASK
)
160 static resource_t
*dup_resource( resource_t
*res
, language_t
*lang
)
162 resource_t
*new = xmalloc( sizeof(*new) );
166 new->next
= new->prev
= NULL
;
167 new->name
= dup_name_id( res
->name
);
172 new->res
.acc
= xmalloc( sizeof(*(new)->res
.acc
) );
173 *new->res
.acc
= *res
->res
.acc
;
174 new->res
.acc
->lvc
.language
= lang
;
175 new->res
.acc
->lvc
.version
= get_dup_version( lang
);
178 new->res
.dlg
= xmalloc( sizeof(*(new)->res
.dlg
) );
179 *new->res
.dlg
= *res
->res
.dlg
;
180 new->res
.dlg
->lvc
.language
= lang
;
181 new->res
.dlg
->lvc
.version
= get_dup_version( lang
);
184 new->res
.men
= xmalloc( sizeof(*(new)->res
.men
) );
185 *new->res
.men
= *res
->res
.men
;
186 new->res
.men
->lvc
.language
= lang
;
187 new->res
.men
->lvc
.version
= get_dup_version( lang
);
190 new->res
.stt
= xmalloc( sizeof(*(new)->res
.stt
) );
191 *new->res
.stt
= *res
->res
.stt
;
192 new->res
.stt
->lvc
.language
= lang
;
193 new->res
.stt
->lvc
.version
= get_dup_version( lang
);
196 new->res
.ver
= xmalloc( sizeof(*(new)->res
.ver
) );
197 *new->res
.ver
= *res
->res
.ver
;
198 new->res
.ver
->lvc
.language
= lang
;
199 new->res
.ver
->lvc
.version
= get_dup_version( lang
);
209 unsigned int id
, sub
;
213 { LANG_AFRIKAANS
, SUBLANG_NEUTRAL
, "af" },
214 { LANG_AFRIKAANS
, SUBLANG_AFRIKAANS_SOUTH_AFRICA
, "af_ZA" },
215 { LANG_ALBANIAN
, SUBLANG_NEUTRAL
, "sq" },
216 { LANG_ALBANIAN
, SUBLANG_ALBANIAN_ALBANIA
, "sq_AL" },
217 { LANG_AMHARIC
, SUBLANG_NEUTRAL
, "am" },
218 { LANG_AMHARIC
, SUBLANG_AMHARIC_ETHIOPIA
, "am_ET" },
219 { LANG_ARABIC
, SUBLANG_NEUTRAL
, "ar" },
220 { LANG_ARABIC
, SUBLANG_ARABIC_SAUDI_ARABIA
, "ar_SA" },
221 { LANG_ARABIC
, SUBLANG_ARABIC_IRAQ
, "ar_IQ" },
222 { LANG_ARABIC
, SUBLANG_ARABIC_EGYPT
, "ar_EG" },
223 { LANG_ARABIC
, SUBLANG_ARABIC_LIBYA
, "ar_LY" },
224 { LANG_ARABIC
, SUBLANG_ARABIC_ALGERIA
, "ar_DZ" },
225 { LANG_ARABIC
, SUBLANG_ARABIC_MOROCCO
, "ar_MA" },
226 { LANG_ARABIC
, SUBLANG_ARABIC_TUNISIA
, "ar_TN" },
227 { LANG_ARABIC
, SUBLANG_ARABIC_OMAN
, "ar_OM" },
228 { LANG_ARABIC
, SUBLANG_ARABIC_YEMEN
, "ar_YE" },
229 { LANG_ARABIC
, SUBLANG_ARABIC_SYRIA
, "ar_SY" },
230 { LANG_ARABIC
, SUBLANG_ARABIC_JORDAN
, "ar_JO" },
231 { LANG_ARABIC
, SUBLANG_ARABIC_LEBANON
, "ar_LB" },
232 { LANG_ARABIC
, SUBLANG_ARABIC_KUWAIT
, "ar_KW" },
233 { LANG_ARABIC
, SUBLANG_ARABIC_UAE
, "ar_AE" },
234 { LANG_ARABIC
, SUBLANG_ARABIC_BAHRAIN
, "ar_BH" },
235 { LANG_ARABIC
, SUBLANG_ARABIC_QATAR
, "ar_QA" },
236 { LANG_ARMENIAN
, SUBLANG_NEUTRAL
, "hy" },
237 { LANG_ARMENIAN
, SUBLANG_ARMENIAN_ARMENIA
, "hy_AM" },
238 { LANG_ASSAMESE
, SUBLANG_NEUTRAL
, "as" },
239 { LANG_ASSAMESE
, SUBLANG_ASSAMESE_INDIA
, "as_IN" },
240 { LANG_ASTURIAN
, SUBLANG_NEUTRAL
, "ast" },
241 { LANG_ASTURIAN
, SUBLANG_DEFAULT
, "ast_ES" },
242 { LANG_AZERBAIJANI
, SUBLANG_NEUTRAL
, "az" },
243 { LANG_AZERBAIJANI
, SUBLANG_AZERBAIJANI_AZERBAIJAN_LATIN
,"az_AZ@latin" },
244 { LANG_AZERBAIJANI
, SUBLANG_AZERBAIJANI_AZERBAIJAN_CYRILLIC
, "az_AZ@cyrillic" },
245 { LANG_BASQUE
, SUBLANG_NEUTRAL
, "eu" },
246 { LANG_BASQUE
, SUBLANG_BASQUE_BASQUE
, "eu_ES" },
247 { LANG_BELARUSIAN
, SUBLANG_NEUTRAL
, "be" },
248 { LANG_BELARUSIAN
, SUBLANG_BELARUSIAN_BELARUS
, "be_BY" },
249 { LANG_BENGALI
, SUBLANG_NEUTRAL
, "bn" },
250 { LANG_BENGALI
, SUBLANG_BENGALI_INDIA
, "bn_IN" },
251 { LANG_BENGALI
, SUBLANG_BENGALI_BANGLADESH
, "bn_BD" },
252 { LANG_BRETON
, SUBLANG_NEUTRAL
, "br" },
253 { LANG_BRETON
, SUBLANG_BRETON_FRANCE
, "br_FR" },
254 { LANG_BULGARIAN
, SUBLANG_NEUTRAL
, "bg" },
255 { LANG_BULGARIAN
, SUBLANG_BULGARIAN_BULGARIA
, "bg_BG" },
256 { LANG_CATALAN
, SUBLANG_NEUTRAL
, "ca" },
257 { LANG_CATALAN
, SUBLANG_CATALAN_CATALAN
, "ca_ES" },
258 { LANG_CHINESE
, SUBLANG_NEUTRAL
, "zh" },
259 { LANG_CHINESE
, SUBLANG_CHINESE_TRADITIONAL
, "zh_TW" },
260 { LANG_CHINESE
, SUBLANG_CHINESE_SIMPLIFIED
, "zh_CN" },
261 { LANG_CHINESE
, SUBLANG_CHINESE_HONGKONG
, "zh_HK" },
262 { LANG_CHINESE
, SUBLANG_CHINESE_SINGAPORE
, "zh_SG" },
263 { LANG_CHINESE
, SUBLANG_CHINESE_MACAU
, "zh_MO" },
264 { LANG_CZECH
, SUBLANG_NEUTRAL
, "cs" },
265 { LANG_CZECH
, SUBLANG_CZECH_CZECH_REPUBLIC
, "cs_CZ" },
266 { LANG_DANISH
, SUBLANG_NEUTRAL
, "da" },
267 { LANG_DANISH
, SUBLANG_DANISH_DENMARK
, "da_DK" },
268 { LANG_DIVEHI
, SUBLANG_NEUTRAL
, "dv" },
269 { LANG_DIVEHI
, SUBLANG_DIVEHI_MALDIVES
, "dv_MV" },
270 { LANG_DUTCH
, SUBLANG_NEUTRAL
, "nl" },
271 { LANG_DUTCH
, SUBLANG_DUTCH
, "nl_NL" },
272 { LANG_DUTCH
, SUBLANG_DUTCH_BELGIAN
, "nl_BE" },
273 { LANG_DUTCH
, SUBLANG_DUTCH_SURINAM
, "nl_SR" },
274 { LANG_ENGLISH
, SUBLANG_NEUTRAL
, "en" },
275 { LANG_ENGLISH
, SUBLANG_ENGLISH_US
, "en_US" },
276 { LANG_ENGLISH
, SUBLANG_ENGLISH_UK
, "en_GB" },
277 { LANG_ENGLISH
, SUBLANG_ENGLISH_AUS
, "en_AU" },
278 { LANG_ENGLISH
, SUBLANG_ENGLISH_CAN
, "en_CA" },
279 { LANG_ENGLISH
, SUBLANG_ENGLISH_NZ
, "en_NZ" },
280 { LANG_ENGLISH
, SUBLANG_ENGLISH_EIRE
, "en_IE" },
281 { LANG_ENGLISH
, SUBLANG_ENGLISH_SOUTH_AFRICA
, "en_ZA" },
282 { LANG_ENGLISH
, SUBLANG_ENGLISH_JAMAICA
, "en_JM" },
283 { LANG_ENGLISH
, SUBLANG_ENGLISH_CARIBBEAN
, "en_CB" },
284 { LANG_ENGLISH
, SUBLANG_ENGLISH_BELIZE
, "en_BZ" },
285 { LANG_ENGLISH
, SUBLANG_ENGLISH_TRINIDAD
, "en_TT" },
286 { LANG_ENGLISH
, SUBLANG_ENGLISH_ZIMBABWE
, "en_ZW" },
287 { LANG_ENGLISH
, SUBLANG_ENGLISH_PHILIPPINES
, "en_PH" },
288 { LANG_ENGLISH
, SUBLANG_ENGLISH_INDIA
, "en_IN" },
289 { LANG_ENGLISH
, SUBLANG_ENGLISH_MALAYSIA
, "en_MY" },
290 { LANG_ENGLISH
, SUBLANG_ENGLISH_SINGAPORE
, "en_SG" },
291 { LANG_ESTONIAN
, SUBLANG_NEUTRAL
, "et" },
292 { LANG_ESTONIAN
, SUBLANG_ESTONIAN_ESTONIA
, "et_EE" },
293 { LANG_FAEROESE
, SUBLANG_NEUTRAL
, "fo" },
294 { LANG_FAEROESE
, SUBLANG_FAEROESE_FAROE_ISLANDS
, "fo_FO" },
295 { LANG_FILIPINO
, SUBLANG_NEUTRAL
, "fil" },
296 { LANG_FILIPINO
, SUBLANG_FILIPINO_PHILIPPINES
, "fil_PH" },
297 { LANG_FINNISH
, SUBLANG_NEUTRAL
, "fi" },
298 { LANG_FINNISH
, SUBLANG_FINNISH_FINLAND
, "fi_FI" },
299 { LANG_FRENCH
, SUBLANG_NEUTRAL
, "fr" },
300 { LANG_FRENCH
, SUBLANG_FRENCH
, "fr_FR" },
301 { LANG_FRENCH
, SUBLANG_FRENCH_BELGIAN
, "fr_BE" },
302 { LANG_FRENCH
, SUBLANG_FRENCH_CANADIAN
, "fr_CA" },
303 { LANG_FRENCH
, SUBLANG_FRENCH_SWISS
, "fr_CH" },
304 { LANG_FRENCH
, SUBLANG_FRENCH_LUXEMBOURG
, "fr_LU" },
305 { LANG_FRENCH
, SUBLANG_FRENCH_MONACO
, "fr_MC" },
306 { LANG_GALICIAN
, SUBLANG_NEUTRAL
, "gl" },
307 { LANG_GALICIAN
, SUBLANG_GALICIAN_GALICIAN
, "gl_ES" },
308 { LANG_GEORGIAN
, SUBLANG_NEUTRAL
, "ka" },
309 { LANG_GEORGIAN
, SUBLANG_GEORGIAN_GEORGIA
, "ka_GE" },
310 { LANG_GERMAN
, SUBLANG_NEUTRAL
, "de" },
311 { LANG_GERMAN
, SUBLANG_GERMAN
, "de_DE" },
312 { LANG_GERMAN
, SUBLANG_GERMAN_SWISS
, "de_CH" },
313 { LANG_GERMAN
, SUBLANG_GERMAN_AUSTRIAN
, "de_AT" },
314 { LANG_GERMAN
, SUBLANG_GERMAN_LUXEMBOURG
, "de_LU" },
315 { LANG_GERMAN
, SUBLANG_GERMAN_LIECHTENSTEIN
, "de_LI" },
316 { LANG_GREEK
, SUBLANG_NEUTRAL
, "el" },
317 { LANG_GREEK
, SUBLANG_GREEK_GREECE
, "el_GR" },
318 { LANG_GUJARATI
, SUBLANG_NEUTRAL
, "gu" },
319 { LANG_GUJARATI
, SUBLANG_GUJARATI_INDIA
, "gu_IN" },
320 { LANG_HAUSA
, SUBLANG_NEUTRAL
, "ha" },
321 { LANG_HAUSA
, SUBLANG_HAUSA_NIGERIA
, "ha_NG" },
322 { LANG_HAWAIIAN
, SUBLANG_NEUTRAL
, "haw" },
323 { LANG_HAWAIIAN
, SUBLANG_HAWAIIAN_US
, "haw_US" },
324 { LANG_HEBREW
, SUBLANG_NEUTRAL
, "he" },
325 { LANG_HEBREW
, SUBLANG_HEBREW_ISRAEL
, "he_IL" },
326 { LANG_HINDI
, SUBLANG_NEUTRAL
, "hi" },
327 { LANG_HINDI
, SUBLANG_HINDI_INDIA
, "hi_IN" },
328 { LANG_HUNGARIAN
, SUBLANG_NEUTRAL
, "hu" },
329 { LANG_HUNGARIAN
, SUBLANG_HUNGARIAN_HUNGARY
, "hu_HU" },
330 { LANG_ICELANDIC
, SUBLANG_NEUTRAL
, "is" },
331 { LANG_ICELANDIC
, SUBLANG_ICELANDIC_ICELAND
, "is_IS" },
332 { LANG_IGBO
, SUBLANG_NEUTRAL
, "ig" },
333 { LANG_IGBO
, SUBLANG_IGBO_NIGERIA
, "ig_NG" },
334 { LANG_INDONESIAN
, SUBLANG_NEUTRAL
, "id" },
335 { LANG_INDONESIAN
, SUBLANG_INDONESIAN_INDONESIA
, "id_ID" },
336 { LANG_INUKTITUT
, SUBLANG_NEUTRAL
, "iu" },
337 { LANG_INUKTITUT
, SUBLANG_INUKTITUT_CANADA
, "iu_CA" },
338 { LANG_IRISH
, SUBLANG_NEUTRAL
, "ga" },
339 { LANG_IRISH
, SUBLANG_IRISH_IRELAND
, "ga_IE" },
340 { LANG_ITALIAN
, SUBLANG_NEUTRAL
, "it" },
341 { LANG_ITALIAN
, SUBLANG_ITALIAN
, "it_IT" },
342 { LANG_ITALIAN
, SUBLANG_ITALIAN_SWISS
, "it_CH" },
343 { LANG_JAPANESE
, SUBLANG_NEUTRAL
, "ja" },
344 { LANG_JAPANESE
, SUBLANG_JAPANESE_JAPAN
, "ja_JP" },
345 { LANG_KANNADA
, SUBLANG_NEUTRAL
, "kn" },
346 { LANG_KANNADA
, SUBLANG_KANNADA_INDIA
, "kn_IN" },
347 { LANG_KAZAK
, SUBLANG_NEUTRAL
, "kk" },
348 { LANG_KAZAK
, SUBLANG_KAZAK_KAZAKHSTAN
, "kk_KZ" },
349 { LANG_KHMER
, SUBLANG_NEUTRAL
, "km" },
350 { LANG_KHMER
, SUBLANG_KHMER_CAMBODIA
, "km_KH" },
351 { LANG_KINYARWANDA
, SUBLANG_NEUTRAL
, "rw" },
352 { LANG_KINYARWANDA
, SUBLANG_KINYARWANDA_RWANDA
, "rw_RW" },
353 { LANG_KONKANI
, SUBLANG_NEUTRAL
, "kok" },
354 { LANG_KONKANI
, SUBLANG_KONKANI_INDIA
, "kok_IN" },
355 { LANG_KOREAN
, SUBLANG_NEUTRAL
, "ko" },
356 { LANG_KOREAN
, SUBLANG_KOREAN
, "ko_KR" },
357 { LANG_KYRGYZ
, SUBLANG_NEUTRAL
, "ky" },
358 { LANG_KYRGYZ
, SUBLANG_KYRGYZ_KYRGYZSTAN
, "ky_KG" },
359 { LANG_LAO
, SUBLANG_NEUTRAL
, "lo" },
360 { LANG_LAO
, SUBLANG_LAO_LAO
, "lo_LA" },
361 { LANG_LATVIAN
, SUBLANG_NEUTRAL
, "lv" },
362 { LANG_LATVIAN
, SUBLANG_LATVIAN_LATVIA
, "lv_LV" },
363 { LANG_LITHUANIAN
, SUBLANG_NEUTRAL
, "lt" },
364 { LANG_LITHUANIAN
, SUBLANG_LITHUANIAN
, "lt_LT" },
365 { LANG_MACEDONIAN
, SUBLANG_NEUTRAL
, "mk" },
366 { LANG_MACEDONIAN
, SUBLANG_MACEDONIAN_MACEDONIA
, "mk_MK" },
367 { LANG_MALAY
, SUBLANG_NEUTRAL
, "ms" },
368 { LANG_MALAY
, SUBLANG_MALAY_MALAYSIA
, "ms_MY" },
369 { LANG_MALAY
, SUBLANG_MALAY_BRUNEI_DARUSSALAM
, "ms_BN" },
370 { LANG_MALAYALAM
, SUBLANG_NEUTRAL
, "ml" },
371 { LANG_MALAYALAM
, SUBLANG_MALAYALAM_INDIA
, "ml_IN" },
372 { LANG_MALTESE
, SUBLANG_NEUTRAL
, "mt" },
373 { LANG_MALTESE
, SUBLANG_MALTESE_MALTA
, "mt_MT" },
374 { LANG_MARATHI
, SUBLANG_NEUTRAL
, "mr" },
375 { LANG_MARATHI
, SUBLANG_MARATHI_INDIA
, "mr_IN" },
376 { LANG_MONGOLIAN
, SUBLANG_NEUTRAL
, "mn" },
377 { LANG_MONGOLIAN
, SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA
, "mn_MN" },
378 { LANG_MONGOLIAN
, SUBLANG_MONGOLIAN_PRC
, "mn_CN" },
379 { LANG_NEPALI
, SUBLANG_NEUTRAL
, "ne" },
380 { LANG_NEPALI
, SUBLANG_NEPALI_NEPAL
, "ne_NP" },
381 { LANG_NEPALI
, SUBLANG_NEPALI_INDIA
, "ne_IN" },
382 { LANG_NORWEGIAN
, SUBLANG_NORWEGIAN_BOKMAL
, "nb_NO" },
383 { LANG_NORWEGIAN
, SUBLANG_NORWEGIAN_NYNORSK
, "nn_NO" },
384 { LANG_ODIA
, SUBLANG_NEUTRAL
, "or" },
385 { LANG_ODIA
, SUBLANG_ODIA_INDIA
, "or_IN" },
386 { LANG_PASHTO
, SUBLANG_NEUTRAL
, "ps" },
387 { LANG_PASHTO
, SUBLANG_PASHTO_AFGHANISTAN
, "ps_AF" },
388 { LANG_PERSIAN
, SUBLANG_NEUTRAL
, "fa" },
389 { LANG_PERSIAN
, SUBLANG_PERSIAN_IRAN
, "fa_IR" },
390 { LANG_POLISH
, SUBLANG_NEUTRAL
, "pl" },
391 { LANG_POLISH
, SUBLANG_POLISH_POLAND
, "pl_PL" },
392 { LANG_PORTUGUESE
, SUBLANG_NEUTRAL
, "pt" },
393 { LANG_PORTUGUESE
, SUBLANG_PORTUGUESE_BRAZILIAN
, "pt_BR" },
394 { LANG_PORTUGUESE
, SUBLANG_PORTUGUESE_PORTUGAL
, "pt_PT" },
395 { LANG_PUNJABI
, SUBLANG_NEUTRAL
, "pa" },
396 { LANG_PUNJABI
, SUBLANG_PUNJABI_INDIA
, "pa_IN" },
397 { LANG_PUNJABI
, SUBLANG_PUNJABI_PAKISTAN
, "pa_PK" },
398 { LANG_ROMANIAN
, SUBLANG_NEUTRAL
, "ro" },
399 { LANG_ROMANIAN
, SUBLANG_ROMANIAN_ROMANIA
, "ro_RO" },
400 { LANG_ROMANSH
, SUBLANG_NEUTRAL
, "rm" },
401 { LANG_ROMANSH
, SUBLANG_ROMANSH_SWITZERLAND
, "rm_CH" },
402 { LANG_RUSSIAN
, SUBLANG_NEUTRAL
, "ru" },
403 { LANG_RUSSIAN
, SUBLANG_RUSSIAN_RUSSIA
, "ru_RU" },
404 { LANG_SAMI
, SUBLANG_NEUTRAL
, "se" },
405 { LANG_SAMI
, SUBLANG_SAMI_NORTHERN_NORWAY
, "se_NO" },
406 { LANG_SAMI
, SUBLANG_SAMI_NORTHERN_SWEDEN
, "se_SE" },
407 { LANG_SAMI
, SUBLANG_SAMI_NORTHERN_FINLAND
, "se_FI" },
408 { LANG_SANSKRIT
, SUBLANG_NEUTRAL
, "sa" },
409 { LANG_SANSKRIT
, SUBLANG_SANSKRIT_INDIA
, "sa_IN" },
410 { LANG_SCOTTISH_GAELIC
,SUBLANG_NEUTRAL
, "gd" },
411 { LANG_SCOTTISH_GAELIC
,SUBLANG_SCOTTISH_GAELIC
, "gd_GB" },
412 /* LANG_SERBIAN/LANG_CROATIAN/LANG_BOSNIAN are the same */
413 { LANG_SERBIAN
, SUBLANG_NEUTRAL
, "hr" },
414 { LANG_SERBIAN
, SUBLANG_SERBIAN_CROATIA
, "hr_HR" },
415 { LANG_SERBIAN
, SUBLANG_SERBIAN_LATIN
, "sr_RS@latin" },
416 { LANG_SERBIAN
, SUBLANG_SERBIAN_CYRILLIC
, "sr_RS@cyrillic" },
417 { LANG_SERBIAN
, SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN
, "hr_BA@latin" },
418 { LANG_SERBIAN
, SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN
, "bs_BA@latin" },
419 { LANG_SERBIAN
, SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_LATIN
, "sr_BA@latin" },
420 { LANG_SERBIAN
, SUBLANG_SERBIAN_BOSNIA_HERZEGOVINA_CYRILLIC
, "sr_BA@cyrillic" },
421 { LANG_SERBIAN
, SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC
, "bs_BA@cyrillic" },
422 { LANG_SERBIAN
, SUBLANG_SERBIAN_SERBIA_LATIN
, "sr_RS@latin" },
423 { LANG_SERBIAN
, SUBLANG_SERBIAN_SERBIA_CYRILLIC
, "sr_RS@cyrillic" },
424 { LANG_SERBIAN
, SUBLANG_SERBIAN_MONTENEGRO_LATIN
, "sr_ME@latin" },
425 { LANG_SERBIAN
, SUBLANG_SERBIAN_MONTENEGRO_CYRILLIC
, "sr_ME@cyrillic" },
426 { LANG_SINHALESE
, SUBLANG_NEUTRAL
, "si" },
427 { LANG_SINHALESE
, SUBLANG_SINHALESE_SRI_LANKA
, "si_LK" },
428 { LANG_SLOVAK
, SUBLANG_NEUTRAL
, "sk" },
429 { LANG_SLOVAK
, SUBLANG_SLOVAK_SLOVAKIA
, "sk_SK" },
430 { LANG_SLOVENIAN
, SUBLANG_NEUTRAL
, "sl" },
431 { LANG_SLOVENIAN
, SUBLANG_SLOVENIAN_SLOVENIA
, "sl_SI" },
432 { LANG_SOTHO
, SUBLANG_NEUTRAL
, "nso" },
433 { LANG_SOTHO
, SUBLANG_SOTHO_NORTHERN_SOUTH_AFRICA
, "nso_ZA" },
434 { LANG_SPANISH
, SUBLANG_NEUTRAL
, "es" },
435 { LANG_SPANISH
, SUBLANG_SPANISH
, "es_ES" },
436 { LANG_SPANISH
, SUBLANG_SPANISH_MEXICAN
, "es_MX" },
437 { LANG_SPANISH
, SUBLANG_SPANISH_MODERN
, "es_ES_modern" },
438 { LANG_SPANISH
, SUBLANG_SPANISH_GUATEMALA
, "es_GT" },
439 { LANG_SPANISH
, SUBLANG_SPANISH_COSTA_RICA
, "es_CR" },
440 { LANG_SPANISH
, SUBLANG_SPANISH_PANAMA
, "es_PA" },
441 { LANG_SPANISH
, SUBLANG_SPANISH_DOMINICAN_REPUBLIC
, "es_DO" },
442 { LANG_SPANISH
, SUBLANG_SPANISH_VENEZUELA
, "es_VE" },
443 { LANG_SPANISH
, SUBLANG_SPANISH_COLOMBIA
, "es_CO" },
444 { LANG_SPANISH
, SUBLANG_SPANISH_PERU
, "es_PE" },
445 { LANG_SPANISH
, SUBLANG_SPANISH_ARGENTINA
, "es_AR" },
446 { LANG_SPANISH
, SUBLANG_SPANISH_ECUADOR
, "es_EC" },
447 { LANG_SPANISH
, SUBLANG_SPANISH_CHILE
, "es_CL" },
448 { LANG_SPANISH
, SUBLANG_SPANISH_URUGUAY
, "es_UY" },
449 { LANG_SPANISH
, SUBLANG_SPANISH_PARAGUAY
, "es_PY" },
450 { LANG_SPANISH
, SUBLANG_SPANISH_BOLIVIA
, "es_BO" },
451 { LANG_SPANISH
, SUBLANG_SPANISH_EL_SALVADOR
, "es_SV" },
452 { LANG_SPANISH
, SUBLANG_SPANISH_HONDURAS
, "es_HN" },
453 { LANG_SPANISH
, SUBLANG_SPANISH_NICARAGUA
, "es_NI" },
454 { LANG_SPANISH
, SUBLANG_SPANISH_PUERTO_RICO
, "es_PR" },
455 { LANG_SPANISH
, SUBLANG_SPANISH_US
, "es_US" },
456 { LANG_SWAHILI
, SUBLANG_NEUTRAL
, "sw" },
457 { LANG_SWAHILI
, SUBLANG_SWAHILI_KENYA
, "sw_KE" },
458 { LANG_SWEDISH
, SUBLANG_NEUTRAL
, "sv" },
459 { LANG_SWEDISH
, SUBLANG_SWEDISH_SWEDEN
, "sv_SE" },
460 { LANG_SWEDISH
, SUBLANG_SWEDISH_FINLAND
, "sv_FI" },
461 { LANG_SYRIAC
, SUBLANG_NEUTRAL
, "syr" },
462 { LANG_SYRIAC
, SUBLANG_SYRIAC_SYRIA
, "syr_SY" },
463 { LANG_TAJIK
, SUBLANG_NEUTRAL
, "tg" },
464 { LANG_TAJIK
, SUBLANG_TAJIK_TAJIKISTAN
, "tg_TJ" },
465 { LANG_TAMIL
, SUBLANG_NEUTRAL
, "ta" },
466 { LANG_TAMIL
, SUBLANG_TAMIL_INDIA
, "ta_IN" },
467 { LANG_TATAR
, SUBLANG_NEUTRAL
, "tt" },
468 { LANG_TATAR
, SUBLANG_TATAR_RUSSIA
, "tt_TA" },
469 { LANG_TELUGU
, SUBLANG_NEUTRAL
, "te" },
470 { LANG_TELUGU
, SUBLANG_TELUGU_INDIA
, "te_IN" },
471 { LANG_THAI
, SUBLANG_NEUTRAL
, "th" },
472 { LANG_THAI
, SUBLANG_THAI_THAILAND
, "th_TH" },
473 { LANG_TIGRINYA
, SUBLANG_NEUTRAL
, "ti" },
474 { LANG_TIGRINYA
, SUBLANG_TIGRINYA_ETHIOPIA
, "ti_ET" },
475 { LANG_TIGRINYA
, SUBLANG_TIGRINYA_ERITREA
, "ti_ER" },
476 { LANG_TSWANA
, SUBLANG_NEUTRAL
, "tn" },
477 { LANG_TSWANA
, SUBLANG_TSWANA_SOUTH_AFRICA
, "tn_ZA" },
478 { LANG_TURKISH
, SUBLANG_NEUTRAL
, "tr" },
479 { LANG_TURKISH
, SUBLANG_TURKISH_TURKEY
, "tr_TR" },
480 { LANG_UIGHUR
, SUBLANG_NEUTRAL
, "ug" },
481 { LANG_UIGHUR
, SUBLANG_UIGHUR_PRC
, "ug_CN" },
482 { LANG_UKRAINIAN
, SUBLANG_NEUTRAL
, "uk" },
483 { LANG_UKRAINIAN
, SUBLANG_UKRAINIAN_UKRAINE
, "uk_UA" },
484 { LANG_URDU
, SUBLANG_NEUTRAL
, "ur" },
485 { LANG_URDU
, SUBLANG_URDU_PAKISTAN
, "ur_PK" },
486 { LANG_URDU
, SUBLANG_URDU_INDIA
, "ur_IN" },
487 { LANG_UZBEK
, SUBLANG_NEUTRAL
, "uz" },
488 { LANG_UZBEK
, SUBLANG_UZBEK_LATIN
, "uz_UZ@latin" },
489 { LANG_UZBEK
, SUBLANG_UZBEK_CYRILLIC
, "uz_UZ@cyrillic" },
490 { LANG_VIETNAMESE
, SUBLANG_NEUTRAL
, "vi" },
491 { LANG_VIETNAMESE
, SUBLANG_VIETNAMESE_VIETNAM
, "vi_VN" },
492 { LANG_WELSH
, SUBLANG_NEUTRAL
, "cy" },
493 { LANG_WELSH
, SUBLANG_WELSH_UNITED_KINGDOM
, "cy_GB" },
494 { LANG_WOLOF
, SUBLANG_NEUTRAL
, "wo" },
495 { LANG_WOLOF
, SUBLANG_WOLOF_SENEGAL
, "wo_SN" },
496 { LANG_XHOSA
, SUBLANG_NEUTRAL
, "xh" },
497 { LANG_XHOSA
, SUBLANG_XHOSA_SOUTH_AFRICA
, "xh_ZA" },
498 { LANG_YORUBA
, SUBLANG_NEUTRAL
, "yo" },
499 { LANG_YORUBA
, SUBLANG_YORUBA_NIGERIA
, "yo_NG" },
500 { LANG_ZULU
, SUBLANG_NEUTRAL
, "zu" },
501 { LANG_ZULU
, SUBLANG_ZULU_SOUTH_AFRICA
, "zu_ZA" },
503 #ifdef LANG_ESPERANTO
504 { LANG_ESPERANTO
, SUBLANG_DEFAULT
, "eo" },
507 { LANG_WALON
, SUBLANG_NEUTRAL
, "wa" },
508 { LANG_WALON
, SUBLANG_DEFAULT
, "wa_BE" },
511 { LANG_CORNISH
, SUBLANG_NEUTRAL
, "kw" },
512 { LANG_CORNISH
, SUBLANG_DEFAULT
, "kw_GB" },
514 #ifdef LANG_MANX_GAELIC
515 { LANG_MANX_GAELIC
, SUBLANG_MANX_GAELIC
, "gv_GB" },
519 #ifndef HAVE_LIBGETTEXTPO
521 void write_pot_file( const char *outname
)
523 error( "PO files not supported in this wrc build\n" );
526 void write_po_files( const char *outname
)
528 error( "PO files not supported in this wrc build\n" );
531 #else /* HAVE_LIBGETTEXTPO */
533 static void po_xerror( int severity
, po_message_t message
,
534 const char *filename
, size_t lineno
, size_t column
,
535 int multiline_p
, const char *message_text
)
537 fprintf( stderr
, "%s:%u:%u: %s\n",
538 filename
, (unsigned int)lineno
, (unsigned int)column
, message_text
);
539 if (severity
) exit(1);
542 static void po_xerror2( int severity
, po_message_t message1
,
543 const char *filename1
, size_t lineno1
, size_t column1
,
544 int multiline_p1
, const char *message_text1
,
545 po_message_t message2
,
546 const char *filename2
, size_t lineno2
, size_t column2
,
547 int multiline_p2
, const char *message_text2
)
549 fprintf( stderr
, "%s:%u:%u: %s\n",
550 filename1
, (unsigned int)lineno1
, (unsigned int)column1
, message_text1
);
551 fprintf( stderr
, "%s:%u:%u: %s\n",
552 filename2
, (unsigned int)lineno2
, (unsigned int)column2
, message_text2
);
553 if (severity
) exit(1);
556 static const struct po_xerror_handler po_xerror_handler
= { po_xerror
, po_xerror2
};
558 static po_message_t
find_message( po_file_t po
, const char *msgid
, const char *msgctxt
,
559 po_message_iterator_t
*iterator
)
564 *iterator
= po_message_iterator( po
, NULL
);
565 while ((msg
= po_next_message( *iterator
)))
567 if (strcmp( po_message_msgid( msg
), msgid
)) continue;
569 if (!(context
= po_message_msgctxt( msg
))) continue;
570 if (!strcmp( context
, msgctxt
)) break;
575 static void add_po_string( po_file_t po
, const string_t
*msgid
, const string_t
*msgstr
,
576 const language_t
*lang
)
578 static const char dnt
[] = "do not translate";
580 po_message_iterator_t iterator
;
582 char *id
, *id_buffer
, *context
, *str
= NULL
, *str_buffer
= NULL
;
584 if (!msgid
->size
) return;
586 id_buffer
= id
= convert_msgid_ascii( msgid
, 1 );
587 context
= get_message_context( &id
);
588 if (context
&& strcmp(context
, dnt
) == 0)
590 /* This string should not be translated */
597 if (lang
) codepage
= get_language_codepage( lang
->id
, lang
->sub
);
598 else codepage
= get_language_codepage( 0, 0 );
599 assert( codepage
!= -1 );
600 str
= str_buffer
= convert_string_utf8( msgstr
, codepage
);
601 if (is_english( lang
)) get_message_context( &str
);
603 if (!(msg
= find_message( po
, id
, context
, &iterator
)))
605 msg
= po_message_create();
606 po_message_set_msgid( msg
, id
);
607 po_message_set_msgstr( msg
, str
? str
: "" );
608 if (context
) po_message_set_msgctxt( msg
, context
);
609 po_message_insert( iterator
, msg
);
611 if (msgid
->loc
.file
) po_message_add_filepos( msg
, msgid
->loc
.file
, msgid
->loc
.line
);
612 po_message_iterator_free( iterator
);
624 static struct list po_file_langs
= LIST_INIT( po_file_langs
);
626 static po_file_t
create_po_file(void)
630 po_message_iterator_t iterator
;
632 po
= po_file_create();
633 iterator
= po_message_iterator( po
, NULL
);
634 msg
= po_message_create();
635 po_message_set_msgid( msg
, "" );
636 po_message_set_msgstr( msg
,
637 "Project-Id-Version: Wine\n"
638 "Report-Msgid-Bugs-To: https://bugs.winehq.org\n"
639 "POT-Creation-Date: N/A\n"
640 "PO-Revision-Date: N/A\n"
641 "Last-Translator: Automatically generated\n"
642 "Language-Team: none\n"
643 "MIME-Version: 1.0\n"
644 "Content-Type: text/plain; charset=UTF-8\n"
645 "Content-Transfer-Encoding: 8bit\n" );
646 po_message_insert( iterator
, msg
);
647 po_message_iterator_free( iterator
);
651 static po_file_t
get_po_file( const language_t
*lang
)
653 struct po_file_lang
*po_file
;
655 LIST_FOR_EACH_ENTRY( po_file
, &po_file_langs
, struct po_file_lang
, entry
)
656 if (po_file
->lang
.id
== lang
->id
&& po_file
->lang
.sub
== lang
->sub
) return po_file
->po
;
658 /* create a new one */
659 po_file
= xmalloc( sizeof(*po_file
) );
660 po_file
->lang
= *lang
;
661 po_file
->po
= create_po_file();
662 list_add_tail( &po_file_langs
, &po_file
->entry
);
666 static const char *get_language_name( const language_t
*lang
)
668 static char name
[20];
671 for (i
= 0; i
< ARRAY_SIZE(languages
); i
++)
672 if (languages
[i
].id
== lang
->id
&& languages
[i
].sub
== lang
->sub
)
673 return languages
[i
].name
;
675 sprintf( name
, "%02x-%02x", lang
->id
, lang
->sub
);
679 static char *get_po_file_name( const language_t
*lang
)
681 return strmake( "%s.po", get_language_name( lang
) );
684 static unsigned int flush_po_files( const char *output_name
)
686 struct po_file_lang
*po_file
, *next
;
687 unsigned int count
= 0;
689 LIST_FOR_EACH_ENTRY_SAFE( po_file
, next
, &po_file_langs
, struct po_file_lang
, entry
)
691 char *name
= get_po_file_name( &po_file
->lang
);
694 const char *p
= strrchr( output_name
, '/' );
696 else p
= output_name
;
697 if (!strcmp( p
, name
))
699 po_file_write( po_file
->po
, name
, &po_xerror_handler
);
703 else /* no specified output name, output a file for every language found */
705 po_file_write( po_file
->po
, name
, &po_xerror_handler
);
707 fprintf( stderr
, "created %s\n", name
);
709 po_file_free( po_file
->po
);
710 list_remove( &po_file
->entry
);
717 static void add_pot_stringtable( po_file_t po
, const resource_t
*res
)
719 const stringtable_t
*stt
= res
->res
.stt
;
724 for (i
= 0; i
< stt
->nentries
; i
++)
725 if (stt
->entries
[i
].str
) add_po_string( po
, stt
->entries
[i
].str
, NULL
, NULL
);
730 static void add_po_stringtable( const resource_t
*english
, const resource_t
*res
)
732 const stringtable_t
*english_stt
= english
->res
.stt
;
733 const stringtable_t
*stt
= res
->res
.stt
;
734 po_file_t po
= get_po_file( stt
->lvc
.language
);
737 while (english_stt
&& stt
)
739 for (i
= 0; i
< stt
->nentries
; i
++)
740 if (english_stt
->entries
[i
].str
&& stt
->entries
[i
].str
)
741 add_po_string( po
, english_stt
->entries
[i
].str
, stt
->entries
[i
].str
, stt
->lvc
.language
);
743 english_stt
= english_stt
->next
;
747 static void add_pot_dialog_controls( po_file_t po
, const control_t
*ctrl
)
751 if (control_has_title( ctrl
)) add_po_string( po
, ctrl
->title
->name
.s_name
, NULL
, NULL
);
756 static void add_pot_dialog( po_file_t po
, const resource_t
*res
)
758 const dialog_t
*dlg
= res
->res
.dlg
;
760 if (dlg
->title
) add_po_string( po
, dlg
->title
, NULL
, NULL
);
761 add_pot_dialog_controls( po
, dlg
->controls
);
764 static void compare_dialogs( const dialog_t
*english_dlg
, const dialog_t
*dlg
)
766 const control_t
*english_ctrl
, *ctrl
;
767 unsigned int style
= 0, exstyle
= 0, english_style
= 0, english_exstyle
= 0;
769 char *title
= english_dlg
->title
? convert_msgid_ascii( english_dlg
->title
, 0 ) : xstrdup("??");
771 if (english_dlg
->width
!= dlg
->width
|| english_dlg
->height
!= dlg
->height
)
772 warning( "%s: dialog %s doesn't have the same size (%d,%d vs %d,%d)\n",
773 get_language_name( dlg
->lvc
.language
), title
, dlg
->width
, dlg
->height
,
774 english_dlg
->width
, english_dlg
->height
);
776 if (dlg
->gotstyle
) style
= dlg
->style
->or_mask
;
777 if (dlg
->gotexstyle
) exstyle
= dlg
->exstyle
->or_mask
;
778 if (english_dlg
->gotstyle
) english_style
= english_dlg
->style
->or_mask
;
779 if (english_dlg
->gotexstyle
) english_exstyle
= english_dlg
->exstyle
->or_mask
;
780 if (is_rtl_language( dlg
->lvc
.language
)) english_exstyle
|= WS_EX_LAYOUTRTL
;
782 if (english_style
!= style
)
783 warning( "%s: dialog %s doesn't have the same style (%08x vs %08x)\n",
784 get_language_name( dlg
->lvc
.language
), title
, style
, english_style
);
785 if (english_exstyle
!= exstyle
)
786 warning( "%s: dialog %s doesn't have the same exstyle (%08x vs %08x)\n",
787 get_language_name( dlg
->lvc
.language
), title
, exstyle
, english_exstyle
);
789 if (english_dlg
->font
|| dlg
->font
)
791 int size
= 0, english_size
= 0;
792 char *font
= NULL
, *english_font
= NULL
;
794 if (english_dlg
->font
)
796 english_font
= convert_msgid_ascii( english_dlg
->font
->name
, 0 );
797 english_size
= english_dlg
->font
->size
;
801 font
= convert_msgid_ascii( dlg
->font
->name
, 0 );
802 size
= dlg
->font
->size
;
804 if (uses_larger_font( dlg
->lvc
.language
)) english_size
++;
806 if (!english_font
|| !font
|| strcasecmp( english_font
, font
) || english_size
!= size
)
807 warning( "%s: dialog %s doesn't have the same font (%s %u vs %s %u)\n",
808 get_language_name(dlg
->lvc
.language
), title
,
809 english_font
? english_font
: "default", english_size
,
810 font
? font
: "default", size
);
812 free( english_font
);
814 english_ctrl
= english_dlg
->controls
;
815 ctrl
= dlg
->controls
;
816 for ( ; english_ctrl
&& ctrl
; ctrl
= ctrl
->next
, english_ctrl
= english_ctrl
->next
)
818 if (control_has_title( english_ctrl
))
819 name
= convert_msgid_ascii( english_ctrl
->title
->name
.s_name
, 0 );
821 name
= strmake( "%d", ctrl
->id
);
823 if (english_ctrl
->width
!= ctrl
->width
|| english_ctrl
->height
!= ctrl
->height
)
824 warning( "%s: dialog %s control %s doesn't have the same size (%d,%d vs %d,%d)\n",
825 get_language_name( dlg
->lvc
.language
), title
, name
,
826 ctrl
->width
, ctrl
->height
, english_ctrl
->width
, english_ctrl
->height
);
827 if (english_ctrl
->x
!= ctrl
->x
|| english_ctrl
->y
!= ctrl
->y
)
828 warning( "%s: dialog %s control %s doesn't have the same position (%d,%d vs %d,%d)\n",
829 get_language_name( dlg
->lvc
.language
), title
, name
,
830 ctrl
->x
, ctrl
->y
, english_ctrl
->x
, english_ctrl
->y
);
836 static void add_po_dialog_controls( po_file_t po
, const control_t
*english_ctrl
,
837 const control_t
*ctrl
, const language_t
*lang
)
839 while (english_ctrl
&& ctrl
)
841 if (control_has_title( english_ctrl
) && control_has_title( ctrl
))
842 add_po_string( po
, english_ctrl
->title
->name
.s_name
, ctrl
->title
->name
.s_name
, lang
);
845 english_ctrl
= english_ctrl
->next
;
849 static void add_po_dialog( const resource_t
*english
, const resource_t
*res
)
851 const dialog_t
*english_dlg
= english
->res
.dlg
;
852 const dialog_t
*dlg
= res
->res
.dlg
;
853 po_file_t po
= get_po_file( dlg
->lvc
.language
);
855 compare_dialogs( english_dlg
, dlg
);
857 if (english_dlg
->title
&& dlg
->title
)
858 add_po_string( po
, english_dlg
->title
, dlg
->title
, dlg
->lvc
.language
);
859 add_po_dialog_controls( po
, english_dlg
->controls
, dlg
->controls
, dlg
->lvc
.language
);
862 static void add_pot_menu_items( po_file_t po
, const menu_item_t
*item
)
866 if (item
->name
) add_po_string( po
, item
->name
, NULL
, NULL
);
867 if (item
->popup
) add_pot_menu_items( po
, item
->popup
);
872 static void add_pot_menu( po_file_t po
, const resource_t
*res
)
874 add_pot_menu_items( po
, res
->res
.men
->items
);
877 static void add_po_menu_items( po_file_t po
, const menu_item_t
*english_item
,
878 const menu_item_t
*item
, const language_t
*lang
)
880 while (english_item
&& item
)
882 if (english_item
->name
&& item
->name
)
883 add_po_string( po
, english_item
->name
, item
->name
, lang
);
884 if (english_item
->popup
&& item
->popup
)
885 add_po_menu_items( po
, english_item
->popup
, item
->popup
, lang
);
887 english_item
= english_item
->next
;
891 static void add_po_menu( const resource_t
*english
, const resource_t
*res
)
893 const menu_item_t
*english_items
= english
->res
.men
->items
;
894 const menu_item_t
*items
= res
->res
.men
->items
;
895 po_file_t po
= get_po_file( res
->res
.men
->lvc
.language
);
897 add_po_menu_items( po
, english_items
, items
, res
->res
.men
->lvc
.language
);
900 static BOOL
string_has_context( const string_t
*str
)
902 char *id
, *id_buffer
, *context
;
904 id_buffer
= id
= convert_msgid_ascii( str
, 1 );
905 context
= get_message_context( &id
);
907 return context
!= NULL
;
910 static void add_pot_accel( po_file_t po
, const resource_t
*res
)
912 event_t
*event
= res
->res
.acc
->events
;
916 /* accelerators without a context don't make sense in po files */
917 if (event
->str
&& string_has_context( event
->str
))
918 add_po_string( po
, event
->str
, NULL
, NULL
);
923 static void add_po_accel( const resource_t
*english
, const resource_t
*res
)
925 event_t
*english_event
= english
->res
.acc
->events
;
926 event_t
*event
= res
->res
.acc
->events
;
927 po_file_t po
= get_po_file( res
->res
.acc
->lvc
.language
);
929 while (english_event
&& event
)
931 if (english_event
->str
&& event
->str
&& string_has_context( english_event
->str
))
932 add_po_string( po
, english_event
->str
, event
->str
, res
->res
.acc
->lvc
.language
);
934 english_event
= english_event
->next
;
938 static ver_block_t
*get_version_langcharset_block( ver_block_t
*block
)
940 ver_block_t
*stringfileinfo
= NULL
;
941 char *translation
= NULL
;
944 for (; block
; block
= block
->next
)
947 name
= convert_msgid_ascii( block
->name
, 0 );
948 if (!strcasecmp( name
, "stringfileinfo" ))
949 stringfileinfo
= block
;
950 else if (!strcasecmp( name
, "varfileinfo" ))
952 for (val
= block
->values
; val
; val
= val
->next
)
954 char *key
= convert_msgid_ascii( val
->key
, 0 );
955 if (val
->type
== val_words
&&
956 !strcasecmp( key
, "Translation" ) &&
957 val
->value
.words
->nwords
>= 2)
958 translation
= strmake( "%04x%04x",
959 val
->value
.words
->words
[0],
960 val
->value
.words
->words
[1] );
967 if (!stringfileinfo
|| !translation
) return NULL
;
969 for (val
= stringfileinfo
->values
; val
; val
= val
->next
)
972 if (val
->type
!= val_block
) continue;
973 block_name
= convert_msgid_ascii( val
->value
.block
->name
, 0 );
974 if (!strcasecmp( block_name
, translation
))
978 return val
->value
.block
;
986 static int version_value_needs_translation( const ver_value_t
*val
)
991 if (val
->type
!= val_str
) return 0;
992 if (!(key
= convert_msgid_ascii( val
->key
, 0 ))) return 0;
994 /* most values contain version numbers or file names, only translate a few specific ones */
995 ret
= (!strcasecmp( key
, "FileDescription" ) || !strcasecmp( key
, "ProductName" ));
1001 static void add_pot_versioninfo( po_file_t po
, const resource_t
*res
)
1004 ver_block_t
*langcharset
= get_version_langcharset_block( res
->res
.ver
->blocks
);
1006 if (!langcharset
) return;
1007 for (val
= langcharset
->values
; val
; val
= val
->next
)
1008 if (version_value_needs_translation( val
))
1009 add_po_string( po
, val
->value
.str
, NULL
, NULL
);
1012 static void add_po_versioninfo( const resource_t
*english
, const resource_t
*res
)
1014 const ver_block_t
*langcharset
= get_version_langcharset_block( res
->res
.ver
->blocks
);
1015 const ver_block_t
*english_langcharset
= get_version_langcharset_block( english
->res
.ver
->blocks
);
1016 ver_value_t
*val
, *english_val
;
1017 po_file_t po
= get_po_file( res
->res
.ver
->lvc
.language
);
1019 if (!langcharset
&& !english_langcharset
) return;
1020 val
= langcharset
->values
;
1021 english_val
= english_langcharset
->values
;
1022 while (english_val
&& val
)
1024 if (val
->type
== val_str
)
1025 add_po_string( po
, english_val
->value
.str
, val
->value
.str
, res
->res
.ver
->lvc
.language
);
1027 english_val
= english_val
->next
;
1031 static resource_t
*find_english_resource( resource_t
*res
)
1035 for (ptr
= resource_top
; ptr
; ptr
= ptr
->next
)
1037 if (ptr
->type
!= res
->type
) continue;
1038 if (!ptr
->lan
) continue;
1039 if (!is_english( ptr
->lan
)) continue;
1040 if (compare_name_id( ptr
->name
, res
->name
)) continue;
1046 void write_pot_file( const char *outname
)
1049 po_file_t po
= create_po_file();
1051 for (res
= resource_top
; res
; res
= res
->next
)
1053 if (!is_english( res
->lan
)) continue;
1057 case res_acc
: add_pot_accel( po
, res
); break;
1058 case res_dlg
: add_pot_dialog( po
, res
); break;
1059 case res_men
: add_pot_menu( po
, res
); break;
1060 case res_stt
: add_pot_stringtable( po
, res
); break;
1061 case res_ver
: add_pot_versioninfo( po
, res
); break;
1062 case res_msg
: break; /* FIXME */
1066 po_file_write( po
, outname
, &po_xerror_handler
);
1070 void write_po_files( const char *outname
)
1072 resource_t
*res
, *english
;
1074 for (res
= resource_top
; res
; res
= res
->next
)
1076 if (!(english
= find_english_resource( res
))) continue;
1079 case res_acc
: add_po_accel( english
, res
); break;
1080 case res_dlg
: add_po_dialog( english
, res
); break;
1081 case res_men
: add_po_menu( english
, res
); break;
1082 case res_stt
: add_po_stringtable( english
, res
); break;
1083 case res_ver
: add_po_versioninfo( english
, res
); break;
1084 case res_msg
: break; /* FIXME */
1088 if (!flush_po_files( outname
))
1090 if (outname
) error( "No translations found for %s\n", outname
);
1091 else error( "No translations found\n" );
1095 #endif /* HAVE_LIBGETTEXTPO */
1097 static struct mo_file
*mo_file
;
1099 static void byteswap( unsigned int *data
, unsigned int count
)
1103 for (i
= 0; i
< count
; i
++)
1104 data
[i
] = data
[i
] >> 24 | (data
[i
] >> 8 & 0xff00) | (data
[i
] << 8 & 0xff0000) | data
[i
] << 24;
1107 static void load_mo_file( const char *name
)
1112 fd
= open( name
, O_RDONLY
| O_BINARY
);
1113 if (fd
== -1) fatal_perror( "Failed to open %s", name
);
1115 mo_file
= xmalloc( st
.st_size
);
1116 res
= read( fd
, mo_file
, st
.st_size
);
1117 if (res
== -1) fatal_perror( "Failed to read %s", name
);
1118 else if (res
!= st
.st_size
) error( "Failed to read %s\n", name
);
1123 if (st
.st_size
< sizeof(*mo_file
))
1124 error( "%s is not a valid .mo file\n", name
);
1125 if (mo_file
->magic
== 0xde120495)
1126 byteswap( &mo_file
->revision
, 4 );
1127 else if (mo_file
->magic
!= 0x950412de)
1128 error( "%s is not a valid .mo file\n", name
);
1129 if ((mo_file
->revision
>> 16) > 1)
1130 error( "%s: unsupported file version %x\n", name
, mo_file
->revision
);
1131 if (mo_file
->msgid_off
>= st
.st_size
||
1132 mo_file
->msgstr_off
>= st
.st_size
||
1133 st
.st_size
< sizeof(*mo_file
) + 2 * 8 * mo_file
->count
)
1134 error( "%s: corrupted file\n", name
);
1136 if (mo_file
->magic
== 0xde120495)
1138 byteswap( (unsigned int *)((char *)mo_file
+ mo_file
->msgid_off
), 2 * mo_file
->count
);
1139 byteswap( (unsigned int *)((char *)mo_file
+ mo_file
->msgstr_off
), 2 * mo_file
->count
);
1143 static void free_mo_file(void)
1149 static inline const char *get_mo_msgid( int index
)
1151 const char *base
= (const char *)mo_file
;
1152 const unsigned int *offsets
= (const unsigned int *)(base
+ mo_file
->msgid_off
);
1153 return base
+ offsets
[2 * index
+ 1];
1156 static inline const char *get_mo_msgstr( int index
)
1158 const char *base
= (const char *)mo_file
;
1159 const unsigned int *offsets
= (const unsigned int *)(base
+ mo_file
->msgstr_off
);
1160 return base
+ offsets
[2 * index
+ 1];
1163 static const char *get_msgstr( const char *msgid
, const char *context
, int *found
)
1165 int pos
, res
, min
, max
;
1166 const char *ret
= msgid
;
1169 if (!mo_file
) /* strings containing a context still need to be transformed */
1171 if (context
) (*found
)++;
1175 if (context
) id
= strmake( "%s%c%s", context
, 4, msgid
);
1177 max
= mo_file
->count
- 1;
1180 pos
= (min
+ max
) / 2;
1181 res
= strcmp( get_mo_msgid(pos
), id
? id
: msgid
);
1184 const char *str
= get_mo_msgstr( pos
);
1185 if (str
[0]) /* ignore empty strings */
1192 if (res
> 0) max
= pos
- 1;
1199 static string_t
*translate_string( string_t
*str
, int *found
)
1201 string_t ustr
, *new;
1203 char *buffer
, *msgid
, *context
;
1205 if (!str
->size
|| !(buffer
= convert_msgid_ascii( str
, 0 )))
1206 return convert_string_unicode( str
, 1252 );
1209 context
= get_message_context( &msgid
);
1210 transl
= get_msgstr( msgid
, context
, found
);
1212 ustr
.type
= str_char
;
1213 ustr
.size
= strlen( transl
);
1214 ustr
.str
.cstr
= (char *)transl
;
1215 ustr
.loc
= str
->loc
;
1217 new = convert_string_unicode( &ustr
, CP_UTF8
);
1222 static control_t
*translate_controls( control_t
*ctrl
, int *found
)
1224 control_t
*new, *head
= NULL
, *tail
= NULL
;
1228 new = xmalloc( sizeof(*new) );
1230 if (control_has_title( ctrl
))
1232 new->title
= new_name_id();
1233 *new->title
= *ctrl
->title
;
1234 new->title
->name
.s_name
= translate_string( ctrl
->title
->name
.s_name
, found
);
1236 else new->title
= dup_name_id( ctrl
->title
);
1237 new->ctlclass
= dup_name_id( ctrl
->ctlclass
);
1238 if (tail
) tail
->next
= new;
1248 static menu_item_t
*translate_items( menu_item_t
*item
, int *found
)
1250 menu_item_t
*new, *head
= NULL
, *tail
= NULL
;
1254 new = xmalloc( sizeof(*new) );
1256 if (item
->name
) new->name
= translate_string( item
->name
, found
);
1257 if (item
->popup
) new->popup
= translate_items( item
->popup
, found
);
1258 if (tail
) tail
->next
= new;
1268 static stringtable_t
*translate_stringtable( stringtable_t
*stt
, language_t
*lang
, int *found
)
1270 stringtable_t
*new, *head
= NULL
, *tail
= NULL
;
1275 new = xmalloc( sizeof(*new) );
1277 new->lvc
.language
= lang
;
1278 new->lvc
.version
= get_dup_version( lang
);
1279 new->entries
= xmalloc( new->nentries
* sizeof(*new->entries
) );
1280 memcpy( new->entries
, stt
->entries
, new->nentries
* sizeof(*new->entries
) );
1281 for (i
= 0; i
< stt
->nentries
; i
++)
1282 if (stt
->entries
[i
].str
)
1283 new->entries
[i
].str
= translate_string( stt
->entries
[i
].str
, found
);
1285 if (tail
) tail
->next
= new;
1295 static void translate_dialog( dialog_t
*dlg
, dialog_t
*new, int *found
)
1297 if (dlg
->title
) new->title
= translate_string( dlg
->title
, found
);
1298 if (is_rtl_language( new->lvc
.language
))
1300 new->gotexstyle
= TRUE
;
1301 if (dlg
->gotexstyle
)
1302 new->exstyle
= new_style( dlg
->exstyle
->or_mask
| WS_EX_LAYOUTRTL
, dlg
->exstyle
->and_mask
);
1304 new->exstyle
= new_style( WS_EX_LAYOUTRTL
, 0 );
1308 new->font
= xmalloc( sizeof(*dlg
->font
) );
1309 *new->font
= *dlg
->font
;
1310 if (uses_larger_font( new->lvc
.language
)) new->font
->size
++;
1311 new->font
->name
= convert_string_unicode( dlg
->font
->name
, 1252 );
1313 new->controls
= translate_controls( dlg
->controls
, found
);
1316 static event_t
*translate_accel( accelerator_t
*acc
, accelerator_t
*new, int *found
)
1318 event_t
*event
, *new_ev
, *head
= NULL
, *tail
= NULL
;
1320 event
= acc
->events
;
1323 new_ev
= new_event();
1325 if (event
->str
) new_ev
->str
= translate_string( event
->str
, found
);
1326 if (tail
) tail
->next
= new_ev
;
1328 new_ev
->next
= NULL
;
1329 new_ev
->prev
= tail
;
1331 event
= event
->next
;
1336 static ver_value_t
*translate_langcharset_values( ver_value_t
*val
, language_t
*lang
, int *found
)
1338 ver_value_t
*new_val
, *head
= NULL
, *tail
= NULL
;
1341 new_val
= new_ver_value();
1343 if (val
->type
== val_str
)
1344 new_val
->value
.str
= translate_string( val
->value
.str
, found
);
1345 if (tail
) tail
->next
= new_val
;
1346 else head
= new_val
;
1347 new_val
->next
= NULL
;
1348 new_val
->prev
= tail
;
1355 static ver_value_t
*translate_stringfileinfo( ver_value_t
*val
, language_t
*lang
, int *found
)
1358 ver_value_t
*new_val
, *head
= NULL
, *tail
= NULL
;
1359 const char *english_block_name
[2] = { "040904b0", "040904e4" };
1360 char *block_name
[2];
1361 LANGID langid
= MAKELANGID( lang
->id
, get_default_sublang( lang
) );
1363 block_name
[0] = strmake( "%04x%04x", langid
, 1200 );
1364 block_name
[1] = strmake( "%04x%04x", langid
, get_language_codepage( lang
->id
, lang
->sub
) );
1368 new_val
= new_ver_value();
1370 if (val
->type
== val_block
)
1372 ver_block_t
*blk
, *blk_head
= NULL
, *blk_tail
= NULL
;
1373 for (blk
= val
->value
.block
; blk
; blk
= blk
->next
)
1375 ver_block_t
*new_blk
;
1377 new_blk
= new_ver_block();
1379 name
= convert_msgid_ascii( blk
->name
, 0 );
1380 for (i
= 0; i
< ARRAY_SIZE(block_name
); i
++)
1382 if (!strcasecmp( name
, english_block_name
[i
] ))
1385 str
.type
= str_char
;
1386 str
.size
= strlen( block_name
[i
] ) + 1;
1387 str
.str
.cstr
= block_name
[i
];
1388 str
.loc
= blk
->name
->loc
;
1389 new_blk
->name
= convert_string_unicode( &str
, CP_UTF8
);
1390 new_blk
->values
= translate_langcharset_values( blk
->values
, lang
, found
);
1394 if (blk_tail
) blk_tail
->next
= new_blk
;
1395 else blk_head
= new_blk
;
1396 new_blk
->next
= NULL
;
1397 new_blk
->prev
= blk_tail
;
1400 new_val
->value
.block
= blk_head
;
1402 if (tail
) tail
->next
= new_val
;
1403 else head
= new_val
;
1404 new_val
->next
= NULL
;
1405 new_val
->prev
= tail
;
1410 for (i
= 0; i
< ARRAY_SIZE(block_name
); i
++)
1411 free( block_name
[i
] );
1415 static ver_value_t
*translate_varfileinfo( ver_value_t
*val
, language_t
*lang
)
1417 ver_value_t
*new_val
, *head
= NULL
, *tail
= NULL
;
1421 new_val
= new_ver_value();
1423 if (val
->type
== val_words
)
1425 char *key
= convert_msgid_ascii( val
->key
, 0 );
1426 if (!strcasecmp( key
, "Translation" ) &&
1427 val
->value
.words
->nwords
== 2 &&
1428 val
->value
.words
->words
[0] == MAKELANGID( LANG_ENGLISH
, SUBLANG_ENGLISH_US
))
1430 ver_words_t
*new_words
;
1433 langid
= MAKELANGID( lang
->id
, get_default_sublang( lang
) );
1434 new_words
= new_ver_words( langid
);
1435 if (val
->value
.words
->words
[1] == 1200)
1438 codepage
= get_language_codepage( lang
->id
, lang
->sub
);
1439 new_val
->value
.words
= add_ver_words( new_words
, codepage
);
1443 if (tail
) tail
->next
= new_val
;
1444 else head
= new_val
;
1445 new_val
->next
= NULL
;
1446 new_val
->prev
= tail
;
1453 static ver_block_t
*translate_versioninfo( ver_block_t
*blk
, language_t
*lang
, int *found
)
1455 ver_block_t
*new_blk
, *head
= NULL
, *tail
= NULL
;
1460 new_blk
= new_ver_block();
1462 name
= convert_msgid_ascii( blk
->name
, 0 );
1463 if (!strcasecmp( name
, "stringfileinfo" ))
1464 new_blk
->values
= translate_stringfileinfo( blk
->values
, lang
, found
);
1465 else if (!strcasecmp( name
, "varfileinfo" ))
1466 new_blk
->values
= translate_varfileinfo( blk
->values
, lang
);
1468 if (tail
) tail
->next
= new_blk
;
1469 else head
= new_blk
;
1470 new_blk
->next
= NULL
;
1471 new_blk
->prev
= tail
;
1478 static void translate_resources( language_t
*lang
)
1482 for (res
= resource_top
; res
; res
= res
->next
)
1484 resource_t
*new = NULL
;
1487 if (!is_english( res
->lan
)) continue;
1492 new = dup_resource( res
, lang
);
1493 new->res
.acc
->events
= translate_accel( res
->res
.acc
, new->res
.acc
, &found
);
1496 new = dup_resource( res
, lang
);
1497 translate_dialog( res
->res
.dlg
, new->res
.dlg
, &found
);
1500 new = dup_resource( res
, lang
);
1501 new->res
.men
->items
= translate_items( res
->res
.men
->items
, &found
);
1504 new = dup_resource( res
, lang
);
1505 new->res
.stt
= translate_stringtable( res
->res
.stt
, lang
, &found
);
1508 new = dup_resource( res
, lang
);
1509 new->res
.ver
->blocks
= translate_versioninfo( res
->res
.ver
->blocks
, lang
, &found
);
1520 if (new_tail
) new_tail
->next
= new;
1522 new->prev
= new_tail
;
1528 void add_translations( const char *po_dir
)
1532 char *p
, *tok
, *name
;
1536 /* first check if we have English resources to translate */
1537 for (res
= resource_top
; res
; res
= res
->next
) if (is_english( res
->lan
)) break;
1540 if (!po_dir
) /* run through the translation process to remove msg contexts */
1542 translate_resources( new_language( LANG_ENGLISH
, SUBLANG_DEFAULT
));
1546 new_top
= new_tail
= NULL
;
1548 name
= strmake( "%s/LINGUAS", po_dir
);
1549 if (!(f
= fopen( name
, "r" )))
1555 while (fgets( buffer
, sizeof(buffer
), f
))
1557 if ((p
= strchr( buffer
, '#' ))) *p
= 0;
1558 for (tok
= strtok( buffer
, " \t\r\n" ); tok
; tok
= strtok( NULL
, " \t\r\n" ))
1560 for (i
= 0; i
< ARRAY_SIZE(languages
); i
++)
1561 if (!strcmp( tok
, languages
[i
].name
)) break;
1563 if (i
== ARRAY_SIZE(languages
))
1564 error( "unknown language '%s'\n", tok
);
1566 name
= strmake( "%s/%s.mo", po_dir
, tok
);
1567 load_mo_file( name
);
1568 translate_resources( new_language(languages
[i
].id
, languages
[i
].sub
) );
1576 /* prepend the translated resources to the global list */
1579 new_tail
->next
= resource_top
;
1580 resource_top
->prev
= new_tail
;
1581 resource_top
= new_top
;