2008-01-15 Marcus Brinkmann <marcus@g10code.de>
[gnupg.git] / common / localename.c
blobf2429068ad87a43131b47e9731b4a2147160cecd
1 /* localename.c - Determine the current selected locale.
2 Copyright (C) 1995-1999, 2000-2003, 2007 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public License
6 as published by the Free Software Foundation; either version 2.1,
7 or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, see <http://www.gnu.org/licenses/>.
17 /* Written by Ulrich Drepper <drepper@gnu.org>, 1995. */
18 /* Win32 code written by Tor Lillqvist <tml@iki.fi>. */
19 /* Modified for GpgOL use by Werner Koch <wk@gnupg.org>, 2005. */
20 /* Modified for GnuPG use by Werner Koch <wk@gnupg.org>, 2007 */
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
26 #include <stdlib.h>
27 #include <string.h>
28 #ifdef HAVE_LOCALE_H
29 #include <locale.h>
30 #endif
32 #ifdef HAVE_W32_SYSTEM
33 # include <windows.h>
34 /* Mingw headers don't have latest language and sublanguage codes. */
35 # ifndef LANG_AFRIKAANS
36 # define LANG_AFRIKAANS 0x36
37 # endif
38 # ifndef LANG_ALBANIAN
39 # define LANG_ALBANIAN 0x1c
40 # endif
41 # ifndef LANG_AMHARIC
42 # define LANG_AMHARIC 0x5e
43 # endif
44 # ifndef LANG_ARABIC
45 # define LANG_ARABIC 0x01
46 # endif
47 # ifndef LANG_ARMENIAN
48 # define LANG_ARMENIAN 0x2b
49 # endif
50 # ifndef LANG_ASSAMESE
51 # define LANG_ASSAMESE 0x4d
52 # endif
53 # ifndef LANG_AZERI
54 # define LANG_AZERI 0x2c
55 # endif
56 # ifndef LANG_BASQUE
57 # define LANG_BASQUE 0x2d
58 # endif
59 # ifndef LANG_BELARUSIAN
60 # define LANG_BELARUSIAN 0x23
61 # endif
62 # ifndef LANG_BENGALI
63 # define LANG_BENGALI 0x45
64 # endif
65 # ifndef LANG_BURMESE
66 # define LANG_BURMESE 0x55
67 # endif
68 # ifndef LANG_CAMBODIAN
69 # define LANG_CAMBODIAN 0x53
70 # endif
71 # ifndef LANG_CATALAN
72 # define LANG_CATALAN 0x03
73 # endif
74 # ifndef LANG_CHEROKEE
75 # define LANG_CHEROKEE 0x5c
76 # endif
77 # ifndef LANG_DIVEHI
78 # define LANG_DIVEHI 0x65
79 # endif
80 # ifndef LANG_EDO
81 # define LANG_EDO 0x66
82 # endif
83 # ifndef LANG_ESTONIAN
84 # define LANG_ESTONIAN 0x25
85 # endif
86 # ifndef LANG_FAEROESE
87 # define LANG_FAEROESE 0x38
88 # endif
89 # ifndef LANG_FARSI
90 # define LANG_FARSI 0x29
91 # endif
92 # ifndef LANG_FRISIAN
93 # define LANG_FRISIAN 0x62
94 # endif
95 # ifndef LANG_FULFULDE
96 # define LANG_FULFULDE 0x67
97 # endif
98 # ifndef LANG_GAELIC
99 # define LANG_GAELIC 0x3c
100 # endif
101 # ifndef LANG_GALICIAN
102 # define LANG_GALICIAN 0x56
103 # endif
104 # ifndef LANG_GEORGIAN
105 # define LANG_GEORGIAN 0x37
106 # endif
107 # ifndef LANG_GUARANI
108 # define LANG_GUARANI 0x74
109 # endif
110 # ifndef LANG_GUJARATI
111 # define LANG_GUJARATI 0x47
112 # endif
113 # ifndef LANG_HAUSA
114 # define LANG_HAUSA 0x68
115 # endif
116 # ifndef LANG_HAWAIIAN
117 # define LANG_HAWAIIAN 0x75
118 # endif
119 # ifndef LANG_HEBREW
120 # define LANG_HEBREW 0x0d
121 # endif
122 # ifndef LANG_HINDI
123 # define LANG_HINDI 0x39
124 # endif
125 # ifndef LANG_IBIBIO
126 # define LANG_IBIBIO 0x69
127 # endif
128 # ifndef LANG_IGBO
129 # define LANG_IGBO 0x70
130 # endif
131 # ifndef LANG_INDONESIAN
132 # define LANG_INDONESIAN 0x21
133 # endif
134 # ifndef LANG_INUKTITUT
135 # define LANG_INUKTITUT 0x5d
136 # endif
137 # ifndef LANG_KANNADA
138 # define LANG_KANNADA 0x4b
139 # endif
140 # ifndef LANG_KANURI
141 # define LANG_KANURI 0x71
142 # endif
143 # ifndef LANG_KASHMIRI
144 # define LANG_KASHMIRI 0x60
145 # endif
146 # ifndef LANG_KAZAK
147 # define LANG_KAZAK 0x3f
148 # endif
149 # ifndef LANG_KONKANI
150 # define LANG_KONKANI 0x57
151 # endif
152 # ifndef LANG_KYRGYZ
153 # define LANG_KYRGYZ 0x40
154 # endif
155 # ifndef LANG_LAO
156 # define LANG_LAO 0x54
157 # endif
158 # ifndef LANG_LATIN
159 # define LANG_LATIN 0x76
160 # endif
161 # ifndef LANG_LATVIAN
162 # define LANG_LATVIAN 0x26
163 # endif
164 # ifndef LANG_LITHUANIAN
165 # define LANG_LITHUANIAN 0x27
166 # endif
167 # ifndef LANG_MACEDONIAN
168 # define LANG_MACEDONIAN 0x2f
169 # endif
170 # ifndef LANG_MALAY
171 # define LANG_MALAY 0x3e
172 # endif
173 # ifndef LANG_MALAYALAM
174 # define LANG_MALAYALAM 0x4c
175 # endif
176 # ifndef LANG_MALTESE
177 # define LANG_MALTESE 0x3a
178 # endif
179 # ifndef LANG_MANIPURI
180 # define LANG_MANIPURI 0x58
181 # endif
182 # ifndef LANG_MARATHI
183 # define LANG_MARATHI 0x4e
184 # endif
185 # ifndef LANG_MONGOLIAN
186 # define LANG_MONGOLIAN 0x50
187 # endif
188 # ifndef LANG_NEPALI
189 # define LANG_NEPALI 0x61
190 # endif
191 # ifndef LANG_ORIYA
192 # define LANG_ORIYA 0x48
193 # endif
194 # ifndef LANG_OROMO
195 # define LANG_OROMO 0x72
196 # endif
197 # ifndef LANG_PAPIAMENTU
198 # define LANG_PAPIAMENTU 0x79
199 # endif
200 # ifndef LANG_PASHTO
201 # define LANG_PASHTO 0x63
202 # endif
203 # ifndef LANG_PUNJABI
204 # define LANG_PUNJABI 0x46
205 # endif
206 # ifndef LANG_RHAETO_ROMANCE
207 # define LANG_RHAETO_ROMANCE 0x17
208 # endif
209 # ifndef LANG_SAAMI
210 # define LANG_SAAMI 0x3b
211 # endif
212 # ifndef LANG_SANSKRIT
213 # define LANG_SANSKRIT 0x4f
214 # endif
215 # ifndef LANG_SERBIAN
216 # define LANG_SERBIAN 0x1a
217 # endif
218 # ifndef LANG_SINDHI
219 # define LANG_SINDHI 0x59
220 # endif
221 # ifndef LANG_SINHALESE
222 # define LANG_SINHALESE 0x5b
223 # endif
224 # ifndef LANG_SLOVAK
225 # define LANG_SLOVAK 0x1b
226 # endif
227 # ifndef LANG_SOMALI
228 # define LANG_SOMALI 0x77
229 # endif
230 # ifndef LANG_SORBIAN
231 # define LANG_SORBIAN 0x2e
232 # endif
233 # ifndef LANG_SUTU
234 # define LANG_SUTU 0x30
235 # endif
236 # ifndef LANG_SWAHILI
237 # define LANG_SWAHILI 0x41
238 # endif
239 # ifndef LANG_SYRIAC
240 # define LANG_SYRIAC 0x5a
241 # endif
242 # ifndef LANG_TAGALOG
243 # define LANG_TAGALOG 0x64
244 # endif
245 # ifndef LANG_TAJIK
246 # define LANG_TAJIK 0x28
247 # endif
248 # ifndef LANG_TAMAZIGHT
249 # define LANG_TAMAZIGHT 0x5f
250 # endif
251 # ifndef LANG_TAMIL
252 # define LANG_TAMIL 0x49
253 # endif
254 # ifndef LANG_TATAR
255 # define LANG_TATAR 0x44
256 # endif
257 # ifndef LANG_TELUGU
258 # define LANG_TELUGU 0x4a
259 # endif
260 # ifndef LANG_THAI
261 # define LANG_THAI 0x1e
262 # endif
263 # ifndef LANG_TIBETAN
264 # define LANG_TIBETAN 0x51
265 # endif
266 # ifndef LANG_TIGRINYA
267 # define LANG_TIGRINYA 0x73
268 # endif
269 # ifndef LANG_TSONGA
270 # define LANG_TSONGA 0x31
271 # endif
272 # ifndef LANG_TSWANA
273 # define LANG_TSWANA 0x32
274 # endif
275 # ifndef LANG_TURKMEN
276 # define LANG_TURKMEN 0x42
277 # endif
278 # ifndef LANG_UKRAINIAN
279 # define LANG_UKRAINIAN 0x22
280 # endif
281 # ifndef LANG_URDU
282 # define LANG_URDU 0x20
283 # endif
284 # ifndef LANG_UZBEK
285 # define LANG_UZBEK 0x43
286 # endif
287 # ifndef LANG_VENDA
288 # define LANG_VENDA 0x33
289 # endif
290 # ifndef LANG_VIETNAMESE
291 # define LANG_VIETNAMESE 0x2a
292 # endif
293 # ifndef LANG_WELSH
294 # define LANG_WELSH 0x52
295 # endif
296 # ifndef LANG_XHOSA
297 # define LANG_XHOSA 0x34
298 # endif
299 # ifndef LANG_YI
300 # define LANG_YI 0x78
301 # endif
302 # ifndef LANG_YIDDISH
303 # define LANG_YIDDISH 0x3d
304 # endif
305 # ifndef LANG_YORUBA
306 # define LANG_YORUBA 0x6a
307 # endif
308 # ifndef LANG_ZULU
309 # define LANG_ZULU 0x35
310 # endif
311 # ifndef SUBLANG_ARABIC_SAUDI_ARABIA
312 # define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
313 # endif
314 # ifndef SUBLANG_ARABIC_IRAQ
315 # define SUBLANG_ARABIC_IRAQ 0x02
316 # endif
317 # ifndef SUBLANG_ARABIC_EGYPT
318 # define SUBLANG_ARABIC_EGYPT 0x03
319 # endif
320 # ifndef SUBLANG_ARABIC_LIBYA
321 # define SUBLANG_ARABIC_LIBYA 0x04
322 # endif
323 # ifndef SUBLANG_ARABIC_ALGERIA
324 # define SUBLANG_ARABIC_ALGERIA 0x05
325 # endif
326 # ifndef SUBLANG_ARABIC_MOROCCO
327 # define SUBLANG_ARABIC_MOROCCO 0x06
328 # endif
329 # ifndef SUBLANG_ARABIC_TUNISIA
330 # define SUBLANG_ARABIC_TUNISIA 0x07
331 # endif
332 # ifndef SUBLANG_ARABIC_OMAN
333 # define SUBLANG_ARABIC_OMAN 0x08
334 # endif
335 # ifndef SUBLANG_ARABIC_YEMEN
336 # define SUBLANG_ARABIC_YEMEN 0x09
337 # endif
338 # ifndef SUBLANG_ARABIC_SYRIA
339 # define SUBLANG_ARABIC_SYRIA 0x0a
340 # endif
341 # ifndef SUBLANG_ARABIC_JORDAN
342 # define SUBLANG_ARABIC_JORDAN 0x0b
343 # endif
344 # ifndef SUBLANG_ARABIC_LEBANON
345 # define SUBLANG_ARABIC_LEBANON 0x0c
346 # endif
347 # ifndef SUBLANG_ARABIC_KUWAIT
348 # define SUBLANG_ARABIC_KUWAIT 0x0d
349 # endif
350 # ifndef SUBLANG_ARABIC_UAE
351 # define SUBLANG_ARABIC_UAE 0x0e
352 # endif
353 # ifndef SUBLANG_ARABIC_BAHRAIN
354 # define SUBLANG_ARABIC_BAHRAIN 0x0f
355 # endif
356 # ifndef SUBLANG_ARABIC_QATAR
357 # define SUBLANG_ARABIC_QATAR 0x10
358 # endif
359 # ifndef SUBLANG_AZERI_LATIN
360 # define SUBLANG_AZERI_LATIN 0x01
361 # endif
362 # ifndef SUBLANG_AZERI_CYRILLIC
363 # define SUBLANG_AZERI_CYRILLIC 0x02
364 # endif
365 # ifndef SUBLANG_BENGALI_INDIA
366 # define SUBLANG_BENGALI_INDIA 0x01
367 # endif
368 # ifndef SUBLANG_BENGALI_BANGLADESH
369 # define SUBLANG_BENGALI_BANGLADESH 0x02
370 # endif
371 # ifndef SUBLANG_CHINESE_MACAU
372 # define SUBLANG_CHINESE_MACAU 0x05
373 # endif
374 # ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
375 # define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
376 # endif
377 # ifndef SUBLANG_ENGLISH_JAMAICA
378 # define SUBLANG_ENGLISH_JAMAICA 0x08
379 # endif
380 # ifndef SUBLANG_ENGLISH_CARIBBEAN
381 # define SUBLANG_ENGLISH_CARIBBEAN 0x09
382 # endif
383 # ifndef SUBLANG_ENGLISH_BELIZE
384 # define SUBLANG_ENGLISH_BELIZE 0x0a
385 # endif
386 # ifndef SUBLANG_ENGLISH_TRINIDAD
387 # define SUBLANG_ENGLISH_TRINIDAD 0x0b
388 # endif
389 # ifndef SUBLANG_ENGLISH_ZIMBABWE
390 # define SUBLANG_ENGLISH_ZIMBABWE 0x0c
391 # endif
392 # ifndef SUBLANG_ENGLISH_PHILIPPINES
393 # define SUBLANG_ENGLISH_PHILIPPINES 0x0d
394 # endif
395 # ifndef SUBLANG_ENGLISH_INDONESIA
396 # define SUBLANG_ENGLISH_INDONESIA 0x0e
397 # endif
398 # ifndef SUBLANG_ENGLISH_HONGKONG
399 # define SUBLANG_ENGLISH_HONGKONG 0x0f
400 # endif
401 # ifndef SUBLANG_ENGLISH_INDIA
402 # define SUBLANG_ENGLISH_INDIA 0x10
403 # endif
404 # ifndef SUBLANG_ENGLISH_MALAYSIA
405 # define SUBLANG_ENGLISH_MALAYSIA 0x11
406 # endif
407 # ifndef SUBLANG_ENGLISH_SINGAPORE
408 # define SUBLANG_ENGLISH_SINGAPORE 0x12
409 # endif
410 # ifndef SUBLANG_FRENCH_LUXEMBOURG
411 # define SUBLANG_FRENCH_LUXEMBOURG 0x05
412 # endif
413 # ifndef SUBLANG_FRENCH_MONACO
414 # define SUBLANG_FRENCH_MONACO 0x06
415 # endif
416 # ifndef SUBLANG_FRENCH_WESTINDIES
417 # define SUBLANG_FRENCH_WESTINDIES 0x07
418 # endif
419 # ifndef SUBLANG_FRENCH_REUNION
420 # define SUBLANG_FRENCH_REUNION 0x08
421 # endif
422 # ifndef SUBLANG_FRENCH_CONGO
423 # define SUBLANG_FRENCH_CONGO 0x09
424 # endif
425 # ifndef SUBLANG_FRENCH_SENEGAL
426 # define SUBLANG_FRENCH_SENEGAL 0x0a
427 # endif
428 # ifndef SUBLANG_FRENCH_CAMEROON
429 # define SUBLANG_FRENCH_CAMEROON 0x0b
430 # endif
431 # ifndef SUBLANG_FRENCH_COTEDIVOIRE
432 # define SUBLANG_FRENCH_COTEDIVOIRE 0x0c
433 # endif
434 # ifndef SUBLANG_FRENCH_MALI
435 # define SUBLANG_FRENCH_MALI 0x0d
436 # endif
437 # ifndef SUBLANG_FRENCH_MOROCCO
438 # define SUBLANG_FRENCH_MOROCCO 0x0e
439 # endif
440 # ifndef SUBLANG_FRENCH_HAITI
441 # define SUBLANG_FRENCH_HAITI 0x0f
442 # endif
443 # ifndef SUBLANG_GERMAN_LUXEMBOURG
444 # define SUBLANG_GERMAN_LUXEMBOURG 0x04
445 # endif
446 # ifndef SUBLANG_GERMAN_LIECHTENSTEIN
447 # define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
448 # endif
449 # ifndef SUBLANG_KASHMIRI_INDIA
450 # define SUBLANG_KASHMIRI_INDIA 0x02
451 # endif
452 # ifndef SUBLANG_MALAY_MALAYSIA
453 # define SUBLANG_MALAY_MALAYSIA 0x01
454 # endif
455 # ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
456 # define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
457 # endif
458 # ifndef SUBLANG_NEPALI_INDIA
459 # define SUBLANG_NEPALI_INDIA 0x02
460 # endif
461 # ifndef SUBLANG_PUNJABI_INDIA
462 # define SUBLANG_PUNJABI_INDIA 0x01
463 # endif
464 # ifndef SUBLANG_ROMANIAN_ROMANIA
465 # define SUBLANG_ROMANIAN_ROMANIA 0x01
466 # endif
467 # ifndef SUBLANG_SERBIAN_LATIN
468 # define SUBLANG_SERBIAN_LATIN 0x02
469 # endif
470 # ifndef SUBLANG_SERBIAN_CYRILLIC
471 # define SUBLANG_SERBIAN_CYRILLIC 0x03
472 # endif
473 # ifndef SUBLANG_SINDHI_INDIA
474 # define SUBLANG_SINDHI_INDIA 0x00
475 # endif
476 # ifndef SUBLANG_SINDHI_PAKISTAN
477 # define SUBLANG_SINDHI_PAKISTAN 0x01
478 # endif
479 # ifndef SUBLANG_SPANISH_GUATEMALA
480 # define SUBLANG_SPANISH_GUATEMALA 0x04
481 # endif
482 # ifndef SUBLANG_SPANISH_COSTA_RICA
483 # define SUBLANG_SPANISH_COSTA_RICA 0x05
484 # endif
485 # ifndef SUBLANG_SPANISH_PANAMA
486 # define SUBLANG_SPANISH_PANAMA 0x06
487 # endif
488 # ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
489 # define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
490 # endif
491 # ifndef SUBLANG_SPANISH_VENEZUELA
492 # define SUBLANG_SPANISH_VENEZUELA 0x08
493 # endif
494 # ifndef SUBLANG_SPANISH_COLOMBIA
495 # define SUBLANG_SPANISH_COLOMBIA 0x09
496 # endif
497 # ifndef SUBLANG_SPANISH_PERU
498 # define SUBLANG_SPANISH_PERU 0x0a
499 # endif
500 # ifndef SUBLANG_SPANISH_ARGENTINA
501 # define SUBLANG_SPANISH_ARGENTINA 0x0b
502 # endif
503 # ifndef SUBLANG_SPANISH_ECUADOR
504 # define SUBLANG_SPANISH_ECUADOR 0x0c
505 # endif
506 # ifndef SUBLANG_SPANISH_CHILE
507 # define SUBLANG_SPANISH_CHILE 0x0d
508 # endif
509 # ifndef SUBLANG_SPANISH_URUGUAY
510 # define SUBLANG_SPANISH_URUGUAY 0x0e
511 # endif
512 # ifndef SUBLANG_SPANISH_PARAGUAY
513 # define SUBLANG_SPANISH_PARAGUAY 0x0f
514 # endif
515 # ifndef SUBLANG_SPANISH_BOLIVIA
516 # define SUBLANG_SPANISH_BOLIVIA 0x10
517 # endif
518 # ifndef SUBLANG_SPANISH_EL_SALVADOR
519 # define SUBLANG_SPANISH_EL_SALVADOR 0x11
520 # endif
521 # ifndef SUBLANG_SPANISH_HONDURAS
522 # define SUBLANG_SPANISH_HONDURAS 0x12
523 # endif
524 # ifndef SUBLANG_SPANISH_NICARAGUA
525 # define SUBLANG_SPANISH_NICARAGUA 0x13
526 # endif
527 # ifndef SUBLANG_SPANISH_PUERTO_RICO
528 # define SUBLANG_SPANISH_PUERTO_RICO 0x14
529 # endif
530 # ifndef SUBLANG_SWEDISH_FINLAND
531 # define SUBLANG_SWEDISH_FINLAND 0x02
532 # endif
533 # ifndef SUBLANG_TAMAZIGHT_ARABIC
534 # define SUBLANG_TAMAZIGHT_ARABIC 0x01
535 # endif
536 # ifndef SUBLANG_TAMAZIGHT_LATIN
537 # define SUBLANG_TAMAZIGHT_LATIN 0x02
538 # endif
539 # ifndef SUBLANG_TIGRINYA_ETHIOPIA
540 # define SUBLANG_TIGRINYA_ETHIOPIA 0x00
541 # endif
542 # ifndef SUBLANG_TIGRINYA_ERITREA
543 # define SUBLANG_TIGRINYA_ERITREA 0x01
544 # endif
545 # ifndef SUBLANG_URDU_PAKISTAN
546 # define SUBLANG_URDU_PAKISTAN 0x01
547 # endif
548 # ifndef SUBLANG_URDU_INDIA
549 # define SUBLANG_URDU_INDIA 0x02
550 # endif
551 # ifndef SUBLANG_UZBEK_LATIN
552 # define SUBLANG_UZBEK_LATIN 0x01
553 # endif
554 # ifndef SUBLANG_UZBEK_CYRILLIC
555 # define SUBLANG_UZBEK_CYRILLIC 0x02
556 # endif
557 #endif /* HAVE_W32_SYSTEM */
559 /* XPG3 defines the result of 'setlocale (category, NULL)' as:
560 "Directs 'setlocale()' to query 'category' and return the current
561 setting of 'local'."
562 However it does not specify the exact format. Neither do SUSV2 and
563 ISO C 99. So we can use this feature only on selected systems (e.g.
564 those using GNU C Library). */
565 #if defined _LIBC || (defined __GNU_LIBRARY__ && __GNU_LIBRARY__ >= 2)
566 # define HAVE_LOCALE_NULL
567 #endif
569 /* Use a dummy value for LC_MESSAGES in case it is not defined. This
570 works becuase we always test for HAVE_LC_MESSAGES and the core
571 fucntion takes the category as a string as well. */
572 #ifndef HAVE_LC_MESSAGES
573 #define LC_MESSAGES 0
574 #endif
577 /* Determine the current locale's name, and canonicalize it into XPG syntax
578 language[_territory[.codeset]][@modifier]
579 The codeset part in the result is not reliable; the locale_charset()
580 should be used for codeset information instead.
581 The result must not be freed; it is statically allocated. */
583 static const char *
584 do_nl_locale_name (int category, const char *categoryname)
586 const char *retval;
588 #ifndef HAVE_W32_SYSTEM
590 /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
591 On some systems this can be done by the 'setlocale' function itself. */
592 # if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
593 retval = setlocale (category, NULL);
594 # else
595 /* Setting of LC_ALL overwrites all other. */
596 retval = getenv ("LC_ALL");
597 if (retval == NULL || retval[0] == '\0')
599 /* Next comes the name of the desired category. */
600 retval = getenv (categoryname);
601 if (retval == NULL || retval[0] == '\0')
603 /* Last possibility is the LANG environment variable. */
604 retval = getenv ("LANG");
605 if (retval == NULL || retval[0] == '\0')
606 /* We use C as the default domain. POSIX says this is
607 implementation defined. */
608 retval = "C";
611 # endif
613 return retval;
615 #else /* HAVE_W32_SYSTEM */
617 /* Return an XPG style locale name language[_territory][@modifier].
618 Don't even bother determining the codeset; it's not useful in this
619 context, because message catalogs are not specific to a single
620 codeset. */
622 LCID lcid;
623 LANGID langid;
624 int primary, sub;
626 /* Let the user override the system settings through environment
627 variables, as on POSIX systems. */
628 retval = getenv ("LC_ALL");
629 if (retval != NULL && retval[0] != '\0')
630 return retval;
631 retval = getenv (categoryname);
632 if (retval != NULL && retval[0] != '\0')
633 return retval;
634 retval = getenv ("LANG");
635 if (retval != NULL && retval[0] != '\0')
636 return retval;
638 /* Use native Win32 API locale ID. */
639 lcid = GetThreadLocale ();
641 /* Strip off the sorting rules, keep only the language part. */
642 langid = LANGIDFROMLCID (lcid);
644 /* Split into language and territory part. */
645 primary = PRIMARYLANGID (langid);
646 sub = SUBLANGID (langid);
648 /* Dispatch on language.
649 See also http://www.unicode.org/unicode/onlinedat/languages.html .
650 For details about languages, see http://www.ethnologue.com/ . */
651 switch (primary)
653 case LANG_AFRIKAANS: return "af_ZA";
654 case LANG_ALBANIAN: return "sq_AL";
655 case LANG_AMHARIC: return "am_ET";
656 case LANG_ARABIC:
657 switch (sub)
659 case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA";
660 case SUBLANG_ARABIC_IRAQ: return "ar_IQ";
661 case SUBLANG_ARABIC_EGYPT: return "ar_EG";
662 case SUBLANG_ARABIC_LIBYA: return "ar_LY";
663 case SUBLANG_ARABIC_ALGERIA: return "ar_DZ";
664 case SUBLANG_ARABIC_MOROCCO: return "ar_MA";
665 case SUBLANG_ARABIC_TUNISIA: return "ar_TN";
666 case SUBLANG_ARABIC_OMAN: return "ar_OM";
667 case SUBLANG_ARABIC_YEMEN: return "ar_YE";
668 case SUBLANG_ARABIC_SYRIA: return "ar_SY";
669 case SUBLANG_ARABIC_JORDAN: return "ar_JO";
670 case SUBLANG_ARABIC_LEBANON: return "ar_LB";
671 case SUBLANG_ARABIC_KUWAIT: return "ar_KW";
672 case SUBLANG_ARABIC_UAE: return "ar_AE";
673 case SUBLANG_ARABIC_BAHRAIN: return "ar_BH";
674 case SUBLANG_ARABIC_QATAR: return "ar_QA";
676 return "ar";
677 case LANG_ARMENIAN: return "hy_AM";
678 case LANG_ASSAMESE: return "as_IN";
679 case LANG_AZERI:
680 switch (sub)
682 /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */
683 case SUBLANG_AZERI_LATIN: return "az_AZ@latin";
684 case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic";
686 return "az";
687 case LANG_BASQUE:
688 return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */
689 case LANG_BELARUSIAN: return "be_BY";
690 case LANG_BENGALI:
691 switch (sub)
693 case SUBLANG_BENGALI_INDIA: return "bn_IN";
694 case SUBLANG_BENGALI_BANGLADESH: return "bn_BD";
696 return "bn";
697 case LANG_BULGARIAN: return "bg_BG";
698 case LANG_BURMESE: return "my_MM";
699 case LANG_CAMBODIAN: return "km_KH";
700 case LANG_CATALAN: return "ca_ES";
701 case LANG_CHEROKEE: return "chr_US";
702 case LANG_CHINESE:
703 switch (sub)
705 case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW";
706 case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN";
707 case SUBLANG_CHINESE_HONGKONG: return "zh_HK";
708 case SUBLANG_CHINESE_SINGAPORE: return "zh_SG";
709 case SUBLANG_CHINESE_MACAU: return "zh_MO";
711 return "zh";
712 case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN
713 * What used to be called Serbo-Croatian
714 * should really now be two separate
715 * languages because of political reasons.
716 * (Says tml, who knows nothing about Serbian
717 * or Croatian.)
718 * (I can feel those flames coming already.)
720 switch (sub)
722 case SUBLANG_DEFAULT: return "hr_HR";
723 case SUBLANG_SERBIAN_LATIN: return "sr_CS";
724 case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic";
726 return "hr";
727 case LANG_CZECH: return "cs_CZ";
728 case LANG_DANISH: return "da_DK";
729 case LANG_DIVEHI: return "div_MV";
730 case LANG_DUTCH:
731 switch (sub)
733 case SUBLANG_DUTCH: return "nl_NL";
734 case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE";
736 return "nl";
737 case LANG_EDO: return "bin_NG";
738 case LANG_ENGLISH:
739 switch (sub)
741 /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought
742 * English was the language spoken in England.
743 * Oh well.
745 case SUBLANG_ENGLISH_US: return "en_US";
746 case SUBLANG_ENGLISH_UK: return "en_GB";
747 case SUBLANG_ENGLISH_AUS: return "en_AU";
748 case SUBLANG_ENGLISH_CAN: return "en_CA";
749 case SUBLANG_ENGLISH_NZ: return "en_NZ";
750 case SUBLANG_ENGLISH_EIRE: return "en_IE";
751 case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA";
752 case SUBLANG_ENGLISH_JAMAICA: return "en_JM";
753 case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */
754 case SUBLANG_ENGLISH_BELIZE: return "en_BZ";
755 case SUBLANG_ENGLISH_TRINIDAD: return "en_TT";
756 case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW";
757 case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH";
758 case SUBLANG_ENGLISH_INDONESIA: return "en_ID";
759 case SUBLANG_ENGLISH_HONGKONG: return "en_HK";
760 case SUBLANG_ENGLISH_INDIA: return "en_IN";
761 case SUBLANG_ENGLISH_MALAYSIA: return "en_MY";
762 case SUBLANG_ENGLISH_SINGAPORE: return "en_SG";
764 return "en";
765 case LANG_ESTONIAN: return "et_EE";
766 case LANG_FAEROESE: return "fo_FO";
767 case LANG_FARSI: return "fa_IR";
768 case LANG_FINNISH: return "fi_FI";
769 case LANG_FRENCH:
770 switch (sub)
772 case SUBLANG_FRENCH: return "fr_FR";
773 case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE";
774 case SUBLANG_FRENCH_CANADIAN: return "fr_CA";
775 case SUBLANG_FRENCH_SWISS: return "fr_CH";
776 case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU";
777 case SUBLANG_FRENCH_MONACO: return "fr_MC";
778 case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */
779 case SUBLANG_FRENCH_REUNION: return "fr_RE";
780 case SUBLANG_FRENCH_CONGO: return "fr_CG";
781 case SUBLANG_FRENCH_SENEGAL: return "fr_SN";
782 case SUBLANG_FRENCH_CAMEROON: return "fr_CM";
783 case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI";
784 case SUBLANG_FRENCH_MALI: return "fr_ML";
785 case SUBLANG_FRENCH_MOROCCO: return "fr_MA";
786 case SUBLANG_FRENCH_HAITI: return "fr_HT";
788 return "fr";
789 case LANG_FRISIAN: return "fy_NL";
790 case LANG_FULFULDE: return "ful_NG";
791 case LANG_GAELIC:
792 switch (sub)
794 case 0x01: /* SCOTTISH */ return "gd_GB";
795 case 0x02: /* IRISH */ return "ga_IE";
797 return "C";
798 case LANG_GALICIAN: return "gl_ES";
799 case LANG_GEORGIAN: return "ka_GE";
800 case LANG_GERMAN:
801 switch (sub)
803 case SUBLANG_GERMAN: return "de_DE";
804 case SUBLANG_GERMAN_SWISS: return "de_CH";
805 case SUBLANG_GERMAN_AUSTRIAN: return "de_AT";
806 case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU";
807 case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI";
809 return "de";
810 case LANG_GREEK: return "el_GR";
811 case LANG_GUARANI: return "gn_PY";
812 case LANG_GUJARATI: return "gu_IN";
813 case LANG_HAUSA: return "ha_NG";
814 case LANG_HAWAIIAN:
815 /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers)
816 or Hawaii Creole English ("cpe_US", 600000 speakers)? */
817 return "cpe_US";
818 case LANG_HEBREW: return "he_IL";
819 case LANG_HINDI: return "hi_IN";
820 case LANG_HUNGARIAN: return "hu_HU";
821 case LANG_IBIBIO: return "nic_NG";
822 case LANG_ICELANDIC: return "is_IS";
823 case LANG_IGBO: return "ibo_NG";
824 case LANG_INDONESIAN: return "id_ID";
825 case LANG_INUKTITUT: return "iu_CA";
826 case LANG_ITALIAN:
827 switch (sub)
829 case SUBLANG_ITALIAN: return "it_IT";
830 case SUBLANG_ITALIAN_SWISS: return "it_CH";
832 return "it";
833 case LANG_JAPANESE: return "ja_JP";
834 case LANG_KANNADA: return "kn_IN";
835 case LANG_KANURI: return "kau_NG";
836 case LANG_KASHMIRI:
837 switch (sub)
839 case SUBLANG_DEFAULT: return "ks_PK";
840 case SUBLANG_KASHMIRI_INDIA: return "ks_IN";
842 return "ks";
843 case LANG_KAZAK: return "kk_KZ";
844 case LANG_KONKANI:
845 /* FIXME: Adjust this when such locales appear on Unix. */
846 return "kok_IN";
847 case LANG_KOREAN: return "ko_KR";
848 case LANG_KYRGYZ: return "ky_KG";
849 case LANG_LAO: return "lo_LA";
850 case LANG_LATIN: return "la_VA";
851 case LANG_LATVIAN: return "lv_LV";
852 case LANG_LITHUANIAN: return "lt_LT";
853 case LANG_MACEDONIAN: return "mk_MK";
854 case LANG_MALAY:
855 switch (sub)
857 case SUBLANG_MALAY_MALAYSIA: return "ms_MY";
858 case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN";
860 return "ms";
861 case LANG_MALAYALAM: return "ml_IN";
862 case LANG_MALTESE: return "mt_MT";
863 case LANG_MANIPURI:
864 /* FIXME: Adjust this when such locales appear on Unix. */
865 return "mni_IN";
866 case LANG_MARATHI: return "mr_IN";
867 case LANG_MONGOLIAN:
868 return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN". */
869 case LANG_NEPALI:
870 switch (sub)
872 case SUBLANG_DEFAULT: return "ne_NP";
873 case SUBLANG_NEPALI_INDIA: return "ne_IN";
875 return "ne";
876 case LANG_NORWEGIAN:
877 switch (sub)
879 case SUBLANG_NORWEGIAN_BOKMAL: return "no_NO";
880 case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO";
882 return "no";
883 case LANG_ORIYA: return "or_IN";
884 case LANG_OROMO: return "om_ET";
885 case LANG_PAPIAMENTU: return "pap_AN";
886 case LANG_PASHTO:
887 return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF". */
888 case LANG_POLISH: return "pl_PL";
889 case LANG_PORTUGUESE:
890 switch (sub)
892 case SUBLANG_PORTUGUESE: return "pt_PT";
893 /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT.
894 Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */
895 case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR";
897 return "pt";
898 case LANG_PUNJABI:
899 switch (sub)
901 case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */
903 return "pa";
904 case LANG_RHAETO_ROMANCE: return "rm_CH";
905 case LANG_ROMANIAN:
906 switch (sub)
908 case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO";
910 return "ro";
911 case LANG_RUSSIAN:
912 return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */
913 case LANG_SAAMI: /* actually Northern Sami */ return "se_NO";
914 case LANG_SANSKRIT: return "sa_IN";
915 case LANG_SINDHI:
916 switch (sub)
918 case SUBLANG_SINDHI_INDIA: return "sd_IN";
919 case SUBLANG_SINDHI_PAKISTAN: return "sd_PK";
921 return "sd";
922 case LANG_SINHALESE: return "si_LK";
923 case LANG_SLOVAK: return "sk_SK";
924 case LANG_SLOVENIAN: return "sl_SI";
925 case LANG_SOMALI: return "so_SO";
926 case LANG_SORBIAN:
927 /* FIXME: Adjust this when such locales appear on Unix. */
928 return "wen_DE";
929 case LANG_SPANISH:
930 switch (sub)
932 case SUBLANG_SPANISH: return "es_ES";
933 case SUBLANG_SPANISH_MEXICAN: return "es_MX";
934 case SUBLANG_SPANISH_MODERN:
935 return "es_ES@modern"; /* not seen on Unix */
936 case SUBLANG_SPANISH_GUATEMALA: return "es_GT";
937 case SUBLANG_SPANISH_COSTA_RICA: return "es_CR";
938 case SUBLANG_SPANISH_PANAMA: return "es_PA";
939 case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO";
940 case SUBLANG_SPANISH_VENEZUELA: return "es_VE";
941 case SUBLANG_SPANISH_COLOMBIA: return "es_CO";
942 case SUBLANG_SPANISH_PERU: return "es_PE";
943 case SUBLANG_SPANISH_ARGENTINA: return "es_AR";
944 case SUBLANG_SPANISH_ECUADOR: return "es_EC";
945 case SUBLANG_SPANISH_CHILE: return "es_CL";
946 case SUBLANG_SPANISH_URUGUAY: return "es_UY";
947 case SUBLANG_SPANISH_PARAGUAY: return "es_PY";
948 case SUBLANG_SPANISH_BOLIVIA: return "es_BO";
949 case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV";
950 case SUBLANG_SPANISH_HONDURAS: return "es_HN";
951 case SUBLANG_SPANISH_NICARAGUA: return "es_NI";
952 case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR";
954 return "es";
955 case LANG_SUTU: return "bnt_TZ"; /* or "st_LS" or "nso_ZA"? */
956 case LANG_SWAHILI: return "sw_KE";
957 case LANG_SWEDISH:
958 switch (sub)
960 case SUBLANG_DEFAULT: return "sv_SE";
961 case SUBLANG_SWEDISH_FINLAND: return "sv_FI";
963 return "sv";
964 case LANG_SYRIAC: return "syr_TR"; /* An extinct language. */
965 case LANG_TAGALOG: return "tl_PH";
966 case LANG_TAJIK: return "tg_TJ";
967 case LANG_TAMAZIGHT:
968 switch (sub)
970 /* FIXME: Adjust this when Tamazight locales appear on Unix. */
971 case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic";
972 case SUBLANG_TAMAZIGHT_LATIN: return "ber_MA@latin";
974 return "ber_MA";
975 case LANG_TAMIL:
976 return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */
977 case LANG_TATAR: return "tt_RU";
978 case LANG_TELUGU: return "te_IN";
979 case LANG_THAI: return "th_TH";
980 case LANG_TIBETAN: return "bo_CN";
981 case LANG_TIGRINYA:
982 switch (sub)
984 case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET";
985 case SUBLANG_TIGRINYA_ERITREA: return "ti_ER";
987 return "ti";
988 case LANG_TSONGA: return "ts_ZA";
989 case LANG_TSWANA: return "tn_BW";
990 case LANG_TURKISH: return "tr_TR";
991 case LANG_TURKMEN: return "tk_TM";
992 case LANG_UKRAINIAN: return "uk_UA";
993 case LANG_URDU:
994 switch (sub)
996 case SUBLANG_URDU_PAKISTAN: return "ur_PK";
997 case SUBLANG_URDU_INDIA: return "ur_IN";
999 return "ur";
1000 case LANG_UZBEK:
1001 switch (sub)
1003 case SUBLANG_UZBEK_LATIN: return "uz_UZ";
1004 case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic";
1006 return "uz";
1007 case LANG_VENDA:
1008 /* FIXME: It's not clear whether Venda has the ISO 639-2 two-letter code
1009 "ve" or not.
1010 http://www.loc.gov/standards/iso639-2/englangn.html has it, but
1011 http://lcweb.loc.gov/standards/iso639-2/codechanges.html doesn't, */
1012 return "ven_ZA"; /* or "ve_ZA"? */
1013 case LANG_VIETNAMESE: return "vi_VN";
1014 case LANG_WELSH: return "cy_GB";
1015 case LANG_XHOSA: return "xh_ZA";
1016 case LANG_YI: return "sit_CN";
1017 case LANG_YIDDISH: return "yi_IL";
1018 case LANG_YORUBA: return "yo_NG";
1019 case LANG_ZULU: return "zu_ZA";
1020 default: return "C";
1023 #endif /* HAVE_W32_SYSTEM */
1028 /* Return the locale used for translatable messages. The standard C
1029 and POSIX are locale names are mapped to an empty string. If a
1030 locale can't be found an empty string will be returned. */
1031 const char *
1032 gnupg_messages_locale_name (void)
1034 const char *s;
1036 s = do_nl_locale_name (LC_MESSAGES, "LC_MESSAGES");
1037 if (!s)
1038 s = "";
1039 else if (!strcmp (s, "C") || !strcmp (s, "POSIX"))
1040 s = "";
1042 return s;