localename: Improvements for MacOS X and Cygwin.
[gnulib.git] / lib / localename.c
1 /* Determine name of the currently selected locale.
2    Copyright (C) 1995-1999, 2000-2009 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify it
5    under the terms of the GNU Library General Public License as published
6    by the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
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.
13
14    You should have received a copy of the GNU Library General Public
15    License along with this program; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17    USA.  */
18
19 /* Written by Ulrich Drepper <drepper@gnu.org>, 1995.  */
20 /* Win32 code written by Tor Lillqvist <tml@iki.fi>.  */
21 /* MacOS X code written by Bruno Haible <bruno@clisp.org>.  */
22
23 #include <config.h>
24
25 /* Specification.  */
26 #ifdef IN_LIBINTL
27 # include "gettextP.h"
28 #else
29 # include "localename.h"
30 #endif
31
32 #include <stdlib.h>
33 #include <locale.h>
34 #include <string.h>
35
36 #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
37 # include <CoreFoundation/CFString.h>
38 # if HAVE_CFLOCALECOPYCURRENT
39 #  include <CoreFoundation/CFLocale.h>
40 # elif HAVE_CFPREFERENCESCOPYAPPVALUE
41 #  include <CoreFoundation/CFPreferences.h>
42 # endif
43 #endif
44
45 #if defined _WIN32 || defined __WIN32__
46 # define WIN32_NATIVE
47 #endif
48
49 #if defined WIN32_NATIVE || defined __CYGWIN__ /* WIN32 or Cygwin */
50 # define WIN32_LEAN_AND_MEAN
51 # include <windows.h>
52 /* List of language codes, sorted by value:
53    0x01 LANG_ARABIC
54    0x02 LANG_BULGARIAN
55    0x03 LANG_CATALAN
56    0x04 LANG_CHINESE
57    0x05 LANG_CZECH
58    0x06 LANG_DANISH
59    0x07 LANG_GERMAN
60    0x08 LANG_GREEK
61    0x09 LANG_ENGLISH
62    0x0a LANG_SPANISH
63    0x0b LANG_FINNISH
64    0x0c LANG_FRENCH
65    0x0d LANG_HEBREW
66    0x0e LANG_HUNGARIAN
67    0x0f LANG_ICELANDIC
68    0x10 LANG_ITALIAN
69    0x11 LANG_JAPANESE
70    0x12 LANG_KOREAN
71    0x13 LANG_DUTCH
72    0x14 LANG_NORWEGIAN
73    0x15 LANG_POLISH
74    0x16 LANG_PORTUGUESE
75    0x17 LANG_ROMANSH
76    0x18 LANG_ROMANIAN
77    0x19 LANG_RUSSIAN
78    0x1a LANG_CROATIAN == LANG_SERBIAN
79    0x1b LANG_SLOVAK
80    0x1c LANG_ALBANIAN
81    0x1d LANG_SWEDISH
82    0x1e LANG_THAI
83    0x1f LANG_TURKISH
84    0x20 LANG_URDU
85    0x21 LANG_INDONESIAN
86    0x22 LANG_UKRAINIAN
87    0x23 LANG_BELARUSIAN
88    0x24 LANG_SLOVENIAN
89    0x25 LANG_ESTONIAN
90    0x26 LANG_LATVIAN
91    0x27 LANG_LITHUANIAN
92    0x28 LANG_TAJIK
93    0x29 LANG_FARSI
94    0x2a LANG_VIETNAMESE
95    0x2b LANG_ARMENIAN
96    0x2c LANG_AZERI
97    0x2d LANG_BASQUE
98    0x2e LANG_SORBIAN
99    0x2f LANG_MACEDONIAN
100    0x30 LANG_SUTU
101    0x31 LANG_TSONGA
102    0x32 LANG_TSWANA
103    0x33 LANG_VENDA
104    0x34 LANG_XHOSA
105    0x35 LANG_ZULU
106    0x36 LANG_AFRIKAANS
107    0x37 LANG_GEORGIAN
108    0x38 LANG_FAEROESE
109    0x39 LANG_HINDI
110    0x3a LANG_MALTESE
111    0x3b LANG_SAMI
112    0x3c LANG_GAELIC
113    0x3d LANG_YIDDISH
114    0x3e LANG_MALAY
115    0x3f LANG_KAZAK
116    0x40 LANG_KYRGYZ
117    0x41 LANG_SWAHILI
118    0x42 LANG_TURKMEN
119    0x43 LANG_UZBEK
120    0x44 LANG_TATAR
121    0x45 LANG_BENGALI
122    0x46 LANG_PUNJABI
123    0x47 LANG_GUJARATI
124    0x48 LANG_ORIYA
125    0x49 LANG_TAMIL
126    0x4a LANG_TELUGU
127    0x4b LANG_KANNADA
128    0x4c LANG_MALAYALAM
129    0x4d LANG_ASSAMESE
130    0x4e LANG_MARATHI
131    0x4f LANG_SANSKRIT
132    0x50 LANG_MONGOLIAN
133    0x51 LANG_TIBETAN
134    0x52 LANG_WELSH
135    0x53 LANG_CAMBODIAN
136    0x54 LANG_LAO
137    0x55 LANG_BURMESE
138    0x56 LANG_GALICIAN
139    0x57 LANG_KONKANI
140    0x58 LANG_MANIPURI
141    0x59 LANG_SINDHI
142    0x5a LANG_SYRIAC
143    0x5b LANG_SINHALESE
144    0x5c LANG_CHEROKEE
145    0x5d LANG_INUKTITUT
146    0x5e LANG_AMHARIC
147    0x5f LANG_TAMAZIGHT
148    0x60 LANG_KASHMIRI
149    0x61 LANG_NEPALI
150    0x62 LANG_FRISIAN
151    0x63 LANG_PASHTO
152    0x64 LANG_TAGALOG
153    0x65 LANG_DIVEHI
154    0x66 LANG_EDO
155    0x67 LANG_FULFULDE
156    0x68 LANG_HAUSA
157    0x69 LANG_IBIBIO
158    0x6a LANG_YORUBA
159    0x6d LANG_BASHKIR
160    0x6e LANG_LUXEMBOURGISH
161    0x6f LANG_GREENLANDIC
162    0x70 LANG_IGBO
163    0x71 LANG_KANURI
164    0x72 LANG_OROMO
165    0x73 LANG_TIGRINYA
166    0x74 LANG_GUARANI
167    0x75 LANG_HAWAIIAN
168    0x76 LANG_LATIN
169    0x77 LANG_SOMALI
170    0x78 LANG_YI
171    0x79 LANG_PAPIAMENTU
172    0x7a LANG_MAPUDUNGUN
173    0x7c LANG_MOHAWK
174    0x7e LANG_BRETON
175    0x82 LANG_OCCITAN
176    0x83 LANG_CORSICAN
177    0x84 LANG_ALSATIAN
178    0x85 LANG_YAKUT
179    0x86 LANG_KICHE
180    0x87 LANG_KINYARWANDA
181    0x88 LANG_WOLOF
182    0x8c LANG_DARI
183    0x91 LANG_SCOTTISH_GAELIC
184 */
185 /* Mingw headers don't have latest language and sublanguage codes.  */
186 # ifndef LANG_AFRIKAANS
187 # define LANG_AFRIKAANS 0x36
188 # endif
189 # ifndef LANG_ALBANIAN
190 # define LANG_ALBANIAN 0x1c
191 # endif
192 # ifndef LANG_ALSATIAN
193 # define LANG_ALSATIAN 0x84
194 # endif
195 # ifndef LANG_AMHARIC
196 # define LANG_AMHARIC 0x5e
197 # endif
198 # ifndef LANG_ARABIC
199 # define LANG_ARABIC 0x01
200 # endif
201 # ifndef LANG_ARMENIAN
202 # define LANG_ARMENIAN 0x2b
203 # endif
204 # ifndef LANG_ASSAMESE
205 # define LANG_ASSAMESE 0x4d
206 # endif
207 # ifndef LANG_AZERI
208 # define LANG_AZERI 0x2c
209 # endif
210 # ifndef LANG_BASHKIR
211 # define LANG_BASHKIR 0x6d
212 # endif
213 # ifndef LANG_BASQUE
214 # define LANG_BASQUE 0x2d
215 # endif
216 # ifndef LANG_BELARUSIAN
217 # define LANG_BELARUSIAN 0x23
218 # endif
219 # ifndef LANG_BENGALI
220 # define LANG_BENGALI 0x45
221 # endif
222 # ifndef LANG_BRETON
223 # define LANG_BRETON 0x7e
224 # endif
225 # ifndef LANG_BURMESE
226 # define LANG_BURMESE 0x55
227 # endif
228 # ifndef LANG_CAMBODIAN
229 # define LANG_CAMBODIAN 0x53
230 # endif
231 # ifndef LANG_CATALAN
232 # define LANG_CATALAN 0x03
233 # endif
234 # ifndef LANG_CHEROKEE
235 # define LANG_CHEROKEE 0x5c
236 # endif
237 # ifndef LANG_CORSICAN
238 # define LANG_CORSICAN 0x83
239 # endif
240 # ifndef LANG_DARI
241 # define LANG_DARI 0x8c
242 # endif
243 # ifndef LANG_DIVEHI
244 # define LANG_DIVEHI 0x65
245 # endif
246 # ifndef LANG_EDO
247 # define LANG_EDO 0x66
248 # endif
249 # ifndef LANG_ESTONIAN
250 # define LANG_ESTONIAN 0x25
251 # endif
252 # ifndef LANG_FAEROESE
253 # define LANG_FAEROESE 0x38
254 # endif
255 # ifndef LANG_FARSI
256 # define LANG_FARSI 0x29
257 # endif
258 # ifndef LANG_FRISIAN
259 # define LANG_FRISIAN 0x62
260 # endif
261 # ifndef LANG_FULFULDE
262 # define LANG_FULFULDE 0x67
263 # endif
264 # ifndef LANG_GAELIC
265 # define LANG_GAELIC 0x3c
266 # endif
267 # ifndef LANG_GALICIAN
268 # define LANG_GALICIAN 0x56
269 # endif
270 # ifndef LANG_GEORGIAN
271 # define LANG_GEORGIAN 0x37
272 # endif
273 # ifndef LANG_GREENLANDIC
274 # define LANG_GREENLANDIC 0x6f
275 # endif
276 # ifndef LANG_GUARANI
277 # define LANG_GUARANI 0x74
278 # endif
279 # ifndef LANG_GUJARATI
280 # define LANG_GUJARATI 0x47
281 # endif
282 # ifndef LANG_HAUSA
283 # define LANG_HAUSA 0x68
284 # endif
285 # ifndef LANG_HAWAIIAN
286 # define LANG_HAWAIIAN 0x75
287 # endif
288 # ifndef LANG_HEBREW
289 # define LANG_HEBREW 0x0d
290 # endif
291 # ifndef LANG_HINDI
292 # define LANG_HINDI 0x39
293 # endif
294 # ifndef LANG_IBIBIO
295 # define LANG_IBIBIO 0x69
296 # endif
297 # ifndef LANG_IGBO
298 # define LANG_IGBO 0x70
299 # endif
300 # ifndef LANG_INDONESIAN
301 # define LANG_INDONESIAN 0x21
302 # endif
303 # ifndef LANG_INUKTITUT
304 # define LANG_INUKTITUT 0x5d
305 # endif
306 # ifndef LANG_KANNADA
307 # define LANG_KANNADA 0x4b
308 # endif
309 # ifndef LANG_KANURI
310 # define LANG_KANURI 0x71
311 # endif
312 # ifndef LANG_KASHMIRI
313 # define LANG_KASHMIRI 0x60
314 # endif
315 # ifndef LANG_KAZAK
316 # define LANG_KAZAK 0x3f
317 # endif
318 # ifndef LANG_KICHE
319 # define LANG_KICHE 0x86
320 # endif
321 # ifndef LANG_KINYARWANDA
322 # define LANG_KINYARWANDA 0x87
323 # endif
324 # ifndef LANG_KONKANI
325 # define LANG_KONKANI 0x57
326 # endif
327 # ifndef LANG_KYRGYZ
328 # define LANG_KYRGYZ 0x40
329 # endif
330 # ifndef LANG_LAO
331 # define LANG_LAO 0x54
332 # endif
333 # ifndef LANG_LATIN
334 # define LANG_LATIN 0x76
335 # endif
336 # ifndef LANG_LATVIAN
337 # define LANG_LATVIAN 0x26
338 # endif
339 # ifndef LANG_LITHUANIAN
340 # define LANG_LITHUANIAN 0x27
341 # endif
342 # ifndef LANG_LUXEMBOURGISH
343 # define LANG_LUXEMBOURGISH 0x6e
344 # endif
345 # ifndef LANG_MACEDONIAN
346 # define LANG_MACEDONIAN 0x2f
347 # endif
348 # ifndef LANG_MALAY
349 # define LANG_MALAY 0x3e
350 # endif
351 # ifndef LANG_MALAYALAM
352 # define LANG_MALAYALAM 0x4c
353 # endif
354 # ifndef LANG_MALTESE
355 # define LANG_MALTESE 0x3a
356 # endif
357 # ifndef LANG_MANIPURI
358 # define LANG_MANIPURI 0x58
359 # endif
360 # ifndef LANG_MAORI
361 # define LANG_MAORI 0x81
362 # endif
363 # ifndef LANG_MAPUDUNGUN
364 # define LANG_MAPUDUNGUN 0x7a
365 # endif
366 # ifndef LANG_MARATHI
367 # define LANG_MARATHI 0x4e
368 # endif
369 # ifndef LANG_MOHAWK
370 # define LANG_MOHAWK 0x7c
371 # endif
372 # ifndef LANG_MONGOLIAN
373 # define LANG_MONGOLIAN 0x50
374 # endif
375 # ifndef LANG_NEPALI
376 # define LANG_NEPALI 0x61
377 # endif
378 # ifndef LANG_OCCITAN
379 # define LANG_OCCITAN 0x82
380 # endif
381 # ifndef LANG_ORIYA
382 # define LANG_ORIYA 0x48
383 # endif
384 # ifndef LANG_OROMO
385 # define LANG_OROMO 0x72
386 # endif
387 # ifndef LANG_PAPIAMENTU
388 # define LANG_PAPIAMENTU 0x79
389 # endif
390 # ifndef LANG_PASHTO
391 # define LANG_PASHTO 0x63
392 # endif
393 # ifndef LANG_PUNJABI
394 # define LANG_PUNJABI 0x46
395 # endif
396 # ifndef LANG_QUECHUA
397 # define LANG_QUECHUA 0x6b
398 # endif
399 # ifndef LANG_ROMANSH
400 # define LANG_ROMANSH 0x17
401 # endif
402 # ifndef LANG_SAMI
403 # define LANG_SAMI 0x3b
404 # endif
405 # ifndef LANG_SANSKRIT
406 # define LANG_SANSKRIT 0x4f
407 # endif
408 # ifndef LANG_SCOTTISH_GAELIC
409 # define LANG_SCOTTISH_GAELIC 0x91
410 # endif
411 # ifndef LANG_SERBIAN
412 # define LANG_SERBIAN 0x1a
413 # endif
414 # ifndef LANG_SINDHI
415 # define LANG_SINDHI 0x59
416 # endif
417 # ifndef LANG_SINHALESE
418 # define LANG_SINHALESE 0x5b
419 # endif
420 # ifndef LANG_SLOVAK
421 # define LANG_SLOVAK 0x1b
422 # endif
423 # ifndef LANG_SOMALI
424 # define LANG_SOMALI 0x77
425 # endif
426 # ifndef LANG_SORBIAN
427 # define LANG_SORBIAN 0x2e
428 # endif
429 # ifndef LANG_SOTHO
430 # define LANG_SOTHO 0x6c
431 # endif
432 # ifndef LANG_SUTU
433 # define LANG_SUTU 0x30
434 # endif
435 # ifndef LANG_SWAHILI
436 # define LANG_SWAHILI 0x41
437 # endif
438 # ifndef LANG_SYRIAC
439 # define LANG_SYRIAC 0x5a
440 # endif
441 # ifndef LANG_TAGALOG
442 # define LANG_TAGALOG 0x64
443 # endif
444 # ifndef LANG_TAJIK
445 # define LANG_TAJIK 0x28
446 # endif
447 # ifndef LANG_TAMAZIGHT
448 # define LANG_TAMAZIGHT 0x5f
449 # endif
450 # ifndef LANG_TAMIL
451 # define LANG_TAMIL 0x49
452 # endif
453 # ifndef LANG_TATAR
454 # define LANG_TATAR 0x44
455 # endif
456 # ifndef LANG_TELUGU
457 # define LANG_TELUGU 0x4a
458 # endif
459 # ifndef LANG_THAI
460 # define LANG_THAI 0x1e
461 # endif
462 # ifndef LANG_TIBETAN
463 # define LANG_TIBETAN 0x51
464 # endif
465 # ifndef LANG_TIGRINYA
466 # define LANG_TIGRINYA 0x73
467 # endif
468 # ifndef LANG_TSONGA
469 # define LANG_TSONGA 0x31
470 # endif
471 # ifndef LANG_TSWANA
472 # define LANG_TSWANA 0x32
473 # endif
474 # ifndef LANG_TURKMEN
475 # define LANG_TURKMEN 0x42
476 # endif
477 # ifndef LANG_UIGHUR
478 # define LANG_UIGHUR 0x80
479 # endif
480 # ifndef LANG_UKRAINIAN
481 # define LANG_UKRAINIAN 0x22
482 # endif
483 # ifndef LANG_URDU
484 # define LANG_URDU 0x20
485 # endif
486 # ifndef LANG_UZBEK
487 # define LANG_UZBEK 0x43
488 # endif
489 # ifndef LANG_VENDA
490 # define LANG_VENDA 0x33
491 # endif
492 # ifndef LANG_VIETNAMESE
493 # define LANG_VIETNAMESE 0x2a
494 # endif
495 # ifndef LANG_WELSH
496 # define LANG_WELSH 0x52
497 # endif
498 # ifndef LANG_WOLOF
499 # define LANG_WOLOF 0x88
500 # endif
501 # ifndef LANG_XHOSA
502 # define LANG_XHOSA 0x34
503 # endif
504 # ifndef LANG_YAKUT
505 # define LANG_YAKUT 0x85
506 # endif
507 # ifndef LANG_YI
508 # define LANG_YI 0x78
509 # endif
510 # ifndef LANG_YIDDISH
511 # define LANG_YIDDISH 0x3d
512 # endif
513 # ifndef LANG_YORUBA
514 # define LANG_YORUBA 0x6a
515 # endif
516 # ifndef LANG_ZULU
517 # define LANG_ZULU 0x35
518 # endif
519 # ifndef SUBLANG_AFRIKAANS_SOUTH_AFRICA
520 # define SUBLANG_AFRIKAANS_SOUTH_AFRICA 0x01
521 # endif
522 # ifndef SUBLANG_ALBANIAN_ALBANIA
523 # define SUBLANG_ALBANIAN_ALBANIA 0x01
524 # endif
525 # ifndef SUBLANG_ALSATIAN_FRANCE
526 # define SUBLANG_ALSATIAN_FRANCE 0x01
527 # endif
528 # ifndef SUBLANG_AMHARIC_ETHIOPIA
529 # define SUBLANG_AMHARIC_ETHIOPIA 0x01
530 # endif
531 # ifndef SUBLANG_ARABIC_SAUDI_ARABIA
532 # define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
533 # endif
534 # ifndef SUBLANG_ARABIC_IRAQ
535 # define SUBLANG_ARABIC_IRAQ 0x02
536 # endif
537 # ifndef SUBLANG_ARABIC_EGYPT
538 # define SUBLANG_ARABIC_EGYPT 0x03
539 # endif
540 # ifndef SUBLANG_ARABIC_LIBYA
541 # define SUBLANG_ARABIC_LIBYA 0x04
542 # endif
543 # ifndef SUBLANG_ARABIC_ALGERIA
544 # define SUBLANG_ARABIC_ALGERIA 0x05
545 # endif
546 # ifndef SUBLANG_ARABIC_MOROCCO
547 # define SUBLANG_ARABIC_MOROCCO 0x06
548 # endif
549 # ifndef SUBLANG_ARABIC_TUNISIA
550 # define SUBLANG_ARABIC_TUNISIA 0x07
551 # endif
552 # ifndef SUBLANG_ARABIC_OMAN
553 # define SUBLANG_ARABIC_OMAN 0x08
554 # endif
555 # ifndef SUBLANG_ARABIC_YEMEN
556 # define SUBLANG_ARABIC_YEMEN 0x09
557 # endif
558 # ifndef SUBLANG_ARABIC_SYRIA
559 # define SUBLANG_ARABIC_SYRIA 0x0a
560 # endif
561 # ifndef SUBLANG_ARABIC_JORDAN
562 # define SUBLANG_ARABIC_JORDAN 0x0b
563 # endif
564 # ifndef SUBLANG_ARABIC_LEBANON
565 # define SUBLANG_ARABIC_LEBANON 0x0c
566 # endif
567 # ifndef SUBLANG_ARABIC_KUWAIT
568 # define SUBLANG_ARABIC_KUWAIT 0x0d
569 # endif
570 # ifndef SUBLANG_ARABIC_UAE
571 # define SUBLANG_ARABIC_UAE 0x0e
572 # endif
573 # ifndef SUBLANG_ARABIC_BAHRAIN
574 # define SUBLANG_ARABIC_BAHRAIN 0x0f
575 # endif
576 # ifndef SUBLANG_ARABIC_QATAR
577 # define SUBLANG_ARABIC_QATAR 0x10
578 # endif
579 # ifndef SUBLANG_ARMENIAN_ARMENIA
580 # define SUBLANG_ARMENIAN_ARMENIA 0x01
581 # endif
582 # ifndef SUBLANG_ASSAMESE_INDIA
583 # define SUBLANG_ASSAMESE_INDIA 0x01
584 # endif
585 # ifndef SUBLANG_AZERI_LATIN
586 # define SUBLANG_AZERI_LATIN 0x01
587 # endif
588 # ifndef SUBLANG_AZERI_CYRILLIC
589 # define SUBLANG_AZERI_CYRILLIC 0x02
590 # endif
591 # ifndef SUBLANG_BASHKIR_RUSSIA
592 # define SUBLANG_BASHKIR_RUSSIA 0x01
593 # endif
594 # ifndef SUBLANG_BASQUE_BASQUE
595 # define SUBLANG_BASQUE_BASQUE 0x01
596 # endif
597 # ifndef SUBLANG_BELARUSIAN_BELARUS
598 # define SUBLANG_BELARUSIAN_BELARUS 0x01
599 # endif
600 # ifndef SUBLANG_BENGALI_INDIA
601 # define SUBLANG_BENGALI_INDIA 0x01
602 # endif
603 # ifndef SUBLANG_BENGALI_BANGLADESH
604 # define SUBLANG_BENGALI_BANGLADESH 0x02
605 # endif
606 # ifndef SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN
607 # define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN 0x05
608 # endif
609 # ifndef SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC
610 # define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC 0x08
611 # endif
612 # ifndef SUBLANG_BRETON_FRANCE
613 # define SUBLANG_BRETON_FRANCE 0x01
614 # endif
615 # ifndef SUBLANG_BULGARIAN_BULGARIA
616 # define SUBLANG_BULGARIAN_BULGARIA 0x01
617 # endif
618 # ifndef SUBLANG_CAMBODIAN_CAMBODIA
619 # define SUBLANG_CAMBODIAN_CAMBODIA 0x01
620 # endif
621 # ifndef SUBLANG_CATALAN_SPAIN
622 # define SUBLANG_CATALAN_SPAIN 0x01
623 # endif
624 # ifndef SUBLANG_CORSICAN_FRANCE
625 # define SUBLANG_CORSICAN_FRANCE 0x01
626 # endif
627 # ifndef SUBLANG_CROATIAN_CROATIA
628 # define SUBLANG_CROATIAN_CROATIA 0x01
629 # endif
630 # ifndef SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN
631 # define SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN 0x04
632 # endif
633 # ifndef SUBLANG_CHINESE_MACAU
634 # define SUBLANG_CHINESE_MACAU 0x05
635 # endif
636 # ifndef SUBLANG_CZECH_CZECH_REPUBLIC
637 # define SUBLANG_CZECH_CZECH_REPUBLIC 0x01
638 # endif
639 # ifndef SUBLANG_DANISH_DENMARK
640 # define SUBLANG_DANISH_DENMARK 0x01
641 # endif
642 # ifndef SUBLANG_DARI_AFGHANISTAN
643 # define SUBLANG_DARI_AFGHANISTAN 0x01
644 # endif
645 # ifndef SUBLANG_DIVEHI_MALDIVES
646 # define SUBLANG_DIVEHI_MALDIVES 0x01
647 # endif
648 # ifndef SUBLANG_DUTCH_SURINAM
649 # define SUBLANG_DUTCH_SURINAM 0x03
650 # endif
651 # ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
652 # define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
653 # endif
654 # ifndef SUBLANG_ENGLISH_JAMAICA
655 # define SUBLANG_ENGLISH_JAMAICA 0x08
656 # endif
657 # ifndef SUBLANG_ENGLISH_CARIBBEAN
658 # define SUBLANG_ENGLISH_CARIBBEAN 0x09
659 # endif
660 # ifndef SUBLANG_ENGLISH_BELIZE
661 # define SUBLANG_ENGLISH_BELIZE 0x0a
662 # endif
663 # ifndef SUBLANG_ENGLISH_TRINIDAD
664 # define SUBLANG_ENGLISH_TRINIDAD 0x0b
665 # endif
666 # ifndef SUBLANG_ENGLISH_ZIMBABWE
667 # define SUBLANG_ENGLISH_ZIMBABWE 0x0c
668 # endif
669 # ifndef SUBLANG_ENGLISH_PHILIPPINES
670 # define SUBLANG_ENGLISH_PHILIPPINES 0x0d
671 # endif
672 # ifndef SUBLANG_ENGLISH_INDONESIA
673 # define SUBLANG_ENGLISH_INDONESIA 0x0e
674 # endif
675 # ifndef SUBLANG_ENGLISH_HONGKONG
676 # define SUBLANG_ENGLISH_HONGKONG 0x0f
677 # endif
678 # ifndef SUBLANG_ENGLISH_INDIA
679 # define SUBLANG_ENGLISH_INDIA 0x10
680 # endif
681 # ifndef SUBLANG_ENGLISH_MALAYSIA
682 # define SUBLANG_ENGLISH_MALAYSIA 0x11
683 # endif
684 # ifndef SUBLANG_ENGLISH_SINGAPORE
685 # define SUBLANG_ENGLISH_SINGAPORE 0x12
686 # endif
687 # ifndef SUBLANG_ESTONIAN_ESTONIA
688 # define SUBLANG_ESTONIAN_ESTONIA 0x01
689 # endif
690 # ifndef SUBLANG_FAEROESE_FAROE_ISLANDS
691 # define SUBLANG_FAEROESE_FAROE_ISLANDS 0x01
692 # endif
693 # ifndef SUBLANG_FARSI_IRAN
694 # define SUBLANG_FARSI_IRAN 0x01
695 # endif
696 # ifndef SUBLANG_FINNISH_FINLAND
697 # define SUBLANG_FINNISH_FINLAND 0x01
698 # endif
699 # ifndef SUBLANG_FRENCH_LUXEMBOURG
700 # define SUBLANG_FRENCH_LUXEMBOURG 0x05
701 # endif
702 # ifndef SUBLANG_FRENCH_MONACO
703 # define SUBLANG_FRENCH_MONACO 0x06
704 # endif
705 # ifndef SUBLANG_FRENCH_WESTINDIES
706 # define SUBLANG_FRENCH_WESTINDIES 0x07
707 # endif
708 # ifndef SUBLANG_FRENCH_REUNION
709 # define SUBLANG_FRENCH_REUNION 0x08
710 # endif
711 # ifndef SUBLANG_FRENCH_CONGO
712 # define SUBLANG_FRENCH_CONGO 0x09
713 # endif
714 # ifndef SUBLANG_FRENCH_SENEGAL
715 # define SUBLANG_FRENCH_SENEGAL 0x0a
716 # endif
717 # ifndef SUBLANG_FRENCH_CAMEROON
718 # define SUBLANG_FRENCH_CAMEROON 0x0b
719 # endif
720 # ifndef SUBLANG_FRENCH_COTEDIVOIRE
721 # define SUBLANG_FRENCH_COTEDIVOIRE 0x0c
722 # endif
723 # ifndef SUBLANG_FRENCH_MALI
724 # define SUBLANG_FRENCH_MALI 0x0d
725 # endif
726 # ifndef SUBLANG_FRENCH_MOROCCO
727 # define SUBLANG_FRENCH_MOROCCO 0x0e
728 # endif
729 # ifndef SUBLANG_FRENCH_HAITI
730 # define SUBLANG_FRENCH_HAITI 0x0f
731 # endif
732 # ifndef SUBLANG_FRISIAN_NETHERLANDS
733 # define SUBLANG_FRISIAN_NETHERLANDS 0x01
734 # endif
735 # ifndef SUBLANG_GALICIAN_SPAIN
736 # define SUBLANG_GALICIAN_SPAIN 0x01
737 # endif
738 # ifndef SUBLANG_GEORGIAN_GEORGIA
739 # define SUBLANG_GEORGIAN_GEORGIA 0x01
740 # endif
741 # ifndef SUBLANG_GERMAN_LUXEMBOURG
742 # define SUBLANG_GERMAN_LUXEMBOURG 0x04
743 # endif
744 # ifndef SUBLANG_GERMAN_LIECHTENSTEIN
745 # define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
746 # endif
747 # ifndef SUBLANG_GREEK_GREECE
748 # define SUBLANG_GREEK_GREECE 0x01
749 # endif
750 # ifndef SUBLANG_GREENLANDIC_GREENLAND
751 # define SUBLANG_GREENLANDIC_GREENLAND 0x01
752 # endif
753 # ifndef SUBLANG_GUJARATI_INDIA
754 # define SUBLANG_GUJARATI_INDIA 0x01
755 # endif
756 # ifndef SUBLANG_HAUSA_NIGERIA_LATIN
757 # define SUBLANG_HAUSA_NIGERIA_LATIN 0x01
758 # endif
759 # ifndef SUBLANG_HEBREW_ISRAEL
760 # define SUBLANG_HEBREW_ISRAEL 0x01
761 # endif
762 # ifndef SUBLANG_HINDI_INDIA
763 # define SUBLANG_HINDI_INDIA 0x01
764 # endif
765 # ifndef SUBLANG_HUNGARIAN_HUNGARY
766 # define SUBLANG_HUNGARIAN_HUNGARY 0x01
767 # endif
768 # ifndef SUBLANG_ICELANDIC_ICELAND
769 # define SUBLANG_ICELANDIC_ICELAND 0x01
770 # endif
771 # ifndef SUBLANG_IGBO_NIGERIA
772 # define SUBLANG_IGBO_NIGERIA 0x01
773 # endif
774 # ifndef SUBLANG_INDONESIAN_INDONESIA
775 # define SUBLANG_INDONESIAN_INDONESIA 0x01
776 # endif
777 # ifndef SUBLANG_INUKTITUT_CANADA
778 # define SUBLANG_INUKTITUT_CANADA 0x01
779 # endif
780 # undef SUBLANG_INUKTITUT_CANADA_LATIN
781 # define SUBLANG_INUKTITUT_CANADA_LATIN 0x02
782 # undef SUBLANG_IRISH_IRELAND
783 # define SUBLANG_IRISH_IRELAND 0x02
784 # ifndef SUBLANG_JAPANESE_JAPAN
785 # define SUBLANG_JAPANESE_JAPAN 0x01
786 # endif
787 # ifndef SUBLANG_KANNADA_INDIA
788 # define SUBLANG_KANNADA_INDIA 0x01
789 # endif
790 # ifndef SUBLANG_KASHMIRI_INDIA
791 # define SUBLANG_KASHMIRI_INDIA 0x02
792 # endif
793 # ifndef SUBLANG_KAZAK_KAZAKHSTAN
794 # define SUBLANG_KAZAK_KAZAKHSTAN 0x01
795 # endif
796 # ifndef SUBLANG_KICHE_GUATEMALA
797 # define SUBLANG_KICHE_GUATEMALA 0x01
798 # endif
799 # ifndef SUBLANG_KINYARWANDA_RWANDA
800 # define SUBLANG_KINYARWANDA_RWANDA 0x01
801 # endif
802 # ifndef SUBLANG_KONKANI_INDIA
803 # define SUBLANG_KONKANI_INDIA 0x01
804 # endif
805 # ifndef SUBLANG_KYRGYZ_KYRGYZSTAN
806 # define SUBLANG_KYRGYZ_KYRGYZSTAN 0x01
807 # endif
808 # ifndef SUBLANG_LAO_LAOS
809 # define SUBLANG_LAO_LAOS 0x01
810 # endif
811 # ifndef SUBLANG_LATVIAN_LATVIA
812 # define SUBLANG_LATVIAN_LATVIA 0x01
813 # endif
814 # ifndef SUBLANG_LITHUANIAN_LITHUANIA
815 # define SUBLANG_LITHUANIAN_LITHUANIA 0x01
816 # endif
817 # undef SUBLANG_LOWER_SORBIAN_GERMANY
818 # define SUBLANG_LOWER_SORBIAN_GERMANY 0x02
819 # ifndef SUBLANG_LUXEMBOURGISH_LUXEMBOURG
820 # define SUBLANG_LUXEMBOURGISH_LUXEMBOURG 0x01
821 # endif
822 # ifndef SUBLANG_MACEDONIAN_MACEDONIA
823 # define SUBLANG_MACEDONIAN_MACEDONIA 0x01
824 # endif
825 # ifndef SUBLANG_MALAY_MALAYSIA
826 # define SUBLANG_MALAY_MALAYSIA 0x01
827 # endif
828 # ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
829 # define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
830 # endif
831 # ifndef SUBLANG_MALAYALAM_INDIA
832 # define SUBLANG_MALAYALAM_INDIA 0x01
833 # endif
834 # ifndef SUBLANG_MALTESE_MALTA
835 # define SUBLANG_MALTESE_MALTA 0x01
836 # endif
837 # ifndef SUBLANG_MAORI_NEW_ZEALAND
838 # define SUBLANG_MAORI_NEW_ZEALAND 0x01
839 # endif
840 # ifndef SUBLANG_MAPUDUNGUN_CHILE
841 # define SUBLANG_MAPUDUNGUN_CHILE 0x01
842 # endif
843 # ifndef SUBLANG_MARATHI_INDIA
844 # define SUBLANG_MARATHI_INDIA 0x01
845 # endif
846 # ifndef SUBLANG_MOHAWK_CANADA
847 # define SUBLANG_MOHAWK_CANADA 0x01
848 # endif
849 # ifndef SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA
850 # define SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA 0x01
851 # endif
852 # ifndef SUBLANG_MONGOLIAN_PRC
853 # define SUBLANG_MONGOLIAN_PRC 0x02
854 # endif
855 # ifndef SUBLANG_NEPALI_NEPAL
856 # define SUBLANG_NEPALI_NEPAL 0x01
857 # endif
858 # ifndef SUBLANG_NEPALI_INDIA
859 # define SUBLANG_NEPALI_INDIA 0x02
860 # endif
861 # ifndef SUBLANG_OCCITAN_FRANCE
862 # define SUBLANG_OCCITAN_FRANCE 0x01
863 # endif
864 # ifndef SUBLANG_ORIYA_INDIA
865 # define SUBLANG_ORIYA_INDIA 0x01
866 # endif
867 # ifndef SUBLANG_PASHTO_AFGHANISTAN
868 # define SUBLANG_PASHTO_AFGHANISTAN 0x01
869 # endif
870 # ifndef SUBLANG_POLISH_POLAND
871 # define SUBLANG_POLISH_POLAND 0x01
872 # endif
873 # ifndef SUBLANG_PUNJABI_INDIA
874 # define SUBLANG_PUNJABI_INDIA 0x01
875 # endif
876 # ifndef SUBLANG_PUNJABI_PAKISTAN
877 # define SUBLANG_PUNJABI_PAKISTAN 0x02
878 # endif
879 # ifndef SUBLANG_QUECHUA_BOLIVIA
880 # define SUBLANG_QUECHUA_BOLIVIA 0x01
881 # endif
882 # ifndef SUBLANG_QUECHUA_ECUADOR
883 # define SUBLANG_QUECHUA_ECUADOR 0x02
884 # endif
885 # ifndef SUBLANG_QUECHUA_PERU
886 # define SUBLANG_QUECHUA_PERU 0x03
887 # endif
888 # ifndef SUBLANG_ROMANIAN_ROMANIA
889 # define SUBLANG_ROMANIAN_ROMANIA 0x01
890 # endif
891 # ifndef SUBLANG_ROMANIAN_MOLDOVA
892 # define SUBLANG_ROMANIAN_MOLDOVA 0x02
893 # endif
894 # ifndef SUBLANG_ROMANSH_SWITZERLAND
895 # define SUBLANG_ROMANSH_SWITZERLAND 0x01
896 # endif
897 # ifndef SUBLANG_RUSSIAN_RUSSIA
898 # define SUBLANG_RUSSIAN_RUSSIA 0x01
899 # endif
900 # ifndef SUBLANG_RUSSIAN_MOLDAVIA
901 # define SUBLANG_RUSSIAN_MOLDAVIA 0x02
902 # endif
903 # ifndef SUBLANG_SAMI_NORTHERN_NORWAY
904 # define SUBLANG_SAMI_NORTHERN_NORWAY 0x01
905 # endif
906 # ifndef SUBLANG_SAMI_NORTHERN_SWEDEN
907 # define SUBLANG_SAMI_NORTHERN_SWEDEN 0x02
908 # endif
909 # ifndef SUBLANG_SAMI_NORTHERN_FINLAND
910 # define SUBLANG_SAMI_NORTHERN_FINLAND 0x03
911 # endif
912 # ifndef SUBLANG_SAMI_LULE_NORWAY
913 # define SUBLANG_SAMI_LULE_NORWAY 0x04
914 # endif
915 # ifndef SUBLANG_SAMI_LULE_SWEDEN
916 # define SUBLANG_SAMI_LULE_SWEDEN 0x05
917 # endif
918 # ifndef SUBLANG_SAMI_SOUTHERN_NORWAY
919 # define SUBLANG_SAMI_SOUTHERN_NORWAY 0x06
920 # endif
921 # ifndef SUBLANG_SAMI_SOUTHERN_SWEDEN
922 # define SUBLANG_SAMI_SOUTHERN_SWEDEN 0x07
923 # endif
924 # undef SUBLANG_SAMI_SKOLT_FINLAND
925 # define SUBLANG_SAMI_SKOLT_FINLAND 0x08
926 # undef SUBLANG_SAMI_INARI_FINLAND
927 # define SUBLANG_SAMI_INARI_FINLAND 0x09
928 # ifndef SUBLANG_SANSKRIT_INDIA
929 # define SUBLANG_SANSKRIT_INDIA 0x01
930 # endif
931 # ifndef SUBLANG_SERBIAN_LATIN
932 # define SUBLANG_SERBIAN_LATIN 0x02
933 # endif
934 # ifndef SUBLANG_SERBIAN_CYRILLIC
935 # define SUBLANG_SERBIAN_CYRILLIC 0x03
936 # endif
937 # ifndef SUBLANG_SINDHI_INDIA
938 # define SUBLANG_SINDHI_INDIA 0x01
939 # endif
940 # undef SUBLANG_SINDHI_PAKISTAN
941 # define SUBLANG_SINDHI_PAKISTAN 0x02
942 # ifndef SUBLANG_SINDHI_AFGHANISTAN
943 # define SUBLANG_SINDHI_AFGHANISTAN 0x02
944 # endif
945 # ifndef SUBLANG_SINHALESE_SRI_LANKA
946 # define SUBLANG_SINHALESE_SRI_LANKA 0x01
947 # endif
948 # ifndef SUBLANG_SLOVAK_SLOVAKIA
949 # define SUBLANG_SLOVAK_SLOVAKIA 0x01
950 # endif
951 # ifndef SUBLANG_SLOVENIAN_SLOVENIA
952 # define SUBLANG_SLOVENIAN_SLOVENIA 0x01
953 # endif
954 # ifndef SUBLANG_SOTHO_SOUTH_AFRICA
955 # define SUBLANG_SOTHO_SOUTH_AFRICA 0x01
956 # endif
957 # ifndef SUBLANG_SPANISH_GUATEMALA
958 # define SUBLANG_SPANISH_GUATEMALA 0x04
959 # endif
960 # ifndef SUBLANG_SPANISH_COSTA_RICA
961 # define SUBLANG_SPANISH_COSTA_RICA 0x05
962 # endif
963 # ifndef SUBLANG_SPANISH_PANAMA
964 # define SUBLANG_SPANISH_PANAMA 0x06
965 # endif
966 # ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
967 # define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
968 # endif
969 # ifndef SUBLANG_SPANISH_VENEZUELA
970 # define SUBLANG_SPANISH_VENEZUELA 0x08
971 # endif
972 # ifndef SUBLANG_SPANISH_COLOMBIA
973 # define SUBLANG_SPANISH_COLOMBIA 0x09
974 # endif
975 # ifndef SUBLANG_SPANISH_PERU
976 # define SUBLANG_SPANISH_PERU 0x0a
977 # endif
978 # ifndef SUBLANG_SPANISH_ARGENTINA
979 # define SUBLANG_SPANISH_ARGENTINA 0x0b
980 # endif
981 # ifndef SUBLANG_SPANISH_ECUADOR
982 # define SUBLANG_SPANISH_ECUADOR 0x0c
983 # endif
984 # ifndef SUBLANG_SPANISH_CHILE
985 # define SUBLANG_SPANISH_CHILE 0x0d
986 # endif
987 # ifndef SUBLANG_SPANISH_URUGUAY
988 # define SUBLANG_SPANISH_URUGUAY 0x0e
989 # endif
990 # ifndef SUBLANG_SPANISH_PARAGUAY
991 # define SUBLANG_SPANISH_PARAGUAY 0x0f
992 # endif
993 # ifndef SUBLANG_SPANISH_BOLIVIA
994 # define SUBLANG_SPANISH_BOLIVIA 0x10
995 # endif
996 # ifndef SUBLANG_SPANISH_EL_SALVADOR
997 # define SUBLANG_SPANISH_EL_SALVADOR 0x11
998 # endif
999 # ifndef SUBLANG_SPANISH_HONDURAS
1000 # define SUBLANG_SPANISH_HONDURAS 0x12
1001 # endif
1002 # ifndef SUBLANG_SPANISH_NICARAGUA
1003 # define SUBLANG_SPANISH_NICARAGUA 0x13
1004 # endif
1005 # ifndef SUBLANG_SPANISH_PUERTO_RICO
1006 # define SUBLANG_SPANISH_PUERTO_RICO 0x14
1007 # endif
1008 # ifndef SUBLANG_SPANISH_US
1009 # define SUBLANG_SPANISH_US 0x15
1010 # endif
1011 # ifndef SUBLANG_SWAHILI_KENYA
1012 # define SUBLANG_SWAHILI_KENYA 0x01
1013 # endif
1014 # ifndef SUBLANG_SWEDISH_SWEDEN
1015 # define SUBLANG_SWEDISH_SWEDEN 0x01
1016 # endif
1017 # ifndef SUBLANG_SWEDISH_FINLAND
1018 # define SUBLANG_SWEDISH_FINLAND 0x02
1019 # endif
1020 # ifndef SUBLANG_SYRIAC_SYRIA
1021 # define SUBLANG_SYRIAC_SYRIA 0x01
1022 # endif
1023 # ifndef SUBLANG_TAGALOG_PHILIPPINES
1024 # define SUBLANG_TAGALOG_PHILIPPINES 0x01
1025 # endif
1026 # ifndef SUBLANG_TAJIK_TAJIKISTAN
1027 # define SUBLANG_TAJIK_TAJIKISTAN 0x01
1028 # endif
1029 # ifndef SUBLANG_TAMAZIGHT_ARABIC
1030 # define SUBLANG_TAMAZIGHT_ARABIC 0x01
1031 # endif
1032 # ifndef SUBLANG_TAMAZIGHT_ALGERIA_LATIN
1033 # define SUBLANG_TAMAZIGHT_ALGERIA_LATIN 0x02
1034 # endif
1035 # ifndef SUBLANG_TAMIL_INDIA
1036 # define SUBLANG_TAMIL_INDIA 0x01
1037 # endif
1038 # ifndef SUBLANG_TATAR_RUSSIA
1039 # define SUBLANG_TATAR_RUSSIA 0x01
1040 # endif
1041 # ifndef SUBLANG_TELUGU_INDIA
1042 # define SUBLANG_TELUGU_INDIA 0x01
1043 # endif
1044 # ifndef SUBLANG_THAI_THAILAND
1045 # define SUBLANG_THAI_THAILAND 0x01
1046 # endif
1047 # ifndef SUBLANG_TIBETAN_PRC
1048 # define SUBLANG_TIBETAN_PRC 0x01
1049 # endif
1050 # undef SUBLANG_TIBETAN_BHUTAN
1051 # define SUBLANG_TIBETAN_BHUTAN 0x02
1052 # ifndef SUBLANG_TIGRINYA_ETHIOPIA
1053 # define SUBLANG_TIGRINYA_ETHIOPIA 0x01
1054 # endif
1055 # ifndef SUBLANG_TIGRINYA_ERITREA
1056 # define SUBLANG_TIGRINYA_ERITREA 0x02
1057 # endif
1058 # ifndef SUBLANG_TSWANA_SOUTH_AFRICA
1059 # define SUBLANG_TSWANA_SOUTH_AFRICA 0x01
1060 # endif
1061 # ifndef SUBLANG_TURKISH_TURKEY
1062 # define SUBLANG_TURKISH_TURKEY 0x01
1063 # endif
1064 # ifndef SUBLANG_TURKMEN_TURKMENISTAN
1065 # define SUBLANG_TURKMEN_TURKMENISTAN 0x01
1066 # endif
1067 # ifndef SUBLANG_UIGHUR_PRC
1068 # define SUBLANG_UIGHUR_PRC 0x01
1069 # endif
1070 # ifndef SUBLANG_UKRAINIAN_UKRAINE
1071 # define SUBLANG_UKRAINIAN_UKRAINE 0x01
1072 # endif
1073 # ifndef SUBLANG_UPPER_SORBIAN_GERMANY
1074 # define SUBLANG_UPPER_SORBIAN_GERMANY 0x01
1075 # endif
1076 # ifndef SUBLANG_URDU_PAKISTAN
1077 # define SUBLANG_URDU_PAKISTAN 0x01
1078 # endif
1079 # ifndef SUBLANG_URDU_INDIA
1080 # define SUBLANG_URDU_INDIA 0x02
1081 # endif
1082 # ifndef SUBLANG_UZBEK_LATIN
1083 # define SUBLANG_UZBEK_LATIN 0x01
1084 # endif
1085 # ifndef SUBLANG_UZBEK_CYRILLIC
1086 # define SUBLANG_UZBEK_CYRILLIC 0x02
1087 # endif
1088 # ifndef SUBLANG_VIETNAMESE_VIETNAM
1089 # define SUBLANG_VIETNAMESE_VIETNAM 0x01
1090 # endif
1091 # ifndef SUBLANG_WELSH_UNITED_KINGDOM
1092 # define SUBLANG_WELSH_UNITED_KINGDOM 0x01
1093 # endif
1094 # ifndef SUBLANG_WOLOF_SENEGAL
1095 # define SUBLANG_WOLOF_SENEGAL 0x01
1096 # endif
1097 # ifndef SUBLANG_XHOSA_SOUTH_AFRICA
1098 # define SUBLANG_XHOSA_SOUTH_AFRICA 0x01
1099 # endif
1100 # ifndef SUBLANG_YAKUT_RUSSIA
1101 # define SUBLANG_YAKUT_RUSSIA 0x01
1102 # endif
1103 # ifndef SUBLANG_YI_PRC
1104 # define SUBLANG_YI_PRC 0x01
1105 # endif
1106 # ifndef SUBLANG_YORUBA_NIGERIA
1107 # define SUBLANG_YORUBA_NIGERIA 0x01
1108 # endif
1109 # ifndef SUBLANG_ZULU_SOUTH_AFRICA
1110 # define SUBLANG_ZULU_SOUTH_AFRICA 0x01
1111 # endif
1112 /* GetLocaleInfoA operations.  */
1113 # ifndef LOCALE_SNAME
1114 # define LOCALE_SNAME 0x5c
1115 # endif
1116 #endif
1117
1118
1119 #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
1120 /* MacOS X 10.2 or newer */
1121
1122 /* Canonicalize a MacOS X locale name to a Unix locale name.
1123    NAME is a sufficiently large buffer.
1124    On input, it contains the MacOS X locale name.
1125    On output, it contains the Unix locale name.  */
1126 # if !defined IN_LIBINTL
1127 static
1128 # endif
1129 void
1130 gl_locale_name_canonicalize (char *name)
1131 {
1132   /* This conversion is based on a posting by
1133      Deborah GoldSmith <goldsmit@apple.com> on 2005-03-08,
1134      http://lists.apple.com/archives/carbon-dev/2005/Mar/msg00293.html */
1135
1136   /* Convert legacy (NeXTstep inherited) English names to Unix (ISO 639 and
1137      ISO 3166) names.  Prior to MacOS X 10.3, there is no API for doing this.
1138      Therefore we do it ourselves, using a table based on the results of the
1139      MacOS X 10.3.8 function
1140      CFLocaleCreateCanonicalLocaleIdentifierFromString().  */
1141   typedef struct { const char legacy[21+1]; const char unixy[5+1]; }
1142           legacy_entry;
1143   static const legacy_entry legacy_table[] = {
1144     { "Afrikaans",             "af" },
1145     { "Albanian",              "sq" },
1146     { "Amharic",               "am" },
1147     { "Arabic",                "ar" },
1148     { "Armenian",              "hy" },
1149     { "Assamese",              "as" },
1150     { "Aymara",                "ay" },
1151     { "Azerbaijani",           "az" },
1152     { "Basque",                "eu" },
1153     { "Belarusian",            "be" },
1154     { "Belorussian",           "be" },
1155     { "Bengali",               "bn" },
1156     { "Brazilian Portugese",   "pt_BR" },
1157     { "Brazilian Portuguese",  "pt_BR" },
1158     { "Breton",                "br" },
1159     { "Bulgarian",             "bg" },
1160     { "Burmese",               "my" },
1161     { "Byelorussian",          "be" },
1162     { "Catalan",               "ca" },
1163     { "Chewa",                 "ny" },
1164     { "Chichewa",              "ny" },
1165     { "Chinese",               "zh" },
1166     { "Chinese, Simplified",   "zh_CN" },
1167     { "Chinese, Traditional",  "zh_TW" },
1168     { "Chinese, Tradtional",   "zh_TW" },
1169     { "Croatian",              "hr" },
1170     { "Czech",                 "cs" },
1171     { "Danish",                "da" },
1172     { "Dutch",                 "nl" },
1173     { "Dzongkha",              "dz" },
1174     { "English",               "en" },
1175     { "Esperanto",             "eo" },
1176     { "Estonian",              "et" },
1177     { "Faroese",               "fo" },
1178     { "Farsi",                 "fa" },
1179     { "Finnish",               "fi" },
1180     { "Flemish",               "nl_BE" },
1181     { "French",                "fr" },
1182     { "Galician",              "gl" },
1183     { "Gallegan",              "gl" },
1184     { "Georgian",              "ka" },
1185     { "German",                "de" },
1186     { "Greek",                 "el" },
1187     { "Greenlandic",           "kl" },
1188     { "Guarani",               "gn" },
1189     { "Gujarati",              "gu" },
1190     { "Hawaiian",              "haw" }, /* Yes, "haw", not "cpe".  */
1191     { "Hebrew",                "he" },
1192     { "Hindi",                 "hi" },
1193     { "Hungarian",             "hu" },
1194     { "Icelandic",             "is" },
1195     { "Indonesian",            "id" },
1196     { "Inuktitut",             "iu" },
1197     { "Irish",                 "ga" },
1198     { "Italian",               "it" },
1199     { "Japanese",              "ja" },
1200     { "Javanese",              "jv" },
1201     { "Kalaallisut",           "kl" },
1202     { "Kannada",               "kn" },
1203     { "Kashmiri",              "ks" },
1204     { "Kazakh",                "kk" },
1205     { "Khmer",                 "km" },
1206     { "Kinyarwanda",           "rw" },
1207     { "Kirghiz",               "ky" },
1208     { "Korean",                "ko" },
1209     { "Kurdish",               "ku" },
1210     { "Latin",                 "la" },
1211     { "Latvian",               "lv" },
1212     { "Lithuanian",            "lt" },
1213     { "Macedonian",            "mk" },
1214     { "Malagasy",              "mg" },
1215     { "Malay",                 "ms" },
1216     { "Malayalam",             "ml" },
1217     { "Maltese",               "mt" },
1218     { "Manx",                  "gv" },
1219     { "Marathi",               "mr" },
1220     { "Moldavian",             "mo" },
1221     { "Mongolian",             "mn" },
1222     { "Nepali",                "ne" },
1223     { "Norwegian",             "nb" }, /* Yes, "nb", not the obsolete "no".  */
1224     { "Nyanja",                "ny" },
1225     { "Nynorsk",               "nn" },
1226     { "Oriya",                 "or" },
1227     { "Oromo",                 "om" },
1228     { "Panjabi",               "pa" },
1229     { "Pashto",                "ps" },
1230     { "Persian",               "fa" },
1231     { "Polish",                "pl" },
1232     { "Portuguese",            "pt" },
1233     { "Portuguese, Brazilian", "pt_BR" },
1234     { "Punjabi",               "pa" },
1235     { "Pushto",                "ps" },
1236     { "Quechua",               "qu" },
1237     { "Romanian",              "ro" },
1238     { "Ruanda",                "rw" },
1239     { "Rundi",                 "rn" },
1240     { "Russian",               "ru" },
1241     { "Sami",                  "se_NO" }, /* Not just "se".  */
1242     { "Sanskrit",              "sa" },
1243     { "Scottish",              "gd" },
1244     { "Serbian",               "sr" },
1245     { "Simplified Chinese",    "zh_CN" },
1246     { "Sindhi",                "sd" },
1247     { "Sinhalese",             "si" },
1248     { "Slovak",                "sk" },
1249     { "Slovenian",             "sl" },
1250     { "Somali",                "so" },
1251     { "Spanish",               "es" },
1252     { "Sundanese",             "su" },
1253     { "Swahili",               "sw" },
1254     { "Swedish",               "sv" },
1255     { "Tagalog",               "tl" },
1256     { "Tajik",                 "tg" },
1257     { "Tajiki",                "tg" },
1258     { "Tamil",                 "ta" },
1259     { "Tatar",                 "tt" },
1260     { "Telugu",                "te" },
1261     { "Thai",                  "th" },
1262     { "Tibetan",               "bo" },
1263     { "Tigrinya",              "ti" },
1264     { "Tongan",                "to" },
1265     { "Traditional Chinese",   "zh_TW" },
1266     { "Turkish",               "tr" },
1267     { "Turkmen",               "tk" },
1268     { "Uighur",                "ug" },
1269     { "Ukrainian",             "uk" },
1270     { "Urdu",                  "ur" },
1271     { "Uzbek",                 "uz" },
1272     { "Vietnamese",            "vi" },
1273     { "Welsh",                 "cy" },
1274     { "Yiddish",               "yi" }
1275   };
1276
1277   /* Convert new-style locale names with language tags (ISO 639 and ISO 15924)
1278      to Unix (ISO 639 and ISO 3166) names.  */
1279   typedef struct { const char langtag[7+1]; const char unixy[12+1]; }
1280           langtag_entry;
1281   static const langtag_entry langtag_table[] = {
1282     /* MacOS X has "az-Arab", "az-Cyrl", "az-Latn".
1283        The default script for az on Unix is Latin.  */
1284     { "az-Latn", "az" },
1285     /* MacOS X has "ga-dots".  Does not yet exist on Unix.  */
1286     { "ga-dots", "ga" },
1287     /* MacOS X has "kk-Cyrl".  Does not yet exist on Unix.  */
1288     /* MacOS X has "mn-Cyrl", "mn-Mong".
1289        The default script for mn on Unix is Cyrillic.  */
1290     { "mn-Cyrl", "mn" },
1291     /* MacOS X has "ms-Arab", "ms-Latn".
1292        The default script for ms on Unix is Latin.  */
1293     { "ms-Latn", "ms" },
1294     /* MacOS X has "tg-Cyrl".
1295        The default script for tg on Unix is Cyrillic.  */
1296     { "tg-Cyrl", "tg" },
1297     /* MacOS X has "tk-Cyrl".  Does not yet exist on Unix.  */
1298     /* MacOS X has "tt-Cyrl".
1299        The default script for tt on Unix is Cyrillic.  */
1300     { "tt-Cyrl", "tt" },
1301     /* MacOS X has "zh-Hans", "zh-Hant".
1302        Country codes are used to distinguish these on Unix.  */
1303     { "zh-Hans", "zh_CN" },
1304     { "zh-Hant", "zh_TW" }
1305   };
1306
1307   /* Convert script names (ISO 15924) to Unix conventions.
1308      See http://www.unicode.org/iso15924/iso15924-codes.html  */
1309   typedef struct { const char script[4+1]; const char unixy[9+1]; }
1310           script_entry;
1311   static const script_entry script_table[] = {
1312     { "Arab", "arabic" },
1313     { "Cyrl", "cyrillic" },
1314     { "Mong", "mongolian" }
1315   };
1316
1317   /* Step 1: Convert using legacy_table.  */
1318   if (name[0] >= 'A' && name[0] <= 'Z')
1319     {
1320       unsigned int i1, i2;
1321       i1 = 0;
1322       i2 = sizeof (legacy_table) / sizeof (legacy_entry);
1323       while (i2 - i1 > 1)
1324         {
1325           /* At this point we know that if name occurs in legacy_table,
1326              its index must be >= i1 and < i2.  */
1327           unsigned int i = (i1 + i2) >> 1;
1328           const legacy_entry *p = &legacy_table[i];
1329           if (strcmp (name, p->legacy) < 0)
1330             i2 = i;
1331           else
1332             i1 = i;
1333         }
1334       if (strcmp (name, legacy_table[i1].legacy) == 0)
1335         {
1336           strcpy (name, legacy_table[i1].unixy);
1337           return;
1338         }
1339     }
1340
1341   /* Step 2: Convert using langtag_table and script_table.  */
1342   if (strlen (name) == 7 && name[2] == '-')
1343     {
1344       unsigned int i1, i2;
1345       i1 = 0;
1346       i2 = sizeof (langtag_table) / sizeof (langtag_entry);
1347       while (i2 - i1 > 1)
1348         {
1349           /* At this point we know that if name occurs in langtag_table,
1350              its index must be >= i1 and < i2.  */
1351           unsigned int i = (i1 + i2) >> 1;
1352           const langtag_entry *p = &langtag_table[i];
1353           if (strcmp (name, p->langtag) < 0)
1354             i2 = i;
1355           else
1356             i1 = i;
1357         }
1358       if (strcmp (name, langtag_table[i1].langtag) == 0)
1359         {
1360           strcpy (name, langtag_table[i1].unixy);
1361           return;
1362         }
1363
1364       i1 = 0;
1365       i2 = sizeof (script_table) / sizeof (script_entry);
1366       while (i2 - i1 > 1)
1367         {
1368           /* At this point we know that if (name + 3) occurs in script_table,
1369              its index must be >= i1 and < i2.  */
1370           unsigned int i = (i1 + i2) >> 1;
1371           const script_entry *p = &script_table[i];
1372           if (strcmp (name + 3, p->script) < 0)
1373             i2 = i;
1374           else
1375             i1 = i;
1376         }
1377       if (strcmp (name + 3, script_table[i1].script) == 0)
1378         {
1379           name[2] = '@';
1380           strcpy (name + 3, script_table[i1].unixy);
1381           return;
1382         }
1383     }
1384
1385   /* Step 3: Convert new-style dash to Unix underscore. */
1386   {
1387     char *p;
1388     for (p = name; *p != '\0'; p++)
1389       if (*p == '-')
1390         *p = '_';
1391   }
1392 }
1393
1394 #endif
1395
1396
1397 #if defined WIN32_NATIVE || defined __CYGWIN__ /* WIN32 or Cygwin */
1398
1399 /* Canonicalize a Win32 native locale name to a Unix locale name.
1400    NAME is a sufficiently large buffer.
1401    On input, it contains the Win32 locale name.
1402    On output, it contains the Unix locale name.  */
1403 # if !defined IN_LIBINTL
1404 static
1405 # endif
1406 void
1407 gl_locale_name_canonicalize (char *name)
1408 {
1409   /* FIXME: This is probably incomplete: it does not handle "zh-Hans" and
1410      "zh-Hant".  */
1411   char *p;
1412
1413   for (p = name; *p != '\0'; p++)
1414     if (*p == '-')
1415       {
1416         *p = '_';
1417         p++;
1418         for (; *p != '\0'; p++)
1419           {
1420             if (*p >= 'a' && *p <= 'z')
1421               *p += 'A' - 'a';
1422             if (*p == '-')
1423               {
1424                 *p = '\0';
1425                 return;
1426               }
1427           }
1428         return;
1429       }
1430 }
1431
1432 # if !defined IN_LIBINTL
1433 static
1434 # endif
1435 const char *
1436 gl_locale_name_from_win32_LANGID (LANGID langid)
1437 {
1438   /* Activate the new code only when the GETTEXT_MUI environment variable is
1439      set, for the time being, since the new code is not well tested.  */
1440   if (getenv ("GETTEXT_MUI") != NULL)
1441     {
1442       static char namebuf[256];
1443
1444       /* Query the system's notion of locale name.
1445          On Windows95/98/ME, GetLocaleInfoA returns some incorrect results.
1446          But we don't need to support systems that are so old.  */
1447       if (GetLocaleInfoA (MAKELCID (langid, SORT_DEFAULT), LOCALE_SNAME,
1448                           namebuf, sizeof (namebuf) - 1))
1449         {
1450           /* Convert it to a Unix locale name.  */
1451           gl_locale_name_canonicalize (namebuf);
1452           return namebuf;
1453         }
1454     }
1455   /* Internet Explorer has an LCID to RFC3066 name mapping stored in
1456      HKEY_CLASSES_ROOT\Mime\Database\Rfc1766.  But we better don't use that
1457      since IE's i18n subsystem is known to be inconsistent with the Win32 base
1458      (e.g. they have different character conversion facilities that produce
1459      different results).  */
1460   /* Use our own table.  */
1461   {
1462     int primary, sub;
1463
1464     /* Split into language and territory part.  */
1465     primary = PRIMARYLANGID (langid);
1466     sub = SUBLANGID (langid);
1467
1468     /* Dispatch on language.
1469        See also http://www.unicode.org/unicode/onlinedat/languages.html .
1470        For details about languages, see http://www.ethnologue.com/ .  */
1471     switch (primary)
1472       {
1473       case LANG_AFRIKAANS:
1474         switch (sub)
1475           {
1476           case SUBLANG_AFRIKAANS_SOUTH_AFRICA: return "af_ZA";
1477           }
1478         return "af";
1479       case LANG_ALBANIAN:
1480         switch (sub)
1481           {
1482           case SUBLANG_ALBANIAN_ALBANIA: return "sq_AL";
1483           }
1484         return "sq";
1485       case LANG_ALSATIAN:
1486         switch (sub)
1487           {
1488           case SUBLANG_ALSATIAN_FRANCE: return "gsw_FR";
1489           }
1490         return "gsw";
1491       case LANG_AMHARIC:
1492         switch (sub)
1493           {
1494           case SUBLANG_AMHARIC_ETHIOPIA: return "am_ET";
1495           }
1496         return "am";
1497       case LANG_ARABIC:
1498         switch (sub)
1499           {
1500           case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA";
1501           case SUBLANG_ARABIC_IRAQ: return "ar_IQ";
1502           case SUBLANG_ARABIC_EGYPT: return "ar_EG";
1503           case SUBLANG_ARABIC_LIBYA: return "ar_LY";
1504           case SUBLANG_ARABIC_ALGERIA: return "ar_DZ";
1505           case SUBLANG_ARABIC_MOROCCO: return "ar_MA";
1506           case SUBLANG_ARABIC_TUNISIA: return "ar_TN";
1507           case SUBLANG_ARABIC_OMAN: return "ar_OM";
1508           case SUBLANG_ARABIC_YEMEN: return "ar_YE";
1509           case SUBLANG_ARABIC_SYRIA: return "ar_SY";
1510           case SUBLANG_ARABIC_JORDAN: return "ar_JO";
1511           case SUBLANG_ARABIC_LEBANON: return "ar_LB";
1512           case SUBLANG_ARABIC_KUWAIT: return "ar_KW";
1513           case SUBLANG_ARABIC_UAE: return "ar_AE";
1514           case SUBLANG_ARABIC_BAHRAIN: return "ar_BH";
1515           case SUBLANG_ARABIC_QATAR: return "ar_QA";
1516           }
1517         return "ar";
1518       case LANG_ARMENIAN:
1519         switch (sub)
1520           {
1521           case SUBLANG_ARMENIAN_ARMENIA: return "hy_AM";
1522           }
1523         return "hy";
1524       case LANG_ASSAMESE:
1525         switch (sub)
1526           {
1527           case SUBLANG_ASSAMESE_INDIA: return "as_IN";
1528           }
1529         return "as";
1530       case LANG_AZERI:
1531         switch (sub)
1532           {
1533           /* FIXME: Adjust this when Azerbaijani locales appear on Unix.  */
1534           case 0x1e: return "az@latin";
1535           case SUBLANG_AZERI_LATIN: return "az_AZ@latin";
1536           case 0x1d: return "az@cyrillic";
1537           case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic";
1538           }
1539         return "az";
1540       case LANG_BASHKIR:
1541         switch (sub)
1542           {
1543           case SUBLANG_BASHKIR_RUSSIA: return "ba_RU";
1544           }
1545         return "ba";
1546       case LANG_BASQUE:
1547         switch (sub)
1548           {
1549           case SUBLANG_BASQUE_BASQUE: return "eu_ES";
1550           }
1551         return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR".  */
1552       case LANG_BELARUSIAN:
1553         switch (sub)
1554           {
1555           case SUBLANG_BELARUSIAN_BELARUS: return "be_BY";
1556           }
1557         return "be";
1558       case LANG_BENGALI:
1559         switch (sub)
1560           {
1561           case SUBLANG_BENGALI_INDIA: return "bn_IN";
1562           case SUBLANG_BENGALI_BANGLADESH: return "bn_BD";
1563           }
1564         return "bn";
1565       case LANG_BRETON:
1566         switch (sub)
1567           {
1568           case SUBLANG_BRETON_FRANCE: return "br_FR";
1569           }
1570         return "br";
1571       case LANG_BULGARIAN:
1572         switch (sub)
1573           {
1574           case SUBLANG_BULGARIAN_BULGARIA: return "bg_BG";
1575           }
1576         return "bg";
1577       case LANG_BURMESE:
1578         switch (sub)
1579           {
1580           case SUBLANG_DEFAULT: return "my_MM";
1581           }
1582         return "my";
1583       case LANG_CAMBODIAN:
1584         switch (sub)
1585           {
1586           case SUBLANG_CAMBODIAN_CAMBODIA: return "km_KH";
1587           }
1588         return "km";
1589       case LANG_CATALAN:
1590         switch (sub)
1591           {
1592           case SUBLANG_CATALAN_SPAIN: return "ca_ES";
1593           }
1594         return "ca";
1595       case LANG_CHEROKEE:
1596         switch (sub)
1597           {
1598           case SUBLANG_DEFAULT: return "chr_US";
1599           }
1600         return "chr";
1601       case LANG_CHINESE:
1602         switch (sub)
1603           {
1604           case SUBLANG_CHINESE_TRADITIONAL: case 0x1f: return "zh_TW";
1605           case SUBLANG_CHINESE_SIMPLIFIED: case 0x00: return "zh_CN";
1606           case SUBLANG_CHINESE_HONGKONG: return "zh_HK"; /* traditional */
1607           case SUBLANG_CHINESE_SINGAPORE: return "zh_SG"; /* simplified */
1608           case SUBLANG_CHINESE_MACAU: return "zh_MO"; /* traditional */
1609           }
1610         return "zh";
1611       case LANG_CORSICAN:
1612         switch (sub)
1613           {
1614           case SUBLANG_CORSICAN_FRANCE: return "co_FR";
1615           }
1616         return "co";
1617       case LANG_CROATIAN:      /* LANG_CROATIAN == LANG_SERBIAN == LANG_BOSNIAN
1618                                 * What used to be called Serbo-Croatian
1619                                 * should really now be two separate
1620                                 * languages because of political reasons.
1621                                 * (Says tml, who knows nothing about Serbian
1622                                 * or Croatian.)
1623                                 * (I can feel those flames coming already.)
1624                                 */
1625         switch (sub)
1626           {
1627           /* Croatian */
1628           case 0x00: return "hr";
1629           case SUBLANG_CROATIAN_CROATIA: return "hr_HR";
1630           case SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN: return "hr_BA";
1631           /* Serbian */
1632           case 0x1f: return "sr";
1633           case 0x1c: return "sr"; /* latin */
1634           case SUBLANG_SERBIAN_LATIN: return "sr_CS"; /* latin */
1635           case 0x09: return "sr_RS"; /* latin */
1636           case 0x0b: return "sr_ME"; /* latin */
1637           case 0x06: return "sr_BA"; /* latin */
1638           case 0x1b: return "sr@cyrillic";
1639           case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic";
1640           case 0x0a: return "sr_RS@cyrillic";
1641           case 0x0c: return "sr_ME@cyrillic";
1642           case 0x07: return "sr_BA@cyrillic";
1643           /* Bosnian */
1644           case 0x1e: return "bs";
1645           case 0x1a: return "bs"; /* latin */
1646           case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN: return "bs_BA"; /* latin */
1647           case 0x19: return "bs@cyrillic";
1648           case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC: return "bs_BA@cyrillic";
1649           }
1650         return "hr";
1651       case LANG_CZECH:
1652         switch (sub)
1653           {
1654           case SUBLANG_CZECH_CZECH_REPUBLIC: return "cs_CZ";
1655           }
1656         return "cs";
1657       case LANG_DANISH:
1658         switch (sub)
1659           {
1660           case SUBLANG_DANISH_DENMARK: return "da_DK";
1661           }
1662         return "da";
1663       case LANG_DARI:
1664         /* FIXME: Adjust this when such locales appear on Unix.  */
1665         switch (sub)
1666           {
1667           case SUBLANG_DARI_AFGHANISTAN: return "prs_AF";
1668           }
1669         return "prs";
1670       case LANG_DIVEHI:
1671         switch (sub)
1672           {
1673           case SUBLANG_DIVEHI_MALDIVES: return "dv_MV";
1674           }
1675         return "dv";
1676       case LANG_DUTCH:
1677         switch (sub)
1678           {
1679           case SUBLANG_DUTCH: return "nl_NL";
1680           case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE";
1681           case SUBLANG_DUTCH_SURINAM: return "nl_SR";
1682           }
1683         return "nl";
1684       case LANG_EDO:
1685         switch (sub)
1686           {
1687           case SUBLANG_DEFAULT: return "bin_NG";
1688           }
1689         return "bin";
1690       case LANG_ENGLISH:
1691         switch (sub)
1692           {
1693           /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought
1694            * English was the language spoken in England.
1695            * Oh well.
1696            */
1697           case SUBLANG_ENGLISH_US: return "en_US";
1698           case SUBLANG_ENGLISH_UK: return "en_GB";
1699           case SUBLANG_ENGLISH_AUS: return "en_AU";
1700           case SUBLANG_ENGLISH_CAN: return "en_CA";
1701           case SUBLANG_ENGLISH_NZ: return "en_NZ";
1702           case SUBLANG_ENGLISH_EIRE: return "en_IE";
1703           case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA";
1704           case SUBLANG_ENGLISH_JAMAICA: return "en_JM";
1705           case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */
1706           case SUBLANG_ENGLISH_BELIZE: return "en_BZ";
1707           case SUBLANG_ENGLISH_TRINIDAD: return "en_TT";
1708           case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW";
1709           case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH";
1710           case SUBLANG_ENGLISH_INDONESIA: return "en_ID";
1711           case SUBLANG_ENGLISH_HONGKONG: return "en_HK";
1712           case SUBLANG_ENGLISH_INDIA: return "en_IN";
1713           case SUBLANG_ENGLISH_MALAYSIA: return "en_MY";
1714           case SUBLANG_ENGLISH_SINGAPORE: return "en_SG";
1715           }
1716         return "en";
1717       case LANG_ESTONIAN:
1718         switch (sub)
1719           {
1720           case SUBLANG_ESTONIAN_ESTONIA: return "et_EE";
1721           }
1722         return "et";
1723       case LANG_FAEROESE:
1724         switch (sub)
1725           {
1726           case SUBLANG_FAEROESE_FAROE_ISLANDS: return "fo_FO";
1727           }
1728         return "fo";
1729       case LANG_FARSI:
1730         switch (sub)
1731           {
1732           case SUBLANG_FARSI_IRAN: return "fa_IR";
1733           }
1734         return "fa";
1735       case LANG_FINNISH:
1736         switch (sub)
1737           {
1738           case SUBLANG_FINNISH_FINLAND: return "fi_FI";
1739           }
1740         return "fi";
1741       case LANG_FRENCH:
1742         switch (sub)
1743           {
1744           case SUBLANG_FRENCH: return "fr_FR";
1745           case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE";
1746           case SUBLANG_FRENCH_CANADIAN: return "fr_CA";
1747           case SUBLANG_FRENCH_SWISS: return "fr_CH";
1748           case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU";
1749           case SUBLANG_FRENCH_MONACO: return "fr_MC";
1750           case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */
1751           case SUBLANG_FRENCH_REUNION: return "fr_RE";
1752           case SUBLANG_FRENCH_CONGO: return "fr_CG";
1753           case SUBLANG_FRENCH_SENEGAL: return "fr_SN";
1754           case SUBLANG_FRENCH_CAMEROON: return "fr_CM";
1755           case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI";
1756           case SUBLANG_FRENCH_MALI: return "fr_ML";
1757           case SUBLANG_FRENCH_MOROCCO: return "fr_MA";
1758           case SUBLANG_FRENCH_HAITI: return "fr_HT";
1759           }
1760         return "fr";
1761       case LANG_FRISIAN:
1762         switch (sub)
1763           {
1764           case SUBLANG_FRISIAN_NETHERLANDS: return "fy_NL";
1765           }
1766         return "fy";
1767       case LANG_FULFULDE:
1768         /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin.  */
1769         switch (sub)
1770           {
1771           case SUBLANG_DEFAULT: return "ff_NG";
1772           }
1773         return "ff";
1774       case LANG_GAELIC:
1775         switch (sub)
1776           {
1777           case 0x01: /* SCOTTISH */
1778             /* old, superseded by LANG_SCOTTISH_GAELIC */
1779             return "gd_GB";
1780           case SUBLANG_IRISH_IRELAND: return "ga_IE";
1781           }
1782         return "ga";
1783       case LANG_GALICIAN:
1784         switch (sub)
1785           {
1786           case SUBLANG_GALICIAN_SPAIN: return "gl_ES";
1787           }
1788         return "gl";
1789       case LANG_GEORGIAN:
1790         switch (sub)
1791           {
1792           case SUBLANG_GEORGIAN_GEORGIA: return "ka_GE";
1793           }
1794         return "ka";
1795       case LANG_GERMAN:
1796         switch (sub)
1797           {
1798           case SUBLANG_GERMAN: return "de_DE";
1799           case SUBLANG_GERMAN_SWISS: return "de_CH";
1800           case SUBLANG_GERMAN_AUSTRIAN: return "de_AT";
1801           case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU";
1802           case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI";
1803           }
1804         return "de";
1805       case LANG_GREEK:
1806         switch (sub)
1807           {
1808           case SUBLANG_GREEK_GREECE: return "el_GR";
1809           }
1810         return "el";
1811       case LANG_GREENLANDIC:
1812         switch (sub)
1813           {
1814           case SUBLANG_GREENLANDIC_GREENLAND: return "kl_GL";
1815           }
1816         return "kl";
1817       case LANG_GUARANI:
1818         switch (sub)
1819           {
1820           case SUBLANG_DEFAULT: return "gn_PY";
1821           }
1822         return "gn";
1823       case LANG_GUJARATI:
1824         switch (sub)
1825           {
1826           case SUBLANG_GUJARATI_INDIA: return "gu_IN";
1827           }
1828         return "gu";
1829       case LANG_HAUSA:
1830         switch (sub)
1831           {
1832           case 0x1f: return "ha";
1833           case SUBLANG_HAUSA_NIGERIA_LATIN: return "ha_NG";
1834           }
1835         return "ha";
1836       case LANG_HAWAIIAN:
1837         /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers)
1838            or Hawaii Creole English ("cpe_US", 600000 speakers)?  */
1839         switch (sub)
1840           {
1841           case SUBLANG_DEFAULT: return "cpe_US";
1842           }
1843         return "cpe";
1844       case LANG_HEBREW:
1845         switch (sub)
1846           {
1847           case SUBLANG_HEBREW_ISRAEL: return "he_IL";
1848           }
1849         return "he";
1850       case LANG_HINDI:
1851         switch (sub)
1852           {
1853           case SUBLANG_HINDI_INDIA: return "hi_IN";
1854           }
1855         return "hi";
1856       case LANG_HUNGARIAN:
1857         switch (sub)
1858           {
1859           case SUBLANG_HUNGARIAN_HUNGARY: return "hu_HU";
1860           }
1861         return "hu";
1862       case LANG_IBIBIO:
1863         switch (sub)
1864           {
1865           case SUBLANG_DEFAULT: return "nic_NG";
1866           }
1867         return "nic";
1868       case LANG_ICELANDIC:
1869         switch (sub)
1870           {
1871           case SUBLANG_ICELANDIC_ICELAND: return "is_IS";
1872           }
1873         return "is";
1874       case LANG_IGBO:
1875         switch (sub)
1876           {
1877           case SUBLANG_IGBO_NIGERIA: return "ig_NG";
1878           }
1879         return "ig";
1880       case LANG_INDONESIAN:
1881         switch (sub)
1882           {
1883           case SUBLANG_INDONESIAN_INDONESIA: return "id_ID";
1884           }
1885         return "id";
1886       case LANG_INUKTITUT:
1887         switch (sub)
1888           {
1889           case 0x1e: return "iu"; /* syllabic */
1890           case SUBLANG_INUKTITUT_CANADA: return "iu_CA"; /* syllabic */
1891           case 0x1f: return "iu@latin";
1892           case SUBLANG_INUKTITUT_CANADA_LATIN: return "iu_CA@latin";
1893           }
1894         return "iu";
1895       case LANG_ITALIAN:
1896         switch (sub)
1897           {
1898           case SUBLANG_ITALIAN: return "it_IT";
1899           case SUBLANG_ITALIAN_SWISS: return "it_CH";
1900           }
1901         return "it";
1902       case LANG_JAPANESE:
1903         switch (sub)
1904           {
1905           case SUBLANG_JAPANESE_JAPAN: return "ja_JP";
1906           }
1907         return "ja";
1908       case LANG_KANNADA:
1909         switch (sub)
1910           {
1911           case SUBLANG_KANNADA_INDIA: return "kn_IN";
1912           }
1913         return "kn";
1914       case LANG_KANURI:
1915         switch (sub)
1916           {
1917           case SUBLANG_DEFAULT: return "kr_NG";
1918           }
1919         return "kr";
1920       case LANG_KASHMIRI:
1921         switch (sub)
1922           {
1923           case SUBLANG_DEFAULT: return "ks_PK";
1924           case SUBLANG_KASHMIRI_INDIA: return "ks_IN";
1925           }
1926         return "ks";
1927       case LANG_KAZAK:
1928         switch (sub)
1929           {
1930           case SUBLANG_KAZAK_KAZAKHSTAN: return "kk_KZ";
1931           }
1932         return "kk";
1933       case LANG_KICHE:
1934         /* FIXME: Adjust this when such locales appear on Unix.  */
1935         switch (sub)
1936           {
1937           case SUBLANG_KICHE_GUATEMALA: return "qut_GT";
1938           }
1939         return "qut";
1940       case LANG_KINYARWANDA:
1941         switch (sub)
1942           {
1943           case SUBLANG_KINYARWANDA_RWANDA: return "rw_RW";
1944           }
1945         return "rw";
1946       case LANG_KONKANI:
1947         /* FIXME: Adjust this when such locales appear on Unix.  */
1948         switch (sub)
1949           {
1950           case SUBLANG_KONKANI_INDIA: return "kok_IN";
1951           }
1952         return "kok";
1953       case LANG_KOREAN:
1954         switch (sub)
1955           {
1956           case SUBLANG_DEFAULT: return "ko_KR";
1957           }
1958         return "ko";
1959       case LANG_KYRGYZ:
1960         switch (sub)
1961           {
1962           case SUBLANG_KYRGYZ_KYRGYZSTAN: return "ky_KG";
1963           }
1964         return "ky";
1965       case LANG_LAO:
1966         switch (sub)
1967           {
1968           case SUBLANG_LAO_LAOS: return "lo_LA";
1969           }
1970         return "lo";
1971       case LANG_LATIN:
1972         switch (sub)
1973           {
1974           case SUBLANG_DEFAULT: return "la_VA";
1975           }
1976         return "la";
1977       case LANG_LATVIAN:
1978         switch (sub)
1979           {
1980           case SUBLANG_LATVIAN_LATVIA: return "lv_LV";
1981           }
1982         return "lv";
1983       case LANG_LITHUANIAN:
1984         switch (sub)
1985           {
1986           case SUBLANG_LITHUANIAN_LITHUANIA: return "lt_LT";
1987           }
1988         return "lt";
1989       case LANG_LUXEMBOURGISH:
1990         switch (sub)
1991           {
1992           case SUBLANG_LUXEMBOURGISH_LUXEMBOURG: return "lb_LU";
1993           }
1994         return "lb";
1995       case LANG_MACEDONIAN:
1996         switch (sub)
1997           {
1998           case SUBLANG_MACEDONIAN_MACEDONIA: return "mk_MK";
1999           }
2000         return "mk";
2001       case LANG_MALAY:
2002         switch (sub)
2003           {
2004           case SUBLANG_MALAY_MALAYSIA: return "ms_MY";
2005           case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN";
2006           }
2007         return "ms";
2008       case LANG_MALAYALAM:
2009         switch (sub)
2010           {
2011           case SUBLANG_MALAYALAM_INDIA: return "ml_IN";
2012           }
2013         return "ml";
2014       case LANG_MALTESE:
2015         switch (sub)
2016           {
2017           case SUBLANG_MALTESE_MALTA: return "mt_MT";
2018           }
2019         return "mt";
2020       case LANG_MANIPURI:
2021         /* FIXME: Adjust this when such locales appear on Unix.  */
2022         switch (sub)
2023           {
2024           case SUBLANG_DEFAULT: return "mni_IN";
2025           }
2026         return "mni";
2027       case LANG_MAORI:
2028         switch (sub)
2029           {
2030           case SUBLANG_MAORI_NEW_ZEALAND: return "mi_NZ";
2031           }
2032         return "mi";
2033       case LANG_MAPUDUNGUN:
2034         switch (sub)
2035           {
2036           case SUBLANG_MAPUDUNGUN_CHILE: return "arn_CL";
2037           }
2038         return "arn";
2039       case LANG_MARATHI:
2040         switch (sub)
2041           {
2042           case SUBLANG_MARATHI_INDIA: return "mr_IN";
2043           }
2044         return "mr";
2045       case LANG_MOHAWK:
2046         switch (sub)
2047           {
2048           case SUBLANG_MOHAWK_CANADA: return "moh_CA";
2049           }
2050         return "moh";
2051       case LANG_MONGOLIAN:
2052         switch (sub)
2053           {
2054           case SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA: case 0x1e: return "mn_MN";
2055           case SUBLANG_MONGOLIAN_PRC: case 0x1f: return "mn_CN";
2056           }
2057         return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN".  */
2058       case LANG_NEPALI:
2059         switch (sub)
2060           {
2061           case SUBLANG_NEPALI_NEPAL: return "ne_NP";
2062           case SUBLANG_NEPALI_INDIA: return "ne_IN";
2063           }
2064         return "ne";
2065       case LANG_NORWEGIAN:
2066         switch (sub)
2067           {
2068           case 0x1f: return "nb";
2069           case SUBLANG_NORWEGIAN_BOKMAL: return "nb_NO";
2070           case 0x1e: return "nn";
2071           case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO";
2072           }
2073         return "no";
2074       case LANG_OCCITAN:
2075         switch (sub)
2076           {
2077           case SUBLANG_OCCITAN_FRANCE: return "oc_FR";
2078           }
2079         return "oc";
2080       case LANG_ORIYA:
2081         switch (sub)
2082           {
2083           case SUBLANG_ORIYA_INDIA: return "or_IN";
2084           }
2085         return "or";
2086       case LANG_OROMO:
2087         switch (sub)
2088           {
2089           case SUBLANG_DEFAULT: return "om_ET";
2090           }
2091         return "om";
2092       case LANG_PAPIAMENTU:
2093         switch (sub)
2094           {
2095           case SUBLANG_DEFAULT: return "pap_AN";
2096           }
2097         return "pap";
2098       case LANG_PASHTO:
2099         switch (sub)
2100           {
2101           case SUBLANG_PASHTO_AFGHANISTAN: return "ps_AF";
2102           }
2103         return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF".  */
2104       case LANG_POLISH:
2105         switch (sub)
2106           {
2107           case SUBLANG_POLISH_POLAND: return "pl_PL";
2108           }
2109         return "pl";
2110       case LANG_PORTUGUESE:
2111         switch (sub)
2112           {
2113           /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT.
2114              Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */
2115           case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR";
2116           case SUBLANG_PORTUGUESE: return "pt_PT";
2117           }
2118         return "pt";
2119       case LANG_PUNJABI:
2120         switch (sub)
2121           {
2122           case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */
2123           case SUBLANG_PUNJABI_PAKISTAN: return "pa_PK"; /* Arabic script */
2124           }
2125         return "pa";
2126       case LANG_QUECHUA:
2127         /* Note: Microsoft uses the non-ISO language code "quz".  */
2128         switch (sub)
2129           {
2130           case SUBLANG_QUECHUA_BOLIVIA: return "qu_BO";
2131           case SUBLANG_QUECHUA_ECUADOR: return "qu_EC";
2132           case SUBLANG_QUECHUA_PERU: return "qu_PE";
2133           }
2134         return "qu";
2135       case LANG_ROMANIAN:
2136         switch (sub)
2137           {
2138           case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO";
2139           case SUBLANG_ROMANIAN_MOLDOVA: return "ro_MD";
2140           }
2141         return "ro";
2142       case LANG_ROMANSH:
2143         switch (sub)
2144           {
2145           case SUBLANG_ROMANSH_SWITZERLAND: return "rm_CH";
2146           }
2147         return "rm";
2148       case LANG_RUSSIAN:
2149         switch (sub)
2150           {
2151           case SUBLANG_RUSSIAN_RUSSIA: return "ru_RU";
2152           case SUBLANG_RUSSIAN_MOLDAVIA: return "ru_MD";
2153           }
2154         return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD".  */
2155       case LANG_SAMI:
2156         switch (sub)
2157           {
2158           /* Northern Sami */
2159           case 0x00: return "se";
2160           case SUBLANG_SAMI_NORTHERN_NORWAY: return "se_NO";
2161           case SUBLANG_SAMI_NORTHERN_SWEDEN: return "se_SE";
2162           case SUBLANG_SAMI_NORTHERN_FINLAND: return "se_FI";
2163           /* Lule Sami */
2164           case 0x1f: return "smj";
2165           case SUBLANG_SAMI_LULE_NORWAY: return "smj_NO";
2166           case SUBLANG_SAMI_LULE_SWEDEN: return "smj_SE";
2167           /* Southern Sami */
2168           case 0x1e: return "sma";
2169           case SUBLANG_SAMI_SOUTHERN_NORWAY: return "sma_NO";
2170           case SUBLANG_SAMI_SOUTHERN_SWEDEN: return "sma_SE";
2171           /* Skolt Sami */
2172           case 0x1d: return "sms";
2173           case SUBLANG_SAMI_SKOLT_FINLAND: return "sms_FI";
2174           /* Inari Sami */
2175           case 0x1c: return "smn";
2176           case SUBLANG_SAMI_INARI_FINLAND: return "smn_FI";
2177           }
2178         return "se"; /* or "smi"? */
2179       case LANG_SANSKRIT:
2180         switch (sub)
2181           {
2182           case SUBLANG_SANSKRIT_INDIA: return "sa_IN";
2183           }
2184         return "sa";
2185       case LANG_SCOTTISH_GAELIC:
2186         switch (sub)
2187           {
2188           case SUBLANG_DEFAULT: return "gd_GB";
2189           }
2190         return "gd";
2191       case LANG_SINDHI:
2192         switch (sub)
2193           {
2194           case SUBLANG_SINDHI_INDIA: return "sd_IN";
2195           case SUBLANG_SINDHI_PAKISTAN: return "sd_PK";
2196           /*case SUBLANG_SINDHI_AFGHANISTAN: return "sd_AF";*/
2197           }
2198         return "sd";
2199       case LANG_SINHALESE:
2200         switch (sub)
2201           {
2202           case SUBLANG_SINHALESE_SRI_LANKA: return "si_LK";
2203           }
2204         return "si";
2205       case LANG_SLOVAK:
2206         switch (sub)
2207           {
2208           case SUBLANG_SLOVAK_SLOVAKIA: return "sk_SK";
2209           }
2210         return "sk";
2211       case LANG_SLOVENIAN:
2212         switch (sub)
2213           {
2214           case SUBLANG_SLOVENIAN_SLOVENIA: return "sl_SI";
2215           }
2216         return "sl";
2217       case LANG_SOMALI:
2218         switch (sub)
2219           {
2220           case SUBLANG_DEFAULT: return "so_SO";
2221           }
2222         return "so";
2223       case LANG_SORBIAN:
2224         /* FIXME: Adjust this when such locales appear on Unix.  */
2225         switch (sub)
2226           {
2227           /* Upper Sorbian */
2228           case 0x00: return "hsb";
2229           case SUBLANG_UPPER_SORBIAN_GERMANY: return "hsb_DE";
2230           /* Lower Sorbian */
2231           case 0x1f: return "dsb";
2232           case SUBLANG_LOWER_SORBIAN_GERMANY: return "dsb_DE";
2233           }
2234         return "wen";
2235       case LANG_SOTHO:
2236         /* <http://www.microsoft.com/globaldev/reference/lcid-all.mspx> calls
2237            it "Sepedi"; according to
2238            <http://www.ethnologue.com/show_language.asp?code=nso>
2239            <http://www.ethnologue.com/show_language.asp?code=sot>
2240            it's the same as Northern Sotho.  */
2241         switch (sub)
2242           {
2243           case SUBLANG_SOTHO_SOUTH_AFRICA: return "nso_ZA";
2244           }
2245         return "nso";
2246       case LANG_SPANISH:
2247         switch (sub)
2248           {
2249           case SUBLANG_SPANISH: return "es_ES";
2250           case SUBLANG_SPANISH_MEXICAN: return "es_MX";
2251           case SUBLANG_SPANISH_MODERN:
2252             return "es_ES@modern";      /* not seen on Unix */
2253           case SUBLANG_SPANISH_GUATEMALA: return "es_GT";
2254           case SUBLANG_SPANISH_COSTA_RICA: return "es_CR";
2255           case SUBLANG_SPANISH_PANAMA: return "es_PA";
2256           case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO";
2257           case SUBLANG_SPANISH_VENEZUELA: return "es_VE";
2258           case SUBLANG_SPANISH_COLOMBIA: return "es_CO";
2259           case SUBLANG_SPANISH_PERU: return "es_PE";
2260           case SUBLANG_SPANISH_ARGENTINA: return "es_AR";
2261           case SUBLANG_SPANISH_ECUADOR: return "es_EC";
2262           case SUBLANG_SPANISH_CHILE: return "es_CL";
2263           case SUBLANG_SPANISH_URUGUAY: return "es_UY";
2264           case SUBLANG_SPANISH_PARAGUAY: return "es_PY";
2265           case SUBLANG_SPANISH_BOLIVIA: return "es_BO";
2266           case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV";
2267           case SUBLANG_SPANISH_HONDURAS: return "es_HN";
2268           case SUBLANG_SPANISH_NICARAGUA: return "es_NI";
2269           case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR";
2270           case SUBLANG_SPANISH_US: return "es_US";
2271           }
2272         return "es";
2273       case LANG_SUTU:
2274         switch (sub)
2275           {
2276           case SUBLANG_DEFAULT: return "bnt_TZ"; /* or "st_LS" or "nso_ZA"? */
2277           }
2278         return "bnt";
2279       case LANG_SWAHILI:
2280         switch (sub)
2281           {
2282           case SUBLANG_SWAHILI_KENYA: return "sw_KE";
2283           }
2284         return "sw";
2285       case LANG_SWEDISH:
2286         switch (sub)
2287           {
2288           case SUBLANG_SWEDISH_SWEDEN: return "sv_SE";
2289           case SUBLANG_SWEDISH_FINLAND: return "sv_FI";
2290           }
2291         return "sv";
2292       case LANG_SYRIAC:
2293         switch (sub)
2294           {
2295           case SUBLANG_SYRIAC_SYRIA: return "syr_SY"; /* An extinct language.  */
2296           }
2297         return "syr";
2298       case LANG_TAGALOG:
2299         switch (sub)
2300           {
2301           case SUBLANG_TAGALOG_PHILIPPINES: return "tl_PH"; /* or "fil_PH"? */
2302           }
2303         return "tl"; /* or "fil"? */
2304       case LANG_TAJIK:
2305         switch (sub)
2306           {
2307           case 0x1f: return "tg";
2308           case SUBLANG_TAJIK_TAJIKISTAN: return "tg_TJ";
2309           }
2310         return "tg";
2311       case LANG_TAMAZIGHT:
2312         /* Note: Microsoft uses the non-ISO language code "tmz".  */
2313         switch (sub)
2314           {
2315           /* FIXME: Adjust this when Tamazight locales appear on Unix.  */
2316           case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic";
2317           case 0x1f: return "ber@latin";
2318           case SUBLANG_TAMAZIGHT_ALGERIA_LATIN: return "ber_DZ@latin";
2319           }
2320         return "ber";
2321       case LANG_TAMIL:
2322         switch (sub)
2323           {
2324           case SUBLANG_TAMIL_INDIA: return "ta_IN";
2325           }
2326         return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG".  */
2327       case LANG_TATAR:
2328         switch (sub)
2329           {
2330           case SUBLANG_TATAR_RUSSIA: return "tt_RU";
2331           }
2332         return "tt";
2333       case LANG_TELUGU:
2334         switch (sub)
2335           {
2336           case SUBLANG_TELUGU_INDIA: return "te_IN";
2337           }
2338         return "te";
2339       case LANG_THAI:
2340         switch (sub)
2341           {
2342           case SUBLANG_THAI_THAILAND: return "th_TH";
2343           }
2344         return "th";
2345       case LANG_TIBETAN:
2346         switch (sub)
2347           {
2348           case SUBLANG_TIBETAN_PRC:
2349             /* Most Tibetans would not like "bo_CN".  But Tibet does not yet
2350                have a country code of its own.  */
2351             return "bo";
2352           case SUBLANG_TIBETAN_BHUTAN: return "bo_BT";
2353           }
2354         return "bo";
2355       case LANG_TIGRINYA:
2356         switch (sub)
2357           {
2358           case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET";
2359           case SUBLANG_TIGRINYA_ERITREA: return "ti_ER";
2360           }
2361         return "ti";
2362       case LANG_TSONGA:
2363         switch (sub)
2364           {
2365           case SUBLANG_DEFAULT: return "ts_ZA";
2366           }
2367         return "ts";
2368       case LANG_TSWANA:
2369         /* Spoken in South Africa, Botswana.  */
2370         switch (sub)
2371           {
2372           case SUBLANG_TSWANA_SOUTH_AFRICA: return "tn_ZA";
2373           }
2374         return "tn";
2375       case LANG_TURKISH:
2376         switch (sub)
2377           {
2378           case SUBLANG_TURKISH_TURKEY: return "tr_TR";
2379           }
2380         return "tr";
2381       case LANG_TURKMEN:
2382         switch (sub)
2383           {
2384           case SUBLANG_TURKMEN_TURKMENISTAN: return "tk_TM";
2385           }
2386         return "tk";
2387       case LANG_UIGHUR:
2388         switch (sub)
2389           {
2390           case SUBLANG_UIGHUR_PRC: return "ug_CN";
2391           }
2392         return "ug";
2393       case LANG_UKRAINIAN:
2394         switch (sub)
2395           {
2396           case SUBLANG_UKRAINIAN_UKRAINE: return "uk_UA";
2397           }
2398         return "uk";
2399       case LANG_URDU:
2400         switch (sub)
2401           {
2402           case SUBLANG_URDU_PAKISTAN: return "ur_PK";
2403           case SUBLANG_URDU_INDIA: return "ur_IN";
2404           }
2405         return "ur";
2406       case LANG_UZBEK:
2407         switch (sub)
2408           {
2409           case 0x1f: return "uz";
2410           case SUBLANG_UZBEK_LATIN: return "uz_UZ";
2411           case 0x1e: return "uz@cyrillic";
2412           case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic";
2413           }
2414         return "uz";
2415       case LANG_VENDA:
2416         switch (sub)
2417           {
2418           case SUBLANG_DEFAULT: return "ve_ZA";
2419           }
2420         return "ve";
2421       case LANG_VIETNAMESE:
2422         switch (sub)
2423           {
2424           case SUBLANG_VIETNAMESE_VIETNAM: return "vi_VN";
2425           }
2426         return "vi";
2427       case LANG_WELSH:
2428         switch (sub)
2429           {
2430           case SUBLANG_WELSH_UNITED_KINGDOM: return "cy_GB";
2431           }
2432         return "cy";
2433       case LANG_WOLOF:
2434         switch (sub)
2435           {
2436           case SUBLANG_WOLOF_SENEGAL: return "wo_SN";
2437           }
2438         return "wo";
2439       case LANG_XHOSA:
2440         switch (sub)
2441           {
2442           case SUBLANG_XHOSA_SOUTH_AFRICA: return "xh_ZA";
2443           }
2444         return "xh";
2445       case LANG_YAKUT:
2446         switch (sub)
2447           {
2448           case SUBLANG_YAKUT_RUSSIA: return "sah_RU";
2449           }
2450         return "sah";
2451       case LANG_YI:
2452         switch (sub)
2453           {
2454           case SUBLANG_YI_PRC: return "ii_CN";
2455           }
2456         return "ii";
2457       case LANG_YIDDISH:
2458         switch (sub)
2459           {
2460           case SUBLANG_DEFAULT: return "yi_IL";
2461           }
2462         return "yi";
2463       case LANG_YORUBA:
2464         switch (sub)
2465           {
2466           case SUBLANG_YORUBA_NIGERIA: return "yo_NG";
2467           }
2468         return "yo";
2469       case LANG_ZULU:
2470         switch (sub)
2471           {
2472           case SUBLANG_ZULU_SOUTH_AFRICA: return "zu_ZA";
2473           }
2474         return "zu";
2475       default: return "C";
2476       }
2477   }
2478 }
2479
2480 # if !defined IN_LIBINTL
2481 static
2482 # endif
2483 const char *
2484 gl_locale_name_from_win32_LCID (LCID lcid)
2485 {
2486   LANGID langid;
2487
2488   /* Strip off the sorting rules, keep only the language part.  */
2489   langid = LANGIDFROMLCID (lcid);
2490
2491   return gl_locale_name_from_win32_LANGID (langid);
2492 }
2493
2494 #endif
2495
2496
2497 /* XPG3 defines the result of 'setlocale (category, NULL)' as:
2498    "Directs 'setlocale()' to query 'category' and return the current
2499     setting of 'local'."
2500    However it does not specify the exact format.  Neither do SUSV2 and
2501    ISO C 99.  So we can use this feature only on selected systems (e.g.
2502    those using GNU C Library).  */
2503 #if defined _LIBC || (defined __GLIBC__ && __GLIBC__ >= 2)
2504 # define HAVE_LOCALE_NULL
2505 #endif
2506
2507 /* Determine the current locale's name, and canonicalize it into XPG syntax
2508      language[_territory][.codeset][@modifier]
2509    The codeset part in the result is not reliable; the locale_charset()
2510    should be used for codeset information instead.
2511    The result must not be freed; it is statically allocated.  */
2512
2513 const char *
2514 gl_locale_name_posix (int category, const char *categoryname)
2515 {
2516   /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
2517      On some systems this can be done by the 'setlocale' function itself.  */
2518 #if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
2519   return setlocale (category, NULL);
2520 #else
2521   /* On other systems we ignore what setlocale reports and instead look at the
2522      environment variables directly.  This is necessary
2523        1. on systems which have a facility for customizing the default locale
2524           (MacOS X, native Windows, Cygwin) and where the system's setlocale()
2525           function ignores this default locale (MacOS X, Cygwin), in two cases:
2526           a. when the user missed to use the setlocale() override from libintl
2527              (for example by not including <libintl.h>),
2528           b. when setlocale supports only the "C" locale, such as on Cygwin
2529              1.5.x.  In this case even the override from libintl cannot help.
2530        2. on all systems where setlocale supports only the "C" locale.  */
2531   /* Strictly speaking, it is a POSIX violation to look at the environment
2532      variables regardless whether setlocale has been called or not.  POSIX
2533      says:
2534          "For C-language programs, the POSIX locale shall be the
2535           default locale when the setlocale() function is not called."
2536      But we assume that all programs that use internationalized APIs call
2537      setlocale (LC_ALL, "").  */
2538   return gl_locale_name_environ (category, categoryname);
2539 #endif
2540 }
2541
2542 const char *
2543 gl_locale_name_environ (int category, const char *categoryname)
2544 {
2545   const char *retval;
2546
2547   /* Setting of LC_ALL overrides all other.  */
2548   retval = getenv ("LC_ALL");
2549   if (retval != NULL && retval[0] != '\0')
2550     return retval;
2551   /* Next comes the name of the desired category.  */
2552   retval = getenv (categoryname);
2553   if (retval != NULL && retval[0] != '\0')
2554     return retval;
2555   /* Last possibility is the LANG environment variable.  */
2556   retval = getenv ("LANG");
2557   if (retval != NULL && retval[0] != '\0')
2558     {
2559 #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
2560       /* MacOS X 10.2 or newer.
2561          Ignore invalid LANG value set by the Terminal application.  */
2562       if (strcmp (retval, "UTF-8") != 0)
2563 #endif
2564 #if defined __CYGWIN__
2565       /* Cygwin.
2566          Ignore dummy LANG value set by ~/.profile.  */
2567       if (strcmp (retval, "C.UTF-8") != 0)
2568 #endif
2569         return retval;
2570     }
2571
2572   return NULL;
2573 }
2574
2575 const char *
2576 gl_locale_name_default (void)
2577 {
2578   /* POSIX:2001 says:
2579      "All implementations shall define a locale as the default locale, to be
2580       invoked when no environment variables are set, or set to the empty
2581       string.  This default locale can be the POSIX locale or any other
2582       implementation-defined locale.  Some implementations may provide
2583       facilities for local installation administrators to set the default
2584       locale, customizing it for each location.  POSIX:2001 does not require
2585       such a facility.
2586
2587      The systems with such a facility are MacOS X and Windows: They provide a
2588      GUI that allows the user to choose a locale.
2589        - On MacOS X, by default, none of LC_* or LANG are set.  Starting with
2590          MacOS X 10.4 or 10.5, LANG is set for processes launched by the
2591          'Terminal' application (but sometimes to an incorrect value "UTF-8").
2592          When no environment variable is set, setlocale (LC_ALL, "") uses the
2593          "C" locale.
2594        - On native Windows, by default, none of LC_* or LANG are set.
2595          When no environment variable is set, setlocale (LC_ALL, "") uses the
2596          locale chosen by the user.
2597        - On Cygwin 1.5.x, by default, none of LC_* or LANG are set.
2598          When no environment variable is set, setlocale (LC_ALL, "") uses the
2599          "C" locale.
2600        - On Cygwin 1.7, by default, LANG is set to "C.UTF-8" when the default
2601          ~/.profile is executed.
2602          When no environment variable is set, setlocale (LC_ALL, "") uses the
2603          "C.UTF-8" locale, which operates in the same way as the "C" locale.
2604   */
2605
2606 #if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined WIN32_NATIVE || defined __CYGWIN__)
2607
2608   /* The system does not have a way of setting the locale, other than the
2609      POSIX specified environment variables.  We use C as default locale.  */
2610   return "C";
2611
2612 #else
2613
2614   /* Return an XPG style locale name language[_territory][@modifier].
2615      Don't even bother determining the codeset; it's not useful in this
2616      context, because message catalogs are not specific to a single
2617      codeset.  */
2618
2619 # if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
2620   /* MacOS X 10.2 or newer */
2621   {
2622     /* Cache the locale name, since CoreFoundation calls are expensive.  */
2623     static const char *cached_localename;
2624
2625     if (cached_localename == NULL)
2626       {
2627         char namebuf[256];
2628 #  if HAVE_CFLOCALECOPYCURRENT /* MacOS X 10.3 or newer */
2629         CFLocaleRef locale = CFLocaleCopyCurrent ();
2630         CFStringRef name = CFLocaleGetIdentifier (locale);
2631
2632         if (CFStringGetCString (name, namebuf, sizeof(namebuf),
2633                                 kCFStringEncodingASCII))
2634           {
2635             gl_locale_name_canonicalize (namebuf);
2636             cached_localename = strdup (namebuf);
2637           }
2638         CFRelease (locale);
2639 #  elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */
2640         CFTypeRef value =
2641           CFPreferencesCopyAppValue (CFSTR ("AppleLocale"),
2642                                      kCFPreferencesCurrentApplication);
2643         if (value != NULL
2644             && CFGetTypeID (value) == CFStringGetTypeID ()
2645             && CFStringGetCString ((CFStringRef)value, namebuf, sizeof(namebuf),
2646                                    kCFStringEncodingASCII))
2647           {
2648             gl_locale_name_canonicalize (namebuf);
2649             cached_localename = strdup (namebuf);
2650           }
2651 #  endif
2652         if (cached_localename == NULL)
2653           cached_localename = "C";
2654       }
2655     return cached_localename;
2656   }
2657
2658 # endif
2659
2660 # if defined WIN32_NATIVE || defined __CYGWIN__ /* WIN32 or Cygwin */
2661   {
2662     LCID lcid;
2663
2664     /* Use native Win32 API locale ID.  */
2665     lcid = GetThreadLocale ();
2666
2667     return gl_locale_name_from_win32_LCID (lcid);
2668   }
2669 # endif
2670 #endif
2671 }
2672
2673 const char *
2674 gl_locale_name (int category, const char *categoryname)
2675 {
2676   const char *retval;
2677
2678   retval = gl_locale_name_posix (category, categoryname);
2679   if (retval != NULL)
2680     return retval;
2681
2682   return gl_locale_name_default ();
2683 }