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"
43 #include "wine/unicode.h"
45 static resource_t
*new_top
, *new_tail
;
50 unsigned int revision
;
52 unsigned int msgid_off
;
53 unsigned int msgstr_off
;
54 /* ... rest of file data here */
57 static int is_english( const language_t
*lan
)
59 return lan
->id
== LANG_ENGLISH
&& lan
->sub
== SUBLANG_DEFAULT
;
62 static int is_rtl_language( const language_t
*lan
)
64 return lan
->id
== LANG_ARABIC
|| lan
->id
== LANG_HEBREW
|| lan
->id
== LANG_PERSIAN
;
67 static int uses_larger_font( const language_t
*lan
)
69 return lan
->id
== LANG_CHINESE
|| lan
->id
== LANG_JAPANESE
|| lan
->id
== LANG_KOREAN
;
72 static version_t
*get_dup_version( language_t
*lang
)
74 /* English "translations" take precedence over the original rc contents */
75 return new_version( is_english( lang
) ? 1 : -1 );
78 static name_id_t
*dup_name_id( name_id_t
*id
)
82 if (!id
|| id
->type
!= name_str
) return id
;
85 new->name
.s_name
= convert_string( id
->name
.s_name
, str_unicode
, 1252 );
89 static char *convert_msgid_ascii( const string_t
*str
, int error_on_invalid_char
)
92 string_t
*newstr
= convert_string( str
, str_unicode
, 1252 );
93 char *buffer
= xmalloc( newstr
->size
+ 1 );
95 for (i
= 0; i
< newstr
->size
; i
++)
97 buffer
[i
] = newstr
->str
.wstr
[i
];
98 if (newstr
->str
.wstr
[i
] >= 32 && newstr
->str
.wstr
[i
] <= 127) continue;
99 if (newstr
->str
.wstr
[i
] == '\t' || newstr
->str
.wstr
[i
] == '\n') continue;
100 if (error_on_invalid_char
)
102 print_location( &newstr
->loc
);
103 error( "Invalid character %04x in source string\n", newstr
->str
.wstr
[i
] );
106 free_string( newstr
);
110 free_string( newstr
);
114 static char *get_message_context( char **msgid
)
116 static const char magic
[] = "#msgctxt#";
119 if (strncmp( *msgid
, magic
, sizeof(magic
) - 1 )) return NULL
;
120 context
= *msgid
+ sizeof(magic
) - 1;
121 if (!(id
= strchr( context
, '#' ))) return NULL
;
127 static int control_has_title( const control_t
*ctrl
)
129 if (!ctrl
->title
) return 0;
130 if (ctrl
->title
->type
!= name_str
) return 0;
131 /* check for text static control */
132 if (ctrl
->ctlclass
&& ctrl
->ctlclass
->type
== name_ord
&& ctrl
->ctlclass
->name
.i_name
== CT_STATIC
)
134 switch (ctrl
->style
->or_mask
& SS_TYPEMASK
)
147 static resource_t
*dup_resource( resource_t
*res
, language_t
*lang
)
149 resource_t
*new = xmalloc( sizeof(*new) );
153 new->next
= new->prev
= NULL
;
154 new->name
= dup_name_id( res
->name
);
159 new->res
.dlg
= xmalloc( sizeof(*(new)->res
.dlg
) );
160 *new->res
.dlg
= *res
->res
.dlg
;
161 new->res
.dlg
->lvc
.language
= lang
;
162 new->res
.dlg
->lvc
.version
= get_dup_version( lang
);
165 new->res
.men
= xmalloc( sizeof(*(new)->res
.men
) );
166 *new->res
.men
= *res
->res
.men
;
167 new->res
.men
->lvc
.language
= lang
;
168 new->res
.men
->lvc
.version
= get_dup_version( lang
);
171 new->res
.stt
= xmalloc( sizeof(*(new)->res
.stt
) );
172 *new->res
.stt
= *res
->res
.stt
;
173 new->res
.stt
->lvc
.language
= lang
;
174 new->res
.stt
->lvc
.version
= get_dup_version( lang
);
184 unsigned int id
, sub
;
188 { LANG_ARABIC
, SUBLANG_NEUTRAL
, "ar" },
189 { LANG_ARABIC
, SUBLANG_ARABIC_SAUDI_ARABIA
, "ar_SA" },
190 { LANG_ARABIC
, SUBLANG_ARABIC_IRAQ
, "ar_IQ" },
191 { LANG_ARABIC
, SUBLANG_ARABIC_EGYPT
, "ar_EG" },
192 { LANG_ARABIC
, SUBLANG_ARABIC_LIBYA
, "ar_LY" },
193 { LANG_ARABIC
, SUBLANG_ARABIC_ALGERIA
, "ar_DZ" },
194 { LANG_ARABIC
, SUBLANG_ARABIC_MOROCCO
, "ar_MA" },
195 { LANG_ARABIC
, SUBLANG_ARABIC_TUNISIA
, "ar_TN" },
196 { LANG_ARABIC
, SUBLANG_ARABIC_OMAN
, "ar_OM" },
197 { LANG_ARABIC
, SUBLANG_ARABIC_YEMEN
, "ar_YE" },
198 { LANG_ARABIC
, SUBLANG_ARABIC_SYRIA
, "ar_SY" },
199 { LANG_ARABIC
, SUBLANG_ARABIC_JORDAN
, "ar_JO" },
200 { LANG_ARABIC
, SUBLANG_ARABIC_LEBANON
, "ar_LB" },
201 { LANG_ARABIC
, SUBLANG_ARABIC_KUWAIT
, "ar_KW" },
202 { LANG_ARABIC
, SUBLANG_ARABIC_UAE
, "ar_AE" },
203 { LANG_ARABIC
, SUBLANG_ARABIC_BAHRAIN
, "ar_BH" },
204 { LANG_ARABIC
, SUBLANG_ARABIC_QATAR
, "ar_QA" },
205 { LANG_BULGARIAN
, SUBLANG_NEUTRAL
, "bg" },
206 { LANG_BULGARIAN
, SUBLANG_BULGARIAN_BULGARIA
, "bg_BG" },
207 { LANG_CATALAN
, SUBLANG_NEUTRAL
, "ca" },
208 { LANG_CATALAN
, SUBLANG_CATALAN_CATALAN
, "ca_ES" },
209 { LANG_CHINESE
, SUBLANG_NEUTRAL
, "zh" },
210 { LANG_CHINESE
, SUBLANG_CHINESE_TRADITIONAL
, "zh_TW" },
211 { LANG_CHINESE
, SUBLANG_CHINESE_SIMPLIFIED
, "zh_CN" },
212 { LANG_CHINESE
, SUBLANG_CHINESE_HONGKONG
, "zh_HK" },
213 { LANG_CHINESE
, SUBLANG_CHINESE_SINGAPORE
, "zh_SG" },
214 { LANG_CHINESE
, SUBLANG_CHINESE_MACAU
, "zh_MO" },
215 { LANG_CZECH
, SUBLANG_NEUTRAL
, "cs" },
216 { LANG_CZECH
, SUBLANG_CZECH_CZECH_REPUBLIC
, "cs_CZ" },
217 { LANG_DANISH
, SUBLANG_NEUTRAL
, "da" },
218 { LANG_DANISH
, SUBLANG_DANISH_DENMARK
, "da_DK" },
219 { LANG_GERMAN
, SUBLANG_NEUTRAL
, "de" },
220 { LANG_GERMAN
, SUBLANG_GERMAN
, "de_DE" },
221 { LANG_GERMAN
, SUBLANG_GERMAN_SWISS
, "de_CH" },
222 { LANG_GERMAN
, SUBLANG_GERMAN_AUSTRIAN
, "de_AT" },
223 { LANG_GERMAN
, SUBLANG_GERMAN_LUXEMBOURG
, "de_LU" },
224 { LANG_GERMAN
, SUBLANG_GERMAN_LIECHTENSTEIN
, "de_LI" },
225 { LANG_GREEK
, SUBLANG_NEUTRAL
, "el" },
226 { LANG_GREEK
, SUBLANG_GREEK_GREECE
, "el_GR" },
227 { LANG_ENGLISH
, SUBLANG_NEUTRAL
, "en" },
228 { LANG_ENGLISH
, SUBLANG_ENGLISH_US
, "en_US" },
229 { LANG_ENGLISH
, SUBLANG_ENGLISH_UK
, "en_GB" },
230 { LANG_ENGLISH
, SUBLANG_ENGLISH_AUS
, "en_AU" },
231 { LANG_ENGLISH
, SUBLANG_ENGLISH_CAN
, "en_CA" },
232 { LANG_ENGLISH
, SUBLANG_ENGLISH_NZ
, "en_NZ" },
233 { LANG_ENGLISH
, SUBLANG_ENGLISH_EIRE
, "en_IE" },
234 { LANG_ENGLISH
, SUBLANG_ENGLISH_SOUTH_AFRICA
, "en_ZA" },
235 { LANG_ENGLISH
, SUBLANG_ENGLISH_JAMAICA
, "en_JM" },
236 { LANG_ENGLISH
, SUBLANG_ENGLISH_CARIBBEAN
, "en_CB" },
237 { LANG_ENGLISH
, SUBLANG_ENGLISH_BELIZE
, "en_BZ" },
238 { LANG_ENGLISH
, SUBLANG_ENGLISH_TRINIDAD
, "en_TT" },
239 { LANG_ENGLISH
, SUBLANG_ENGLISH_ZIMBABWE
, "en_ZW" },
240 { LANG_ENGLISH
, SUBLANG_ENGLISH_PHILIPPINES
, "en_PH" },
241 { LANG_SPANISH
, SUBLANG_NEUTRAL
, "es" },
242 { LANG_SPANISH
, SUBLANG_SPANISH
, "es_ES" },
243 { LANG_SPANISH
, SUBLANG_SPANISH_MEXICAN
, "es_MX" },
244 { LANG_SPANISH
, SUBLANG_SPANISH_MODERN
, "es_ES_modern" },
245 { LANG_SPANISH
, SUBLANG_SPANISH_GUATEMALA
, "es_GT" },
246 { LANG_SPANISH
, SUBLANG_SPANISH_COSTA_RICA
, "es_CR" },
247 { LANG_SPANISH
, SUBLANG_SPANISH_PANAMA
, "es_PA" },
248 { LANG_SPANISH
, SUBLANG_SPANISH_DOMINICAN_REPUBLIC
, "es_DO" },
249 { LANG_SPANISH
, SUBLANG_SPANISH_VENEZUELA
, "es_VE" },
250 { LANG_SPANISH
, SUBLANG_SPANISH_COLOMBIA
, "es_CO" },
251 { LANG_SPANISH
, SUBLANG_SPANISH_PERU
, "es_PE" },
252 { LANG_SPANISH
, SUBLANG_SPANISH_ARGENTINA
, "es_AR" },
253 { LANG_SPANISH
, SUBLANG_SPANISH_ECUADOR
, "es_EC" },
254 { LANG_SPANISH
, SUBLANG_SPANISH_CHILE
, "es_CL" },
255 { LANG_SPANISH
, SUBLANG_SPANISH_URUGUAY
, "es_UY" },
256 { LANG_SPANISH
, SUBLANG_SPANISH_PARAGUAY
, "es_PY" },
257 { LANG_SPANISH
, SUBLANG_SPANISH_BOLIVIA
, "es_BO" },
258 { LANG_SPANISH
, SUBLANG_SPANISH_EL_SALVADOR
, "es_SV" },
259 { LANG_SPANISH
, SUBLANG_SPANISH_HONDURAS
, "es_HN" },
260 { LANG_SPANISH
, SUBLANG_SPANISH_NICARAGUA
, "es_NI" },
261 { LANG_SPANISH
, SUBLANG_SPANISH_PUERTO_RICO
, "es_PR" },
262 { LANG_FINNISH
, SUBLANG_NEUTRAL
, "fi" },
263 { LANG_FINNISH
, SUBLANG_FINNISH_FINLAND
, "fi_FI" },
264 { LANG_FRENCH
, SUBLANG_NEUTRAL
, "fr" },
265 { LANG_FRENCH
, SUBLANG_FRENCH
, "fr_FR" },
266 { LANG_FRENCH
, SUBLANG_FRENCH_BELGIAN
, "fr_BE" },
267 { LANG_FRENCH
, SUBLANG_FRENCH_CANADIAN
, "fr_CA" },
268 { LANG_FRENCH
, SUBLANG_FRENCH_SWISS
, "fr_CH" },
269 { LANG_FRENCH
, SUBLANG_FRENCH_LUXEMBOURG
, "fr_LU" },
270 { LANG_FRENCH
, SUBLANG_FRENCH_MONACO
, "fr_MC" },
271 { LANG_HEBREW
, SUBLANG_NEUTRAL
, "he" },
272 { LANG_HEBREW
, SUBLANG_HEBREW_ISRAEL
, "he_IL" },
273 { LANG_HUNGARIAN
, SUBLANG_NEUTRAL
, "hu" },
274 { LANG_HUNGARIAN
, SUBLANG_HUNGARIAN_HUNGARY
, "hu_HU" },
275 { LANG_ICELANDIC
, SUBLANG_NEUTRAL
, "is" },
276 { LANG_ICELANDIC
, SUBLANG_ICELANDIC_ICELAND
, "is_IS" },
277 { LANG_ITALIAN
, SUBLANG_NEUTRAL
, "it" },
278 { LANG_ITALIAN
, SUBLANG_ITALIAN
, "it_IT" },
279 { LANG_ITALIAN
, SUBLANG_ITALIAN_SWISS
, "it_CH" },
280 { LANG_JAPANESE
, SUBLANG_NEUTRAL
, "ja" },
281 { LANG_JAPANESE
, SUBLANG_JAPANESE_JAPAN
, "ja_JP" },
282 { LANG_KOREAN
, SUBLANG_NEUTRAL
, "ko" },
283 { LANG_KOREAN
, SUBLANG_KOREAN
, "ko_KR" },
284 { LANG_DUTCH
, SUBLANG_NEUTRAL
, "nl" },
285 { LANG_DUTCH
, SUBLANG_DUTCH
, "nl_NL" },
286 { LANG_DUTCH
, SUBLANG_DUTCH_BELGIAN
, "nl_BE" },
287 { LANG_DUTCH
, SUBLANG_DUTCH_SURINAM
, "nl_SR" },
288 { LANG_NORWEGIAN
, SUBLANG_NORWEGIAN_BOKMAL
, "nb_NO" },
289 { LANG_NORWEGIAN
, SUBLANG_NORWEGIAN_NYNORSK
, "nn_NO" },
290 { LANG_POLISH
, SUBLANG_NEUTRAL
, "pl" },
291 { LANG_POLISH
, SUBLANG_POLISH_POLAND
, "pl_PL" },
292 { LANG_PORTUGUESE
, SUBLANG_NEUTRAL
, "pt" },
293 { LANG_PORTUGUESE
, SUBLANG_PORTUGUESE_BRAZILIAN
, "pt_BR" },
294 { LANG_PORTUGUESE
, SUBLANG_PORTUGUESE_PORTUGAL
, "pt_PT" },
295 { LANG_ROMANSH
, SUBLANG_NEUTRAL
, "rm" },
296 { LANG_ROMANSH
, SUBLANG_ROMANSH_SWITZERLAND
, "rm_CH" },
297 { LANG_ROMANIAN
, SUBLANG_NEUTRAL
, "ro" },
298 { LANG_ROMANIAN
, SUBLANG_ROMANIAN_ROMANIA
, "ro_RO" },
299 { LANG_RUSSIAN
, SUBLANG_NEUTRAL
, "ru" },
300 { LANG_RUSSIAN
, SUBLANG_RUSSIAN_RUSSIA
, "ru_RU" },
301 { LANG_SERBIAN
, SUBLANG_NEUTRAL
, "hr" },
302 { LANG_SERBIAN
, SUBLANG_SERBIAN_CROATIA
, "hr_HR" },
303 { LANG_SERBIAN
, SUBLANG_SERBIAN_LATIN
, "sr_RS@latin" },
304 { LANG_SERBIAN
, SUBLANG_SERBIAN_CYRILLIC
, "sr_RS@cyrillic" },
305 { LANG_SLOVAK
, SUBLANG_NEUTRAL
, "sk" },
306 { LANG_SLOVAK
, SUBLANG_SLOVAK_SLOVAKIA
, "sk_SK" },
307 { LANG_ALBANIAN
, SUBLANG_NEUTRAL
, "sq" },
308 { LANG_ALBANIAN
, SUBLANG_ALBANIAN_ALBANIA
, "sq_AL" },
309 { LANG_SWEDISH
, SUBLANG_NEUTRAL
, "sv" },
310 { LANG_SWEDISH
, SUBLANG_SWEDISH_SWEDEN
, "sv_SE" },
311 { LANG_SWEDISH
, SUBLANG_SWEDISH_FINLAND
, "sv_FI" },
312 { LANG_THAI
, SUBLANG_NEUTRAL
, "th" },
313 { LANG_THAI
, SUBLANG_THAI_THAILAND
, "th_TH" },
314 { LANG_TURKISH
, SUBLANG_NEUTRAL
, "tr" },
315 { LANG_TURKISH
, SUBLANG_TURKISH_TURKEY
, "tr_TR" },
316 { LANG_URDU
, SUBLANG_NEUTRAL
, "ur" },
317 { LANG_URDU
, SUBLANG_URDU_PAKISTAN
, "ur_PK" },
318 { LANG_INDONESIAN
, SUBLANG_NEUTRAL
, "id" },
319 { LANG_INDONESIAN
, SUBLANG_INDONESIAN_INDONESIA
, "id_ID" },
320 { LANG_UKRAINIAN
, SUBLANG_NEUTRAL
, "uk" },
321 { LANG_UKRAINIAN
, SUBLANG_UKRAINIAN_UKRAINE
, "uk_UA" },
322 { LANG_BELARUSIAN
, SUBLANG_NEUTRAL
, "be" },
323 { LANG_BELARUSIAN
, SUBLANG_BELARUSIAN_BELARUS
, "be_BY" },
324 { LANG_SLOVENIAN
, SUBLANG_NEUTRAL
, "sl" },
325 { LANG_SLOVENIAN
, SUBLANG_SLOVENIAN_SLOVENIA
, "sl_SI" },
326 { LANG_ESTONIAN
, SUBLANG_NEUTRAL
, "et" },
327 { LANG_ESTONIAN
, SUBLANG_ESTONIAN_ESTONIA
, "et_EE" },
328 { LANG_LATVIAN
, SUBLANG_NEUTRAL
, "lv" },
329 { LANG_LATVIAN
, SUBLANG_LATVIAN_LATVIA
, "lv_LV" },
330 { LANG_LITHUANIAN
, SUBLANG_NEUTRAL
, "lt" },
331 { LANG_LITHUANIAN
, SUBLANG_LITHUANIAN_LITHUANIA
, "lt_LT" },
332 { LANG_PERSIAN
, SUBLANG_NEUTRAL
, "fa" },
333 { LANG_PERSIAN
, SUBLANG_PERSIAN_IRAN
, "fa_IR" },
334 { LANG_ARMENIAN
, SUBLANG_NEUTRAL
, "hy" },
335 { LANG_ARMENIAN
, SUBLANG_ARMENIAN_ARMENIA
, "hy_AM" },
336 { LANG_AZERI
, SUBLANG_NEUTRAL
, "az" },
337 { LANG_AZERI
, SUBLANG_AZERI_LATIN
, "az_AZ@latin" },
338 { LANG_AZERI
, SUBLANG_AZERI_CYRILLIC
, "az_AZ@cyrillic" },
339 { LANG_BASQUE
, SUBLANG_NEUTRAL
, "eu" },
340 { LANG_BASQUE
, SUBLANG_BASQUE_BASQUE
, "eu_ES" },
341 { LANG_MACEDONIAN
, SUBLANG_NEUTRAL
, "mk" },
342 { LANG_MACEDONIAN
, SUBLANG_MACEDONIAN_MACEDONIA
, "mk_MK" },
343 { LANG_AFRIKAANS
, SUBLANG_NEUTRAL
, "af" },
344 { LANG_AFRIKAANS
, SUBLANG_AFRIKAANS_SOUTH_AFRICA
, "af_ZA" },
345 { LANG_GEORGIAN
, SUBLANG_NEUTRAL
, "ka" },
346 { LANG_GEORGIAN
, SUBLANG_GEORGIAN_GEORGIA
, "ka_GE" },
347 { LANG_FAEROESE
, SUBLANG_NEUTRAL
, "fo" },
348 { LANG_FAEROESE
, SUBLANG_FAEROESE_FAROE_ISLANDS
, "fo_FO" },
349 { LANG_HINDI
, SUBLANG_NEUTRAL
, "hi" },
350 { LANG_HINDI
, SUBLANG_HINDI_INDIA
, "hi_IN" },
351 { LANG_MALAY
, SUBLANG_NEUTRAL
, "ms" },
352 { LANG_MALAY
, SUBLANG_MALAY_MALAYSIA
, "ms_MY" },
353 { LANG_MALAY
, SUBLANG_MALAY_BRUNEI_DARUSSALAM
, "ms_BN" },
354 { LANG_KAZAK
, SUBLANG_NEUTRAL
, "kk" },
355 { LANG_KAZAK
, SUBLANG_KAZAK_KAZAKHSTAN
, "kk_KZ" },
356 { LANG_KYRGYZ
, SUBLANG_NEUTRAL
, "ky" },
357 { LANG_KYRGYZ
, SUBLANG_KYRGYZ_KYRGYZSTAN
, "ky_KG" },
358 { LANG_SWAHILI
, SUBLANG_NEUTRAL
, "sw" },
359 { LANG_SWAHILI
, SUBLANG_SWAHILI_KENYA
, "sw_KE" },
360 { LANG_UZBEK
, SUBLANG_NEUTRAL
, "uz" },
361 { LANG_UZBEK
, SUBLANG_UZBEK_LATIN
, "uz_UZ@latin" },
362 { LANG_UZBEK
, SUBLANG_UZBEK_CYRILLIC
, "uz_UZ@cyrillic" },
363 { LANG_TATAR
, SUBLANG_NEUTRAL
, "tt" },
364 { LANG_TATAR
, SUBLANG_TATAR_RUSSIA
, "tt_TA" },
365 { LANG_PUNJABI
, SUBLANG_NEUTRAL
, "pa" },
366 { LANG_PUNJABI
, SUBLANG_PUNJABI_INDIA
, "pa_IN" },
367 { LANG_GUJARATI
, SUBLANG_NEUTRAL
, "gu" },
368 { LANG_GUJARATI
, SUBLANG_GUJARATI_INDIA
, "gu_IN" },
369 { LANG_ORIYA
, SUBLANG_NEUTRAL
, "or" },
370 { LANG_ORIYA
, SUBLANG_ORIYA_INDIA
, "or_IN" },
371 { LANG_TAMIL
, SUBLANG_NEUTRAL
, "ta" },
372 { LANG_TAMIL
, SUBLANG_TAMIL_INDIA
, "ta_IN" },
373 { LANG_TELUGU
, SUBLANG_NEUTRAL
, "te" },
374 { LANG_TELUGU
, SUBLANG_TELUGU_INDIA
, "te_IN" },
375 { LANG_KANNADA
, SUBLANG_NEUTRAL
, "kn" },
376 { LANG_KANNADA
, SUBLANG_KANNADA_INDIA
, "kn_IN" },
377 { LANG_MALAYALAM
, SUBLANG_NEUTRAL
, "ml" },
378 { LANG_MALAYALAM
, SUBLANG_MALAYALAM_INDIA
, "ml_IN" },
379 { LANG_MARATHI
, SUBLANG_NEUTRAL
, "mr" },
380 { LANG_MARATHI
, SUBLANG_MARATHI_INDIA
, "mr_IN" },
381 { LANG_SANSKRIT
, SUBLANG_NEUTRAL
, "sa" },
382 { LANG_SANSKRIT
, SUBLANG_SANSKRIT_INDIA
, "sa_IN" },
383 { LANG_MONGOLIAN
, SUBLANG_NEUTRAL
, "mn" },
384 { LANG_MONGOLIAN
, SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA
, "mn_MN" },
385 { LANG_WELSH
, SUBLANG_NEUTRAL
, "cy" },
386 { LANG_WELSH
, SUBLANG_WELSH_UNITED_KINGDOM
, "cy_GB" },
387 { LANG_GALICIAN
, SUBLANG_NEUTRAL
, "gl" },
388 { LANG_GALICIAN
, SUBLANG_GALICIAN_GALICIAN
, "gl_ES" },
389 { LANG_KONKANI
, SUBLANG_NEUTRAL
, "kok" },
390 { LANG_KONKANI
, SUBLANG_KONKANI_INDIA
, "kok_IN" },
391 { LANG_DIVEHI
, SUBLANG_NEUTRAL
, "dv" },
392 { LANG_DIVEHI
, SUBLANG_DIVEHI_MALDIVES
, "dv_MV" },
393 { LANG_BRETON
, SUBLANG_NEUTRAL
, "br" },
394 { LANG_BRETON
, SUBLANG_BRETON_FRANCE
, "br_FR" },
396 #ifdef LANG_ESPERANTO
397 { LANG_ESPERANTO
, SUBLANG_DEFAULT
, "eo" },
400 { LANG_WALON
, SUBLANG_NEUTRAL
, "wa" },
401 { LANG_WALON
, SUBLANG_DEFAULT
, "wa_BE" },
404 { LANG_CORNISH
, SUBLANG_NEUTRAL
, "kw" },
405 { LANG_CORNISH
, SUBLANG_DEFAULT
, "kw_GB" },
408 { LANG_GAELIC
, SUBLANG_NEUTRAL
, "ga" },
409 { LANG_GAELIC
, SUBLANG_GAELIC
, "ga_IE" },
410 { LANG_GAELIC
, SUBLANG_GAELIC_SCOTTISH
, "gd_GB" },
411 { LANG_GAELIC
, SUBLANG_GAELIC_MANX
, "gv_GB" },
415 #ifndef HAVE_LIBGETTEXTPO
417 void write_pot_file( const char *outname
)
419 error( "PO files not supported in this wrc build\n" );
422 void write_po_files( const char *outname
)
424 error( "PO files not supported in this wrc build\n" );
427 #else /* HAVE_LIBGETTEXTPO */
429 static void po_xerror( int severity
, po_message_t message
,
430 const char *filename
, size_t lineno
, size_t column
,
431 int multiline_p
, const char *message_text
)
433 fprintf( stderr
, "%s:%u:%u: %s\n",
434 filename
, (unsigned int)lineno
, (unsigned int)column
, message_text
);
435 if (severity
) exit(1);
438 static void po_xerror2( int severity
, po_message_t message1
,
439 const char *filename1
, size_t lineno1
, size_t column1
,
440 int multiline_p1
, const char *message_text1
,
441 po_message_t message2
,
442 const char *filename2
, size_t lineno2
, size_t column2
,
443 int multiline_p2
, const char *message_text2
)
445 fprintf( stderr
, "%s:%u:%u: %s\n",
446 filename1
, (unsigned int)lineno1
, (unsigned int)column1
, message_text1
);
447 fprintf( stderr
, "%s:%u:%u: %s\n",
448 filename2
, (unsigned int)lineno2
, (unsigned int)column2
, message_text2
);
449 if (severity
) exit(1);
452 static const struct po_xerror_handler po_xerror_handler
= { po_xerror
, po_xerror2
};
454 static char *convert_string_utf8( const string_t
*str
, int codepage
)
456 string_t
*newstr
= convert_string( str
, str_unicode
, codepage
);
457 char *buffer
= xmalloc( newstr
->size
* 4 + 1 );
458 int len
= wine_utf8_wcstombs( 0, newstr
->str
.wstr
, newstr
->size
, buffer
, newstr
->size
* 4 );
460 free_string( newstr
);
464 static po_message_t
find_message( po_file_t po
, const char *msgid
, const char *msgctxt
,
465 po_message_iterator_t
*iterator
)
470 *iterator
= po_message_iterator( po
, NULL
);
471 while ((msg
= po_next_message( *iterator
)))
473 if (strcmp( po_message_msgid( msg
), msgid
)) continue;
475 if (!(context
= po_message_msgctxt( msg
))) continue;
476 if (!strcmp( context
, msgctxt
)) break;
481 static void add_po_string( po_file_t po
, const string_t
*msgid
, const string_t
*msgstr
,
482 const language_t
*lang
)
484 static const char dnt
[] = "do not translate";
486 po_message_iterator_t iterator
;
488 char *id
, *id_buffer
, *context
, *str
= NULL
, *str_buffer
= NULL
;
490 if (!msgid
->size
) return;
492 id_buffer
= id
= convert_msgid_ascii( msgid
, 1 );
493 context
= get_message_context( &id
);
494 if (context
&& strcmp(context
, dnt
) == 0)
496 /* This string should not be translated */
503 if (lang
) codepage
= get_language_codepage( lang
->id
, lang
->sub
);
504 else codepage
= get_language_codepage( 0, 0 );
505 assert( codepage
!= -1 );
506 str_buffer
= str
= convert_string_utf8( msgstr
, codepage
);
507 if (is_english( lang
)) get_message_context( &str
);
509 if (!(msg
= find_message( po
, id
, context
, &iterator
)))
511 msg
= po_message_create();
512 po_message_set_msgid( msg
, id
);
513 po_message_set_msgstr( msg
, str
? str
: "" );
514 if (context
) po_message_set_msgctxt( msg
, context
);
515 po_message_insert( iterator
, msg
);
517 if (msgid
->loc
.file
) po_message_add_filepos( msg
, msgid
->loc
.file
, msgid
->loc
.line
);
518 po_message_iterator_free( iterator
);
530 static struct list po_file_langs
= LIST_INIT( po_file_langs
);
532 static po_file_t
create_po_file(void)
536 po_message_iterator_t iterator
;
538 po
= po_file_create();
539 iterator
= po_message_iterator( po
, NULL
);
540 msg
= po_message_create();
541 po_message_set_msgid( msg
, "" );
542 po_message_set_msgstr( msg
,
543 "Project-Id-Version: Wine\n"
544 "Report-Msgid-Bugs-To: http://bugs.winehq.org\n"
545 "POT-Creation-Date: N/A\n"
546 "PO-Revision-Date: N/A\n"
547 "Last-Translator: Automatically generated\n"
548 "Language-Team: none\n"
549 "MIME-Version: 1.0\n"
550 "Content-Type: text/plain; charset=UTF-8\n"
551 "Content-Transfer-Encoding: 8bit\n" );
552 po_message_insert( iterator
, msg
);
553 po_message_iterator_free( iterator
);
557 static po_file_t
get_po_file( const language_t
*lang
)
559 struct po_file_lang
*po_file
;
561 LIST_FOR_EACH_ENTRY( po_file
, &po_file_langs
, struct po_file_lang
, entry
)
562 if (po_file
->lang
.id
== lang
->id
&& po_file
->lang
.sub
== lang
->sub
) return po_file
->po
;
564 /* create a new one */
565 po_file
= xmalloc( sizeof(*po_file
) );
566 po_file
->lang
= *lang
;
567 po_file
->po
= create_po_file();
568 list_add_tail( &po_file_langs
, &po_file
->entry
);
572 static const char *get_language_name( const language_t
*lang
)
574 static char name
[20];
577 for (i
= 0; i
< sizeof(languages
)/sizeof(languages
[0]); i
++)
578 if (languages
[i
].id
== lang
->id
&& languages
[i
].sub
== lang
->sub
)
579 return languages
[i
].name
;
581 sprintf( name
, "%02x-%02x", lang
->id
, lang
->sub
);
585 static char *get_po_file_name( const language_t
*lang
)
587 return strmake( "%s.po", get_language_name( lang
) );
590 static unsigned int flush_po_files( const char *output_name
)
592 struct po_file_lang
*po_file
, *next
;
593 unsigned int count
= 0;
595 LIST_FOR_EACH_ENTRY_SAFE( po_file
, next
, &po_file_langs
, struct po_file_lang
, entry
)
597 char *name
= get_po_file_name( &po_file
->lang
);
600 const char *p
= strrchr( output_name
, '/' );
602 else p
= output_name
;
603 if (!strcmp( p
, name
))
605 po_file_write( po_file
->po
, name
, &po_xerror_handler
);
609 else /* no specified output name, output a file for every language found */
611 po_file_write( po_file
->po
, name
, &po_xerror_handler
);
613 fprintf( stderr
, "created %s\n", name
);
615 po_file_free( po_file
->po
);
616 list_remove( &po_file
->entry
);
623 static void add_pot_stringtable( po_file_t po
, const resource_t
*res
)
625 const stringtable_t
*stt
= res
->res
.stt
;
630 for (i
= 0; i
< stt
->nentries
; i
++)
631 if (stt
->entries
[i
].str
) add_po_string( po
, stt
->entries
[i
].str
, NULL
, NULL
);
636 static void add_po_stringtable( const resource_t
*english
, const resource_t
*res
)
638 const stringtable_t
*english_stt
= english
->res
.stt
;
639 const stringtable_t
*stt
= res
->res
.stt
;
640 po_file_t po
= get_po_file( stt
->lvc
.language
);
643 while (english_stt
&& stt
)
645 for (i
= 0; i
< stt
->nentries
; i
++)
646 if (english_stt
->entries
[i
].str
&& stt
->entries
[i
].str
)
647 add_po_string( po
, english_stt
->entries
[i
].str
, stt
->entries
[i
].str
, stt
->lvc
.language
);
649 english_stt
= english_stt
->next
;
653 static void add_pot_dialog_controls( po_file_t po
, const control_t
*ctrl
)
657 if (control_has_title( ctrl
)) add_po_string( po
, ctrl
->title
->name
.s_name
, NULL
, NULL
);
662 static void add_pot_dialog( po_file_t po
, const resource_t
*res
)
664 const dialog_t
*dlg
= res
->res
.dlg
;
666 if (dlg
->title
) add_po_string( po
, dlg
->title
, NULL
, NULL
);
667 add_pot_dialog_controls( po
, dlg
->controls
);
670 static void compare_dialogs( const dialog_t
*english_dlg
, const dialog_t
*dlg
)
672 const control_t
*english_ctrl
, *ctrl
;
673 unsigned int style
= 0, exstyle
= 0, english_style
= 0, english_exstyle
= 0;
675 char *title
= english_dlg
->title
? convert_msgid_ascii( english_dlg
->title
, 0 ) : xstrdup("??");
677 if (english_dlg
->width
!= dlg
->width
|| english_dlg
->height
!= dlg
->height
)
678 warning( "%s: dialog %s doesn't have the same size (%d,%d vs %d,%d)\n",
679 get_language_name( dlg
->lvc
.language
), title
, dlg
->width
, dlg
->height
,
680 english_dlg
->width
, english_dlg
->height
);
682 if (dlg
->gotstyle
) style
= dlg
->style
->or_mask
;
683 if (dlg
->gotexstyle
) exstyle
= dlg
->exstyle
->or_mask
;
684 if (english_dlg
->gotstyle
) english_style
= english_dlg
->style
->or_mask
;
685 if (english_dlg
->gotexstyle
) english_exstyle
= english_dlg
->exstyle
->or_mask
;
686 if (is_rtl_language( dlg
->lvc
.language
)) english_exstyle
|= WS_EX_LAYOUTRTL
;
688 if (english_style
!= style
)
689 warning( "%s: dialog %s doesn't have the same style (%08x vs %08x)\n",
690 get_language_name( dlg
->lvc
.language
), title
, style
, english_style
);
691 if (english_exstyle
!= exstyle
)
692 warning( "%s: dialog %s doesn't have the same exstyle (%08x vs %08x)\n",
693 get_language_name( dlg
->lvc
.language
), title
, exstyle
, english_exstyle
);
695 if (english_dlg
->font
|| dlg
->font
)
697 int size
= 0, english_size
= 0;
698 char *font
= NULL
, *english_font
= NULL
;
700 if (english_dlg
->font
)
702 english_font
= convert_msgid_ascii( english_dlg
->font
->name
, 0 );
703 english_size
= english_dlg
->font
->size
;
707 font
= convert_msgid_ascii( dlg
->font
->name
, 0 );
708 size
= dlg
->font
->size
;
710 if (uses_larger_font( dlg
->lvc
.language
)) english_size
++;
712 if (!english_font
|| !font
|| strcasecmp( english_font
, font
) || english_size
!= size
)
713 warning( "%s: dialog %s doesn't have the same font (%s %u vs %s %u)\n",
714 get_language_name(dlg
->lvc
.language
), title
,
715 english_font
? english_font
: "default", english_size
,
716 font
? font
: "default", size
);
718 free( english_font
);
720 english_ctrl
= english_dlg
->controls
;
721 ctrl
= dlg
->controls
;
722 for ( ; english_ctrl
&& ctrl
; ctrl
= ctrl
->next
, english_ctrl
= english_ctrl
->next
)
724 if (control_has_title( english_ctrl
))
725 name
= convert_msgid_ascii( english_ctrl
->title
->name
.s_name
, 0 );
727 name
= strmake( "%d", ctrl
->id
);
729 if (english_ctrl
->width
!= ctrl
->width
|| english_ctrl
->height
!= ctrl
->height
)
730 warning( "%s: dialog %s control %s doesn't have the same size (%d,%d vs %d,%d)\n",
731 get_language_name( dlg
->lvc
.language
), title
, name
,
732 ctrl
->width
, ctrl
->height
, english_ctrl
->width
, english_ctrl
->height
);
733 if (english_ctrl
->x
!= ctrl
->x
|| english_ctrl
->y
!= ctrl
->y
)
734 warning( "%s: dialog %s control %s doesn't have the same position (%d,%d vs %d,%d)\n",
735 get_language_name( dlg
->lvc
.language
), title
, name
,
736 ctrl
->x
, ctrl
->y
, english_ctrl
->x
, english_ctrl
->y
);
742 static void add_po_dialog_controls( po_file_t po
, const control_t
*english_ctrl
,
743 const control_t
*ctrl
, const language_t
*lang
)
745 while (english_ctrl
&& ctrl
)
747 if (control_has_title( english_ctrl
) && control_has_title( ctrl
))
748 add_po_string( po
, english_ctrl
->title
->name
.s_name
, ctrl
->title
->name
.s_name
, lang
);
751 english_ctrl
= english_ctrl
->next
;
755 static void add_po_dialog( const resource_t
*english
, const resource_t
*res
)
757 const dialog_t
*english_dlg
= english
->res
.dlg
;
758 const dialog_t
*dlg
= res
->res
.dlg
;
759 po_file_t po
= get_po_file( dlg
->lvc
.language
);
761 compare_dialogs( english_dlg
, dlg
);
763 if (english_dlg
->title
&& dlg
->title
)
764 add_po_string( po
, english_dlg
->title
, dlg
->title
, dlg
->lvc
.language
);
765 add_po_dialog_controls( po
, english_dlg
->controls
, dlg
->controls
, dlg
->lvc
.language
);
768 static void add_pot_menu_items( po_file_t po
, const menu_item_t
*item
)
772 if (item
->name
) add_po_string( po
, item
->name
, NULL
, NULL
);
773 if (item
->popup
) add_pot_menu_items( po
, item
->popup
);
778 static void add_pot_menu( po_file_t po
, const resource_t
*res
)
780 add_pot_menu_items( po
, res
->res
.men
->items
);
783 static void add_po_menu_items( po_file_t po
, const menu_item_t
*english_item
,
784 const menu_item_t
*item
, const language_t
*lang
)
786 while (english_item
&& item
)
788 if (english_item
->name
&& item
->name
)
789 add_po_string( po
, english_item
->name
, item
->name
, lang
);
790 if (english_item
->popup
&& item
->popup
)
791 add_po_menu_items( po
, english_item
->popup
, item
->popup
, lang
);
793 english_item
= english_item
->next
;
797 static void add_po_menu( const resource_t
*english
, const resource_t
*res
)
799 const menu_item_t
*english_items
= english
->res
.men
->items
;
800 const menu_item_t
*items
= res
->res
.men
->items
;
801 po_file_t po
= get_po_file( res
->res
.men
->lvc
.language
);
803 add_po_menu_items( po
, english_items
, items
, res
->res
.men
->lvc
.language
);
806 static resource_t
*find_english_resource( resource_t
*res
)
810 for (ptr
= resource_top
; ptr
; ptr
= ptr
->next
)
812 if (ptr
->type
!= res
->type
) continue;
813 if (!ptr
->lan
) continue;
814 if (!is_english( ptr
->lan
)) continue;
815 if (compare_name_id( ptr
->name
, res
->name
)) continue;
821 void write_pot_file( const char *outname
)
824 po_file_t po
= create_po_file();
826 for (res
= resource_top
; res
; res
= res
->next
)
828 if (!is_english( res
->lan
)) continue;
832 case res_acc
: break; /* FIXME */
833 case res_dlg
: add_pot_dialog( po
, res
); break;
834 case res_men
: add_pot_menu( po
, res
); break;
835 case res_stt
: add_pot_stringtable( po
, res
); break;
836 case res_msg
: break; /* FIXME */
840 po_file_write( po
, outname
, &po_xerror_handler
);
844 void write_po_files( const char *outname
)
846 resource_t
*res
, *english
;
848 for (res
= resource_top
; res
; res
= res
->next
)
850 if (!(english
= find_english_resource( res
))) continue;
853 case res_acc
: break; /* FIXME */
854 case res_dlg
: add_po_dialog( english
, res
); break;
855 case res_men
: add_po_menu( english
, res
); break;
856 case res_stt
: add_po_stringtable( english
, res
); break;
857 case res_msg
: break; /* FIXME */
861 if (!flush_po_files( outname
))
863 if (outname
) error( "No translations found for %s\n", outname
);
864 else error( "No translations found\n" );
868 #endif /* HAVE_LIBGETTEXTPO */
870 static struct mo_file
*mo_file
;
872 static void byteswap( unsigned int *data
, unsigned int count
)
876 for (i
= 0; i
< count
; i
++)
877 data
[i
] = data
[i
] >> 24 | (data
[i
] >> 8 & 0xff00) | (data
[i
] << 8 & 0xff0000) | data
[i
] << 24;
880 static void load_mo_file( const char *name
)
885 fd
= open( name
, O_RDONLY
| O_BINARY
);
886 if (fd
== -1) fatal_perror( "Failed to open %s", name
);
888 mo_file
= xmalloc( st
.st_size
);
889 res
= read( fd
, mo_file
, st
.st_size
);
890 if (res
== -1) fatal_perror( "Failed to read %s", name
);
891 else if (res
!= st
.st_size
) error( "Failed to read %s\n", name
);
896 if (st
.st_size
< sizeof(*mo_file
))
897 error( "%s is not a valid .mo file\n", name
);
898 if (mo_file
->magic
== 0xde120495)
899 byteswap( &mo_file
->revision
, 4 );
900 else if (mo_file
->magic
!= 0x950412de)
901 error( "%s is not a valid .mo file\n", name
);
902 if ((mo_file
->revision
>> 16) > 1)
903 error( "%s: unsupported file version %x\n", name
, mo_file
->revision
);
904 if (mo_file
->msgid_off
>= st
.st_size
||
905 mo_file
->msgstr_off
>= st
.st_size
||
906 st
.st_size
< sizeof(*mo_file
) + 2 * 8 * mo_file
->count
)
907 error( "%s: corrupted file\n", name
);
909 if (mo_file
->magic
== 0xde120495)
911 byteswap( (unsigned int *)((char *)mo_file
+ mo_file
->msgid_off
), 2 * mo_file
->count
);
912 byteswap( (unsigned int *)((char *)mo_file
+ mo_file
->msgstr_off
), 2 * mo_file
->count
);
916 static void free_mo_file(void)
922 static inline const char *get_mo_msgid( int index
)
924 const char *base
= (const char *)mo_file
;
925 const unsigned int *offsets
= (const unsigned int *)(base
+ mo_file
->msgid_off
);
926 return base
+ offsets
[2 * index
+ 1];
929 static inline const char *get_mo_msgstr( int index
)
931 const char *base
= (const char *)mo_file
;
932 const unsigned int *offsets
= (const unsigned int *)(base
+ mo_file
->msgstr_off
);
933 return base
+ offsets
[2 * index
+ 1];
936 static const char *get_msgstr( const char *msgid
, const char *context
, int *found
)
938 int pos
, res
, min
, max
;
939 const char *ret
= msgid
;
942 if (!mo_file
) /* strings containing a context still need to be transformed */
944 if (context
) (*found
)++;
948 if (context
) id
= strmake( "%s%c%s", context
, 4, msgid
);
950 max
= mo_file
->count
- 1;
953 pos
= (min
+ max
) / 2;
954 res
= strcmp( get_mo_msgid(pos
), msgid
);
957 const char *str
= get_mo_msgstr( pos
);
958 if (str
[0]) /* ignore empty strings */
965 if (res
> 0) max
= pos
- 1;
972 static string_t
*translate_string( string_t
*str
, int *found
)
977 char *buffer
, *msgid
, *context
;
979 if (!str
->size
|| !(buffer
= convert_msgid_ascii( str
, 0 )))
980 return convert_string( str
, str_unicode
, 1252 );
983 context
= get_message_context( &msgid
);
984 transl
= get_msgstr( msgid
, context
, found
);
986 new = xmalloc( sizeof(*new) );
987 new->type
= str_unicode
;
988 new->size
= wine_utf8_mbstowcs( 0, transl
, strlen(transl
), NULL
, 0 );
989 new->str
.wstr
= xmalloc( (new->size
+1) * sizeof(WCHAR
) );
990 res
= wine_utf8_mbstowcs( MB_ERR_INVALID_CHARS
, transl
, strlen(transl
), new->str
.wstr
, new->size
);
992 error( "Invalid utf-8 character in string '%s'\n", transl
);
993 new->str
.wstr
[new->size
] = 0;
998 static control_t
*translate_controls( control_t
*ctrl
, int *found
)
1000 control_t
*new, *head
= NULL
, *tail
= NULL
;
1004 new = xmalloc( sizeof(*new) );
1006 if (control_has_title( ctrl
))
1008 new->title
= new_name_id();
1009 *new->title
= *ctrl
->title
;
1010 new->title
->name
.s_name
= translate_string( ctrl
->title
->name
.s_name
, found
);
1012 else new->title
= dup_name_id( ctrl
->title
);
1013 new->ctlclass
= dup_name_id( ctrl
->ctlclass
);
1014 if (tail
) tail
->next
= new;
1024 static menu_item_t
*translate_items( menu_item_t
*item
, int *found
)
1026 menu_item_t
*new, *head
= NULL
, *tail
= NULL
;
1030 new = xmalloc( sizeof(*new) );
1032 if (item
->name
) new->name
= translate_string( item
->name
, found
);
1033 if (item
->popup
) new->popup
= translate_items( item
->popup
, found
);
1034 if (tail
) tail
->next
= new;
1044 static stringtable_t
*translate_stringtable( stringtable_t
*stt
, language_t
*lang
, int *found
)
1046 stringtable_t
*new, *head
= NULL
, *tail
= NULL
;
1051 new = xmalloc( sizeof(*new) );
1053 new->lvc
.language
= lang
;
1054 new->lvc
.version
= get_dup_version( lang
);
1055 new->entries
= xmalloc( new->nentries
* sizeof(*new->entries
) );
1056 memcpy( new->entries
, stt
->entries
, new->nentries
* sizeof(*new->entries
) );
1057 for (i
= 0; i
< stt
->nentries
; i
++)
1058 if (stt
->entries
[i
].str
)
1059 new->entries
[i
].str
= translate_string( stt
->entries
[i
].str
, found
);
1061 if (tail
) tail
->next
= new;
1071 static void translate_dialog( dialog_t
*dlg
, dialog_t
*new, int *found
)
1073 if (dlg
->title
) new->title
= translate_string( dlg
->title
, found
);
1074 if (is_rtl_language( new->lvc
.language
))
1076 new->gotexstyle
= TRUE
;
1077 if (dlg
->gotexstyle
)
1078 new->exstyle
= new_style( dlg
->exstyle
->or_mask
| WS_EX_LAYOUTRTL
, dlg
->exstyle
->and_mask
);
1080 new->exstyle
= new_style( WS_EX_LAYOUTRTL
, 0 );
1084 new->font
= xmalloc( sizeof(*dlg
->font
) );
1085 *new->font
= *dlg
->font
;
1086 if (uses_larger_font( new->lvc
.language
)) new->font
->size
++;
1087 new->font
->name
= convert_string( dlg
->font
->name
, str_unicode
, 1252 );
1089 new->controls
= translate_controls( dlg
->controls
, found
);
1092 static void translate_resources( language_t
*lang
)
1096 for (res
= resource_top
; res
; res
= res
->next
)
1098 resource_t
*new = NULL
;
1101 if (!is_english( res
->lan
)) continue;
1109 new = dup_resource( res
, lang
);
1110 translate_dialog( res
->res
.dlg
, new->res
.dlg
, &found
);
1113 new = dup_resource( res
, lang
);
1114 new->res
.men
->items
= translate_items( res
->res
.men
->items
, &found
);
1117 new = dup_resource( res
, lang
);
1118 new->res
.stt
= translate_stringtable( res
->res
.stt
, lang
, &found
);
1129 if (new_tail
) new_tail
->next
= new;
1131 new->prev
= new_tail
;
1137 void add_translations( const char *po_dir
)
1141 char *p
, *tok
, *name
;
1145 /* first check if we have English resources to translate */
1146 for (res
= resource_top
; res
; res
= res
->next
) if (is_english( res
->lan
)) break;
1149 if (!po_dir
) /* run through the translation process to remove msg contexts */
1151 translate_resources( new_language( LANG_ENGLISH
, SUBLANG_DEFAULT
));
1155 new_top
= new_tail
= NULL
;
1157 name
= strmake( "%s/LINGUAS", po_dir
);
1158 if (!(f
= fopen( name
, "r" )))
1164 while (fgets( buffer
, sizeof(buffer
), f
))
1166 if ((p
= strchr( buffer
, '#' ))) *p
= 0;
1167 for (tok
= strtok( buffer
, " \t\r\n" ); tok
; tok
= strtok( NULL
, " \t\r\n" ))
1169 for (i
= 0; i
< sizeof(languages
)/sizeof(languages
[0]); i
++)
1170 if (!strcmp( tok
, languages
[i
].name
)) break;
1172 if (i
== sizeof(languages
)/sizeof(languages
[0]))
1173 error( "unknown language '%s'\n", tok
);
1175 name
= strmake( "%s/%s.mo", po_dir
, tok
);
1176 load_mo_file( name
);
1177 translate_resources( new_language(languages
[i
].id
, languages
[i
].sub
) );
1185 /* prepend the translated resources to the global list */
1188 new_tail
->next
= resource_top
;
1189 resource_top
->prev
= new_tail
;
1190 resource_top
= new_top
;