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