1 /* Determine name of the currently selected locale.
2 Copyright (C) 1995-2016 Free Software Foundation, Inc.
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.
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.
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/>. */
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>. */
25 # include "gettextP.h"
27 # include "localename.h"
36 #include "flexmember.h"
39 /* Mac OS X 10.5 defines the locale_t type in <xlocale.h>. */
40 # if defined __APPLE__ && defined __MACH__
43 # if __GLIBC__ >= 2 && !defined __UCLIBC__
44 # include <langinfo.h>
46 # if !defined IN_LIBINTL
47 # include "glthread/lock.h"
49 # if defined __sun && HAVE_GETLOCALENAME_L
51 extern char * getlocalename_l(int, locale_t);
55 #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
56 # include <CoreFoundation/CFString.h>
57 # if HAVE_CFLOCALECOPYCURRENT
58 # include <CoreFoundation/CFLocale.h>
59 # elif HAVE_CFPREFERENCESCOPYAPPVALUE
60 # include <CoreFoundation/CFPreferences.h>
64 #if defined _WIN32 || defined __WIN32__
65 # define WINDOWS_NATIVE
66 # if !defined IN_LIBINTL
67 # include "glthread/lock.h"
71 #if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Native Windows or Cygwin */
72 # define WIN32_LEAN_AND_MEAN
75 /* List of language codes, sorted by value:
101 0x1a LANG_CROATIAN == LANG_SERBIAN
183 0x6e LANG_LUXEMBOURGISH
184 0x6f LANG_GREENLANDIC
203 0x87 LANG_KINYARWANDA
206 0x91 LANG_SCOTTISH_GAELIC
208 /* Mingw headers don't have latest language and sublanguage codes. */
209 # ifndef LANG_AFRIKAANS
210 # define LANG_AFRIKAANS 0x36
212 # ifndef LANG_ALBANIAN
213 # define LANG_ALBANIAN 0x1c
215 # ifndef LANG_ALSATIAN
216 # define LANG_ALSATIAN 0x84
218 # ifndef LANG_AMHARIC
219 # define LANG_AMHARIC 0x5e
222 # define LANG_ARABIC 0x01
224 # ifndef LANG_ARMENIAN
225 # define LANG_ARMENIAN 0x2b
227 # ifndef LANG_ASSAMESE
228 # define LANG_ASSAMESE 0x4d
231 # define LANG_AZERI 0x2c
233 # ifndef LANG_BASHKIR
234 # define LANG_BASHKIR 0x6d
237 # define LANG_BASQUE 0x2d
239 # ifndef LANG_BELARUSIAN
240 # define LANG_BELARUSIAN 0x23
242 # ifndef LANG_BENGALI
243 # define LANG_BENGALI 0x45
246 # define LANG_BRETON 0x7e
248 # ifndef LANG_BURMESE
249 # define LANG_BURMESE 0x55
251 # ifndef LANG_CAMBODIAN
252 # define LANG_CAMBODIAN 0x53
254 # ifndef LANG_CATALAN
255 # define LANG_CATALAN 0x03
257 # ifndef LANG_CHEROKEE
258 # define LANG_CHEROKEE 0x5c
260 # ifndef LANG_CORSICAN
261 # define LANG_CORSICAN 0x83
264 # define LANG_DARI 0x8c
267 # define LANG_DIVEHI 0x65
270 # define LANG_EDO 0x66
272 # ifndef LANG_ESTONIAN
273 # define LANG_ESTONIAN 0x25
275 # ifndef LANG_FAEROESE
276 # define LANG_FAEROESE 0x38
279 # define LANG_FARSI 0x29
281 # ifndef LANG_FRISIAN
282 # define LANG_FRISIAN 0x62
284 # ifndef LANG_FULFULDE
285 # define LANG_FULFULDE 0x67
288 # define LANG_GAELIC 0x3c
290 # ifndef LANG_GALICIAN
291 # define LANG_GALICIAN 0x56
293 # ifndef LANG_GEORGIAN
294 # define LANG_GEORGIAN 0x37
296 # ifndef LANG_GREENLANDIC
297 # define LANG_GREENLANDIC 0x6f
299 # ifndef LANG_GUARANI
300 # define LANG_GUARANI 0x74
302 # ifndef LANG_GUJARATI
303 # define LANG_GUJARATI 0x47
306 # define LANG_HAUSA 0x68
308 # ifndef LANG_HAWAIIAN
309 # define LANG_HAWAIIAN 0x75
312 # define LANG_HEBREW 0x0d
315 # define LANG_HINDI 0x39
318 # define LANG_IBIBIO 0x69
321 # define LANG_IGBO 0x70
323 # ifndef LANG_INDONESIAN
324 # define LANG_INDONESIAN 0x21
326 # ifndef LANG_INUKTITUT
327 # define LANG_INUKTITUT 0x5d
329 # ifndef LANG_KANNADA
330 # define LANG_KANNADA 0x4b
333 # define LANG_KANURI 0x71
335 # ifndef LANG_KASHMIRI
336 # define LANG_KASHMIRI 0x60
339 # define LANG_KAZAK 0x3f
342 # define LANG_KICHE 0x86
344 # ifndef LANG_KINYARWANDA
345 # define LANG_KINYARWANDA 0x87
347 # ifndef LANG_KONKANI
348 # define LANG_KONKANI 0x57
351 # define LANG_KYRGYZ 0x40
354 # define LANG_LAO 0x54
357 # define LANG_LATIN 0x76
359 # ifndef LANG_LATVIAN
360 # define LANG_LATVIAN 0x26
362 # ifndef LANG_LITHUANIAN
363 # define LANG_LITHUANIAN 0x27
365 # ifndef LANG_LUXEMBOURGISH
366 # define LANG_LUXEMBOURGISH 0x6e
368 # ifndef LANG_MACEDONIAN
369 # define LANG_MACEDONIAN 0x2f
372 # define LANG_MALAY 0x3e
374 # ifndef LANG_MALAYALAM
375 # define LANG_MALAYALAM 0x4c
377 # ifndef LANG_MALTESE
378 # define LANG_MALTESE 0x3a
380 # ifndef LANG_MANIPURI
381 # define LANG_MANIPURI 0x58
384 # define LANG_MAORI 0x81
386 # ifndef LANG_MAPUDUNGUN
387 # define LANG_MAPUDUNGUN 0x7a
389 # ifndef LANG_MARATHI
390 # define LANG_MARATHI 0x4e
393 # define LANG_MOHAWK 0x7c
395 # ifndef LANG_MONGOLIAN
396 # define LANG_MONGOLIAN 0x50
399 # define LANG_NEPALI 0x61
401 # ifndef LANG_OCCITAN
402 # define LANG_OCCITAN 0x82
405 # define LANG_ORIYA 0x48
408 # define LANG_OROMO 0x72
410 # ifndef LANG_PAPIAMENTU
411 # define LANG_PAPIAMENTU 0x79
414 # define LANG_PASHTO 0x63
416 # ifndef LANG_PUNJABI
417 # define LANG_PUNJABI 0x46
419 # ifndef LANG_QUECHUA
420 # define LANG_QUECHUA 0x6b
422 # ifndef LANG_ROMANSH
423 # define LANG_ROMANSH 0x17
426 # define LANG_SAMI 0x3b
428 # ifndef LANG_SANSKRIT
429 # define LANG_SANSKRIT 0x4f
431 # ifndef LANG_SCOTTISH_GAELIC
432 # define LANG_SCOTTISH_GAELIC 0x91
434 # ifndef LANG_SERBIAN
435 # define LANG_SERBIAN 0x1a
438 # define LANG_SINDHI 0x59
440 # ifndef LANG_SINHALESE
441 # define LANG_SINHALESE 0x5b
444 # define LANG_SLOVAK 0x1b
447 # define LANG_SOMALI 0x77
449 # ifndef LANG_SORBIAN
450 # define LANG_SORBIAN 0x2e
453 # define LANG_SOTHO 0x6c
456 # define LANG_SUTU 0x30
458 # ifndef LANG_SWAHILI
459 # define LANG_SWAHILI 0x41
462 # define LANG_SYRIAC 0x5a
464 # ifndef LANG_TAGALOG
465 # define LANG_TAGALOG 0x64
468 # define LANG_TAJIK 0x28
470 # ifndef LANG_TAMAZIGHT
471 # define LANG_TAMAZIGHT 0x5f
474 # define LANG_TAMIL 0x49
477 # define LANG_TATAR 0x44
480 # define LANG_TELUGU 0x4a
483 # define LANG_THAI 0x1e
485 # ifndef LANG_TIBETAN
486 # define LANG_TIBETAN 0x51
488 # ifndef LANG_TIGRINYA
489 # define LANG_TIGRINYA 0x73
492 # define LANG_TSONGA 0x31
495 # define LANG_TSWANA 0x32
497 # ifndef LANG_TURKMEN
498 # define LANG_TURKMEN 0x42
501 # define LANG_UIGHUR 0x80
503 # ifndef LANG_UKRAINIAN
504 # define LANG_UKRAINIAN 0x22
507 # define LANG_URDU 0x20
510 # define LANG_UZBEK 0x43
513 # define LANG_VENDA 0x33
515 # ifndef LANG_VIETNAMESE
516 # define LANG_VIETNAMESE 0x2a
519 # define LANG_WELSH 0x52
522 # define LANG_WOLOF 0x88
525 # define LANG_XHOSA 0x34
528 # define LANG_YAKUT 0x85
531 # define LANG_YI 0x78
533 # ifndef LANG_YIDDISH
534 # define LANG_YIDDISH 0x3d
537 # define LANG_YORUBA 0x6a
540 # define LANG_ZULU 0x35
542 # ifndef SUBLANG_AFRIKAANS_SOUTH_AFRICA
543 # define SUBLANG_AFRIKAANS_SOUTH_AFRICA 0x01
545 # ifndef SUBLANG_ALBANIAN_ALBANIA
546 # define SUBLANG_ALBANIAN_ALBANIA 0x01
548 # ifndef SUBLANG_ALSATIAN_FRANCE
549 # define SUBLANG_ALSATIAN_FRANCE 0x01
551 # ifndef SUBLANG_AMHARIC_ETHIOPIA
552 # define SUBLANG_AMHARIC_ETHIOPIA 0x01
554 # ifndef SUBLANG_ARABIC_SAUDI_ARABIA
555 # define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
557 # ifndef SUBLANG_ARABIC_IRAQ
558 # define SUBLANG_ARABIC_IRAQ 0x02
560 # ifndef SUBLANG_ARABIC_EGYPT
561 # define SUBLANG_ARABIC_EGYPT 0x03
563 # ifndef SUBLANG_ARABIC_LIBYA
564 # define SUBLANG_ARABIC_LIBYA 0x04
566 # ifndef SUBLANG_ARABIC_ALGERIA
567 # define SUBLANG_ARABIC_ALGERIA 0x05
569 # ifndef SUBLANG_ARABIC_MOROCCO
570 # define SUBLANG_ARABIC_MOROCCO 0x06
572 # ifndef SUBLANG_ARABIC_TUNISIA
573 # define SUBLANG_ARABIC_TUNISIA 0x07
575 # ifndef SUBLANG_ARABIC_OMAN
576 # define SUBLANG_ARABIC_OMAN 0x08
578 # ifndef SUBLANG_ARABIC_YEMEN
579 # define SUBLANG_ARABIC_YEMEN 0x09
581 # ifndef SUBLANG_ARABIC_SYRIA
582 # define SUBLANG_ARABIC_SYRIA 0x0a
584 # ifndef SUBLANG_ARABIC_JORDAN
585 # define SUBLANG_ARABIC_JORDAN 0x0b
587 # ifndef SUBLANG_ARABIC_LEBANON
588 # define SUBLANG_ARABIC_LEBANON 0x0c
590 # ifndef SUBLANG_ARABIC_KUWAIT
591 # define SUBLANG_ARABIC_KUWAIT 0x0d
593 # ifndef SUBLANG_ARABIC_UAE
594 # define SUBLANG_ARABIC_UAE 0x0e
596 # ifndef SUBLANG_ARABIC_BAHRAIN
597 # define SUBLANG_ARABIC_BAHRAIN 0x0f
599 # ifndef SUBLANG_ARABIC_QATAR
600 # define SUBLANG_ARABIC_QATAR 0x10
602 # ifndef SUBLANG_ARMENIAN_ARMENIA
603 # define SUBLANG_ARMENIAN_ARMENIA 0x01
605 # ifndef SUBLANG_ASSAMESE_INDIA
606 # define SUBLANG_ASSAMESE_INDIA 0x01
608 # ifndef SUBLANG_AZERI_LATIN
609 # define SUBLANG_AZERI_LATIN 0x01
611 # ifndef SUBLANG_AZERI_CYRILLIC
612 # define SUBLANG_AZERI_CYRILLIC 0x02
614 # ifndef SUBLANG_BASHKIR_RUSSIA
615 # define SUBLANG_BASHKIR_RUSSIA 0x01
617 # ifndef SUBLANG_BASQUE_BASQUE
618 # define SUBLANG_BASQUE_BASQUE 0x01
620 # ifndef SUBLANG_BELARUSIAN_BELARUS
621 # define SUBLANG_BELARUSIAN_BELARUS 0x01
623 # ifndef SUBLANG_BENGALI_INDIA
624 # define SUBLANG_BENGALI_INDIA 0x01
626 # ifndef SUBLANG_BENGALI_BANGLADESH
627 # define SUBLANG_BENGALI_BANGLADESH 0x02
629 # ifndef SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN
630 # define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN 0x05
632 # ifndef SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC
633 # define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC 0x08
635 # ifndef SUBLANG_BRETON_FRANCE
636 # define SUBLANG_BRETON_FRANCE 0x01
638 # ifndef SUBLANG_BULGARIAN_BULGARIA
639 # define SUBLANG_BULGARIAN_BULGARIA 0x01
641 # ifndef SUBLANG_CAMBODIAN_CAMBODIA
642 # define SUBLANG_CAMBODIAN_CAMBODIA 0x01
644 # ifndef SUBLANG_CATALAN_SPAIN
645 # define SUBLANG_CATALAN_SPAIN 0x01
647 # ifndef SUBLANG_CORSICAN_FRANCE
648 # define SUBLANG_CORSICAN_FRANCE 0x01
650 # ifndef SUBLANG_CROATIAN_CROATIA
651 # define SUBLANG_CROATIAN_CROATIA 0x01
653 # ifndef SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN
654 # define SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN 0x04
656 # ifndef SUBLANG_CHINESE_MACAU
657 # define SUBLANG_CHINESE_MACAU 0x05
659 # ifndef SUBLANG_CZECH_CZECH_REPUBLIC
660 # define SUBLANG_CZECH_CZECH_REPUBLIC 0x01
662 # ifndef SUBLANG_DANISH_DENMARK
663 # define SUBLANG_DANISH_DENMARK 0x01
665 # ifndef SUBLANG_DARI_AFGHANISTAN
666 # define SUBLANG_DARI_AFGHANISTAN 0x01
668 # ifndef SUBLANG_DIVEHI_MALDIVES
669 # define SUBLANG_DIVEHI_MALDIVES 0x01
671 # ifndef SUBLANG_DUTCH_SURINAM
672 # define SUBLANG_DUTCH_SURINAM 0x03
674 # ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
675 # define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
677 # ifndef SUBLANG_ENGLISH_JAMAICA
678 # define SUBLANG_ENGLISH_JAMAICA 0x08
680 # ifndef SUBLANG_ENGLISH_CARIBBEAN
681 # define SUBLANG_ENGLISH_CARIBBEAN 0x09
683 # ifndef SUBLANG_ENGLISH_BELIZE
684 # define SUBLANG_ENGLISH_BELIZE 0x0a
686 # ifndef SUBLANG_ENGLISH_TRINIDAD
687 # define SUBLANG_ENGLISH_TRINIDAD 0x0b
689 # ifndef SUBLANG_ENGLISH_ZIMBABWE
690 # define SUBLANG_ENGLISH_ZIMBABWE 0x0c
692 # ifndef SUBLANG_ENGLISH_PHILIPPINES
693 # define SUBLANG_ENGLISH_PHILIPPINES 0x0d
695 # ifndef SUBLANG_ENGLISH_INDONESIA
696 # define SUBLANG_ENGLISH_INDONESIA 0x0e
698 # ifndef SUBLANG_ENGLISH_HONGKONG
699 # define SUBLANG_ENGLISH_HONGKONG 0x0f
701 # ifndef SUBLANG_ENGLISH_INDIA
702 # define SUBLANG_ENGLISH_INDIA 0x10
704 # ifndef SUBLANG_ENGLISH_MALAYSIA
705 # define SUBLANG_ENGLISH_MALAYSIA 0x11
707 # ifndef SUBLANG_ENGLISH_SINGAPORE
708 # define SUBLANG_ENGLISH_SINGAPORE 0x12
710 # ifndef SUBLANG_ESTONIAN_ESTONIA
711 # define SUBLANG_ESTONIAN_ESTONIA 0x01
713 # ifndef SUBLANG_FAEROESE_FAROE_ISLANDS
714 # define SUBLANG_FAEROESE_FAROE_ISLANDS 0x01
716 # ifndef SUBLANG_FARSI_IRAN
717 # define SUBLANG_FARSI_IRAN 0x01
719 # ifndef SUBLANG_FINNISH_FINLAND
720 # define SUBLANG_FINNISH_FINLAND 0x01
722 # ifndef SUBLANG_FRENCH_LUXEMBOURG
723 # define SUBLANG_FRENCH_LUXEMBOURG 0x05
725 # ifndef SUBLANG_FRENCH_MONACO
726 # define SUBLANG_FRENCH_MONACO 0x06
728 # ifndef SUBLANG_FRENCH_WESTINDIES
729 # define SUBLANG_FRENCH_WESTINDIES 0x07
731 # ifndef SUBLANG_FRENCH_REUNION
732 # define SUBLANG_FRENCH_REUNION 0x08
734 # ifndef SUBLANG_FRENCH_CONGO
735 # define SUBLANG_FRENCH_CONGO 0x09
737 # ifndef SUBLANG_FRENCH_SENEGAL
738 # define SUBLANG_FRENCH_SENEGAL 0x0a
740 # ifndef SUBLANG_FRENCH_CAMEROON
741 # define SUBLANG_FRENCH_CAMEROON 0x0b
743 # ifndef SUBLANG_FRENCH_COTEDIVOIRE
744 # define SUBLANG_FRENCH_COTEDIVOIRE 0x0c
746 # ifndef SUBLANG_FRENCH_MALI
747 # define SUBLANG_FRENCH_MALI 0x0d
749 # ifndef SUBLANG_FRENCH_MOROCCO
750 # define SUBLANG_FRENCH_MOROCCO 0x0e
752 # ifndef SUBLANG_FRENCH_HAITI
753 # define SUBLANG_FRENCH_HAITI 0x0f
755 # ifndef SUBLANG_FRISIAN_NETHERLANDS
756 # define SUBLANG_FRISIAN_NETHERLANDS 0x01
758 # ifndef SUBLANG_GALICIAN_SPAIN
759 # define SUBLANG_GALICIAN_SPAIN 0x01
761 # ifndef SUBLANG_GEORGIAN_GEORGIA
762 # define SUBLANG_GEORGIAN_GEORGIA 0x01
764 # ifndef SUBLANG_GERMAN_LUXEMBOURG
765 # define SUBLANG_GERMAN_LUXEMBOURG 0x04
767 # ifndef SUBLANG_GERMAN_LIECHTENSTEIN
768 # define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
770 # ifndef SUBLANG_GREEK_GREECE
771 # define SUBLANG_GREEK_GREECE 0x01
773 # ifndef SUBLANG_GREENLANDIC_GREENLAND
774 # define SUBLANG_GREENLANDIC_GREENLAND 0x01
776 # ifndef SUBLANG_GUJARATI_INDIA
777 # define SUBLANG_GUJARATI_INDIA 0x01
779 # ifndef SUBLANG_HAUSA_NIGERIA_LATIN
780 # define SUBLANG_HAUSA_NIGERIA_LATIN 0x01
782 # ifndef SUBLANG_HEBREW_ISRAEL
783 # define SUBLANG_HEBREW_ISRAEL 0x01
785 # ifndef SUBLANG_HINDI_INDIA
786 # define SUBLANG_HINDI_INDIA 0x01
788 # ifndef SUBLANG_HUNGARIAN_HUNGARY
789 # define SUBLANG_HUNGARIAN_HUNGARY 0x01
791 # ifndef SUBLANG_ICELANDIC_ICELAND
792 # define SUBLANG_ICELANDIC_ICELAND 0x01
794 # ifndef SUBLANG_IGBO_NIGERIA
795 # define SUBLANG_IGBO_NIGERIA 0x01
797 # ifndef SUBLANG_INDONESIAN_INDONESIA
798 # define SUBLANG_INDONESIAN_INDONESIA 0x01
800 # ifndef SUBLANG_INUKTITUT_CANADA
801 # define SUBLANG_INUKTITUT_CANADA 0x01
803 # undef SUBLANG_INUKTITUT_CANADA_LATIN
804 # define SUBLANG_INUKTITUT_CANADA_LATIN 0x02
805 # undef SUBLANG_IRISH_IRELAND
806 # define SUBLANG_IRISH_IRELAND 0x02
807 # ifndef SUBLANG_JAPANESE_JAPAN
808 # define SUBLANG_JAPANESE_JAPAN 0x01
810 # ifndef SUBLANG_KANNADA_INDIA
811 # define SUBLANG_KANNADA_INDIA 0x01
813 # ifndef SUBLANG_KASHMIRI_INDIA
814 # define SUBLANG_KASHMIRI_INDIA 0x02
816 # ifndef SUBLANG_KAZAK_KAZAKHSTAN
817 # define SUBLANG_KAZAK_KAZAKHSTAN 0x01
819 # ifndef SUBLANG_KICHE_GUATEMALA
820 # define SUBLANG_KICHE_GUATEMALA 0x01
822 # ifndef SUBLANG_KINYARWANDA_RWANDA
823 # define SUBLANG_KINYARWANDA_RWANDA 0x01
825 # ifndef SUBLANG_KONKANI_INDIA
826 # define SUBLANG_KONKANI_INDIA 0x01
828 # ifndef SUBLANG_KYRGYZ_KYRGYZSTAN
829 # define SUBLANG_KYRGYZ_KYRGYZSTAN 0x01
831 # ifndef SUBLANG_LAO_LAOS
832 # define SUBLANG_LAO_LAOS 0x01
834 # ifndef SUBLANG_LATVIAN_LATVIA
835 # define SUBLANG_LATVIAN_LATVIA 0x01
837 # ifndef SUBLANG_LITHUANIAN_LITHUANIA
838 # define SUBLANG_LITHUANIAN_LITHUANIA 0x01
840 # undef SUBLANG_LOWER_SORBIAN_GERMANY
841 # define SUBLANG_LOWER_SORBIAN_GERMANY 0x02
842 # ifndef SUBLANG_LUXEMBOURGISH_LUXEMBOURG
843 # define SUBLANG_LUXEMBOURGISH_LUXEMBOURG 0x01
845 # ifndef SUBLANG_MACEDONIAN_MACEDONIA
846 # define SUBLANG_MACEDONIAN_MACEDONIA 0x01
848 # ifndef SUBLANG_MALAY_MALAYSIA
849 # define SUBLANG_MALAY_MALAYSIA 0x01
851 # ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
852 # define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
854 # ifndef SUBLANG_MALAYALAM_INDIA
855 # define SUBLANG_MALAYALAM_INDIA 0x01
857 # ifndef SUBLANG_MALTESE_MALTA
858 # define SUBLANG_MALTESE_MALTA 0x01
860 # ifndef SUBLANG_MAORI_NEW_ZEALAND
861 # define SUBLANG_MAORI_NEW_ZEALAND 0x01
863 # ifndef SUBLANG_MAPUDUNGUN_CHILE
864 # define SUBLANG_MAPUDUNGUN_CHILE 0x01
866 # ifndef SUBLANG_MARATHI_INDIA
867 # define SUBLANG_MARATHI_INDIA 0x01
869 # ifndef SUBLANG_MOHAWK_CANADA
870 # define SUBLANG_MOHAWK_CANADA 0x01
872 # ifndef SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA
873 # define SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA 0x01
875 # ifndef SUBLANG_MONGOLIAN_PRC
876 # define SUBLANG_MONGOLIAN_PRC 0x02
878 # ifndef SUBLANG_NEPALI_NEPAL
879 # define SUBLANG_NEPALI_NEPAL 0x01
881 # ifndef SUBLANG_NEPALI_INDIA
882 # define SUBLANG_NEPALI_INDIA 0x02
884 # ifndef SUBLANG_OCCITAN_FRANCE
885 # define SUBLANG_OCCITAN_FRANCE 0x01
887 # ifndef SUBLANG_ORIYA_INDIA
888 # define SUBLANG_ORIYA_INDIA 0x01
890 # ifndef SUBLANG_PASHTO_AFGHANISTAN
891 # define SUBLANG_PASHTO_AFGHANISTAN 0x01
893 # ifndef SUBLANG_POLISH_POLAND
894 # define SUBLANG_POLISH_POLAND 0x01
896 # ifndef SUBLANG_PUNJABI_INDIA
897 # define SUBLANG_PUNJABI_INDIA 0x01
899 # ifndef SUBLANG_PUNJABI_PAKISTAN
900 # define SUBLANG_PUNJABI_PAKISTAN 0x02
902 # ifndef SUBLANG_QUECHUA_BOLIVIA
903 # define SUBLANG_QUECHUA_BOLIVIA 0x01
905 # ifndef SUBLANG_QUECHUA_ECUADOR
906 # define SUBLANG_QUECHUA_ECUADOR 0x02
908 # ifndef SUBLANG_QUECHUA_PERU
909 # define SUBLANG_QUECHUA_PERU 0x03
911 # ifndef SUBLANG_ROMANIAN_ROMANIA
912 # define SUBLANG_ROMANIAN_ROMANIA 0x01
914 # ifndef SUBLANG_ROMANIAN_MOLDOVA
915 # define SUBLANG_ROMANIAN_MOLDOVA 0x02
917 # ifndef SUBLANG_ROMANSH_SWITZERLAND
918 # define SUBLANG_ROMANSH_SWITZERLAND 0x01
920 # ifndef SUBLANG_RUSSIAN_RUSSIA
921 # define SUBLANG_RUSSIAN_RUSSIA 0x01
923 # ifndef SUBLANG_RUSSIAN_MOLDAVIA
924 # define SUBLANG_RUSSIAN_MOLDAVIA 0x02
926 # ifndef SUBLANG_SAMI_NORTHERN_NORWAY
927 # define SUBLANG_SAMI_NORTHERN_NORWAY 0x01
929 # ifndef SUBLANG_SAMI_NORTHERN_SWEDEN
930 # define SUBLANG_SAMI_NORTHERN_SWEDEN 0x02
932 # ifndef SUBLANG_SAMI_NORTHERN_FINLAND
933 # define SUBLANG_SAMI_NORTHERN_FINLAND 0x03
935 # ifndef SUBLANG_SAMI_LULE_NORWAY
936 # define SUBLANG_SAMI_LULE_NORWAY 0x04
938 # ifndef SUBLANG_SAMI_LULE_SWEDEN
939 # define SUBLANG_SAMI_LULE_SWEDEN 0x05
941 # ifndef SUBLANG_SAMI_SOUTHERN_NORWAY
942 # define SUBLANG_SAMI_SOUTHERN_NORWAY 0x06
944 # ifndef SUBLANG_SAMI_SOUTHERN_SWEDEN
945 # define SUBLANG_SAMI_SOUTHERN_SWEDEN 0x07
947 # undef SUBLANG_SAMI_SKOLT_FINLAND
948 # define SUBLANG_SAMI_SKOLT_FINLAND 0x08
949 # undef SUBLANG_SAMI_INARI_FINLAND
950 # define SUBLANG_SAMI_INARI_FINLAND 0x09
951 # ifndef SUBLANG_SANSKRIT_INDIA
952 # define SUBLANG_SANSKRIT_INDIA 0x01
954 # ifndef SUBLANG_SERBIAN_LATIN
955 # define SUBLANG_SERBIAN_LATIN 0x02
957 # ifndef SUBLANG_SERBIAN_CYRILLIC
958 # define SUBLANG_SERBIAN_CYRILLIC 0x03
960 # ifndef SUBLANG_SINDHI_INDIA
961 # define SUBLANG_SINDHI_INDIA 0x01
963 # undef SUBLANG_SINDHI_PAKISTAN
964 # define SUBLANG_SINDHI_PAKISTAN 0x02
965 # ifndef SUBLANG_SINDHI_AFGHANISTAN
966 # define SUBLANG_SINDHI_AFGHANISTAN 0x02
968 # ifndef SUBLANG_SINHALESE_SRI_LANKA
969 # define SUBLANG_SINHALESE_SRI_LANKA 0x01
971 # ifndef SUBLANG_SLOVAK_SLOVAKIA
972 # define SUBLANG_SLOVAK_SLOVAKIA 0x01
974 # ifndef SUBLANG_SLOVENIAN_SLOVENIA
975 # define SUBLANG_SLOVENIAN_SLOVENIA 0x01
977 # ifndef SUBLANG_SOTHO_SOUTH_AFRICA
978 # define SUBLANG_SOTHO_SOUTH_AFRICA 0x01
980 # ifndef SUBLANG_SPANISH_GUATEMALA
981 # define SUBLANG_SPANISH_GUATEMALA 0x04
983 # ifndef SUBLANG_SPANISH_COSTA_RICA
984 # define SUBLANG_SPANISH_COSTA_RICA 0x05
986 # ifndef SUBLANG_SPANISH_PANAMA
987 # define SUBLANG_SPANISH_PANAMA 0x06
989 # ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
990 # define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
992 # ifndef SUBLANG_SPANISH_VENEZUELA
993 # define SUBLANG_SPANISH_VENEZUELA 0x08
995 # ifndef SUBLANG_SPANISH_COLOMBIA
996 # define SUBLANG_SPANISH_COLOMBIA 0x09
998 # ifndef SUBLANG_SPANISH_PERU
999 # define SUBLANG_SPANISH_PERU 0x0a
1001 # ifndef SUBLANG_SPANISH_ARGENTINA
1002 # define SUBLANG_SPANISH_ARGENTINA 0x0b
1004 # ifndef SUBLANG_SPANISH_ECUADOR
1005 # define SUBLANG_SPANISH_ECUADOR 0x0c
1007 # ifndef SUBLANG_SPANISH_CHILE
1008 # define SUBLANG_SPANISH_CHILE 0x0d
1010 # ifndef SUBLANG_SPANISH_URUGUAY
1011 # define SUBLANG_SPANISH_URUGUAY 0x0e
1013 # ifndef SUBLANG_SPANISH_PARAGUAY
1014 # define SUBLANG_SPANISH_PARAGUAY 0x0f
1016 # ifndef SUBLANG_SPANISH_BOLIVIA
1017 # define SUBLANG_SPANISH_BOLIVIA 0x10
1019 # ifndef SUBLANG_SPANISH_EL_SALVADOR
1020 # define SUBLANG_SPANISH_EL_SALVADOR 0x11
1022 # ifndef SUBLANG_SPANISH_HONDURAS
1023 # define SUBLANG_SPANISH_HONDURAS 0x12
1025 # ifndef SUBLANG_SPANISH_NICARAGUA
1026 # define SUBLANG_SPANISH_NICARAGUA 0x13
1028 # ifndef SUBLANG_SPANISH_PUERTO_RICO
1029 # define SUBLANG_SPANISH_PUERTO_RICO 0x14
1031 # ifndef SUBLANG_SPANISH_US
1032 # define SUBLANG_SPANISH_US 0x15
1034 # ifndef SUBLANG_SWAHILI_KENYA
1035 # define SUBLANG_SWAHILI_KENYA 0x01
1037 # ifndef SUBLANG_SWEDISH_SWEDEN
1038 # define SUBLANG_SWEDISH_SWEDEN 0x01
1040 # ifndef SUBLANG_SWEDISH_FINLAND
1041 # define SUBLANG_SWEDISH_FINLAND 0x02
1043 # ifndef SUBLANG_SYRIAC_SYRIA
1044 # define SUBLANG_SYRIAC_SYRIA 0x01
1046 # ifndef SUBLANG_TAGALOG_PHILIPPINES
1047 # define SUBLANG_TAGALOG_PHILIPPINES 0x01
1049 # ifndef SUBLANG_TAJIK_TAJIKISTAN
1050 # define SUBLANG_TAJIK_TAJIKISTAN 0x01
1052 # ifndef SUBLANG_TAMAZIGHT_ARABIC
1053 # define SUBLANG_TAMAZIGHT_ARABIC 0x01
1055 # ifndef SUBLANG_TAMAZIGHT_ALGERIA_LATIN
1056 # define SUBLANG_TAMAZIGHT_ALGERIA_LATIN 0x02
1058 # ifndef SUBLANG_TAMIL_INDIA
1059 # define SUBLANG_TAMIL_INDIA 0x01
1061 # ifndef SUBLANG_TATAR_RUSSIA
1062 # define SUBLANG_TATAR_RUSSIA 0x01
1064 # ifndef SUBLANG_TELUGU_INDIA
1065 # define SUBLANG_TELUGU_INDIA 0x01
1067 # ifndef SUBLANG_THAI_THAILAND
1068 # define SUBLANG_THAI_THAILAND 0x01
1070 # ifndef SUBLANG_TIBETAN_PRC
1071 # define SUBLANG_TIBETAN_PRC 0x01
1073 # undef SUBLANG_TIBETAN_BHUTAN
1074 # define SUBLANG_TIBETAN_BHUTAN 0x02
1075 # ifndef SUBLANG_TIGRINYA_ETHIOPIA
1076 # define SUBLANG_TIGRINYA_ETHIOPIA 0x01
1078 # ifndef SUBLANG_TIGRINYA_ERITREA
1079 # define SUBLANG_TIGRINYA_ERITREA 0x02
1081 # ifndef SUBLANG_TSWANA_SOUTH_AFRICA
1082 # define SUBLANG_TSWANA_SOUTH_AFRICA 0x01
1084 # ifndef SUBLANG_TURKISH_TURKEY
1085 # define SUBLANG_TURKISH_TURKEY 0x01
1087 # ifndef SUBLANG_TURKMEN_TURKMENISTAN
1088 # define SUBLANG_TURKMEN_TURKMENISTAN 0x01
1090 # ifndef SUBLANG_UIGHUR_PRC
1091 # define SUBLANG_UIGHUR_PRC 0x01
1093 # ifndef SUBLANG_UKRAINIAN_UKRAINE
1094 # define SUBLANG_UKRAINIAN_UKRAINE 0x01
1096 # ifndef SUBLANG_UPPER_SORBIAN_GERMANY
1097 # define SUBLANG_UPPER_SORBIAN_GERMANY 0x01
1099 # ifndef SUBLANG_URDU_PAKISTAN
1100 # define SUBLANG_URDU_PAKISTAN 0x01
1102 # ifndef SUBLANG_URDU_INDIA
1103 # define SUBLANG_URDU_INDIA 0x02
1105 # ifndef SUBLANG_UZBEK_LATIN
1106 # define SUBLANG_UZBEK_LATIN 0x01
1108 # ifndef SUBLANG_UZBEK_CYRILLIC
1109 # define SUBLANG_UZBEK_CYRILLIC 0x02
1111 # ifndef SUBLANG_VIETNAMESE_VIETNAM
1112 # define SUBLANG_VIETNAMESE_VIETNAM 0x01
1114 # ifndef SUBLANG_WELSH_UNITED_KINGDOM
1115 # define SUBLANG_WELSH_UNITED_KINGDOM 0x01
1117 # ifndef SUBLANG_WOLOF_SENEGAL
1118 # define SUBLANG_WOLOF_SENEGAL 0x01
1120 # ifndef SUBLANG_XHOSA_SOUTH_AFRICA
1121 # define SUBLANG_XHOSA_SOUTH_AFRICA 0x01
1123 # ifndef SUBLANG_YAKUT_RUSSIA
1124 # define SUBLANG_YAKUT_RUSSIA 0x01
1126 # ifndef SUBLANG_YI_PRC
1127 # define SUBLANG_YI_PRC 0x01
1129 # ifndef SUBLANG_YORUBA_NIGERIA
1130 # define SUBLANG_YORUBA_NIGERIA 0x01
1132 # ifndef SUBLANG_ZULU_SOUTH_AFRICA
1133 # define SUBLANG_ZULU_SOUTH_AFRICA 0x01
1135 /* GetLocaleInfoA operations. */
1136 # ifndef LOCALE_SNAME
1137 # define LOCALE_SNAME 0x5c
1139 # ifndef LOCALE_NAME_MAX_LENGTH
1140 # define LOCALE_NAME_MAX_LENGTH 85
1145 #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
1146 /* Mac OS X 10.2 or newer */
1148 /* Canonicalize a Mac OS X locale name to a Unix locale name.
1149 NAME is a sufficiently large buffer.
1150 On input, it contains the Mac OS X locale name.
1151 On output, it contains the Unix locale name. */
1152 # if !defined IN_LIBINTL
1156 gl_locale_name_canonicalize (char *name)
1158 /* This conversion is based on a posting by
1159 Deborah GoldSmith <goldsmit@apple.com> on 2005-03-08,
1160 http://lists.apple.com/archives/carbon-dev/2005/Mar/msg00293.html */
1162 /* Convert legacy (NeXTstep inherited) English names to Unix (ISO 639 and
1163 ISO 3166) names. Prior to Mac OS X 10.3, there is no API for doing this.
1164 Therefore we do it ourselves, using a table based on the results of the
1165 Mac OS X 10.3.8 function
1166 CFLocaleCreateCanonicalLocaleIdentifierFromString(). */
1167 typedef struct { const char legacy[21+1]; const char unixy[5+1]; }
1169 static const legacy_entry legacy_table[] = {
1170 { "Afrikaans", "af" },
1171 { "Albanian", "sq" },
1172 { "Amharic", "am" },
1174 { "Armenian", "hy" },
1175 { "Assamese", "as" },
1177 { "Azerbaijani", "az" },
1179 { "Belarusian", "be" },
1180 { "Belorussian", "be" },
1181 { "Bengali", "bn" },
1182 { "Brazilian Portugese", "pt_BR" },
1183 { "Brazilian Portuguese", "pt_BR" },
1185 { "Bulgarian", "bg" },
1186 { "Burmese", "my" },
1187 { "Byelorussian", "be" },
1188 { "Catalan", "ca" },
1190 { "Chichewa", "ny" },
1191 { "Chinese", "zh" },
1192 { "Chinese, Simplified", "zh_CN" },
1193 { "Chinese, Traditional", "zh_TW" },
1194 { "Chinese, Tradtional", "zh_TW" },
1195 { "Croatian", "hr" },
1199 { "Dzongkha", "dz" },
1200 { "English", "en" },
1201 { "Esperanto", "eo" },
1202 { "Estonian", "et" },
1203 { "Faroese", "fo" },
1205 { "Finnish", "fi" },
1206 { "Flemish", "nl_BE" },
1208 { "Galician", "gl" },
1209 { "Gallegan", "gl" },
1210 { "Georgian", "ka" },
1213 { "Greenlandic", "kl" },
1214 { "Guarani", "gn" },
1215 { "Gujarati", "gu" },
1216 { "Hawaiian", "haw" }, /* Yes, "haw", not "cpe". */
1219 { "Hungarian", "hu" },
1220 { "Icelandic", "is" },
1221 { "Indonesian", "id" },
1222 { "Inuktitut", "iu" },
1224 { "Italian", "it" },
1225 { "Japanese", "ja" },
1226 { "Javanese", "jv" },
1227 { "Kalaallisut", "kl" },
1228 { "Kannada", "kn" },
1229 { "Kashmiri", "ks" },
1232 { "Kinyarwanda", "rw" },
1233 { "Kirghiz", "ky" },
1235 { "Kurdish", "ku" },
1237 { "Latvian", "lv" },
1238 { "Lithuanian", "lt" },
1239 { "Macedonian", "mk" },
1240 { "Malagasy", "mg" },
1242 { "Malayalam", "ml" },
1243 { "Maltese", "mt" },
1245 { "Marathi", "mr" },
1246 { "Moldavian", "mo" },
1247 { "Mongolian", "mn" },
1249 { "Norwegian", "nb" }, /* Yes, "nb", not the obsolete "no". */
1251 { "Nynorsk", "nn" },
1254 { "Panjabi", "pa" },
1256 { "Persian", "fa" },
1258 { "Portuguese", "pt" },
1259 { "Portuguese, Brazilian", "pt_BR" },
1260 { "Punjabi", "pa" },
1262 { "Quechua", "qu" },
1263 { "Romanian", "ro" },
1266 { "Russian", "ru" },
1267 { "Sami", "se_NO" }, /* Not just "se". */
1268 { "Sanskrit", "sa" },
1269 { "Scottish", "gd" },
1270 { "Serbian", "sr" },
1271 { "Simplified Chinese", "zh_CN" },
1273 { "Sinhalese", "si" },
1275 { "Slovenian", "sl" },
1277 { "Spanish", "es" },
1278 { "Sundanese", "su" },
1279 { "Swahili", "sw" },
1280 { "Swedish", "sv" },
1281 { "Tagalog", "tl" },
1288 { "Tibetan", "bo" },
1289 { "Tigrinya", "ti" },
1291 { "Traditional Chinese", "zh_TW" },
1292 { "Turkish", "tr" },
1293 { "Turkmen", "tk" },
1295 { "Ukrainian", "uk" },
1298 { "Vietnamese", "vi" },
1303 /* Convert new-style locale names with language tags (ISO 639 and ISO 15924)
1304 to Unix (ISO 639 and ISO 3166) names. */
1305 typedef struct { const char langtag[7+1]; const char unixy[12+1]; }
1307 static const langtag_entry langtag_table[] = {
1308 /* Mac OS X has "az-Arab", "az-Cyrl", "az-Latn".
1309 The default script for az on Unix is Latin. */
1310 { "az-Latn", "az" },
1311 /* Mac OS X has "ga-dots". Does not yet exist on Unix. */
1312 { "ga-dots", "ga" },
1313 /* Mac OS X has "kk-Cyrl". Does not yet exist on Unix. */
1314 /* Mac OS X has "mn-Cyrl", "mn-Mong".
1315 The default script for mn on Unix is Cyrillic. */
1316 { "mn-Cyrl", "mn" },
1317 /* Mac OS X has "ms-Arab", "ms-Latn".
1318 The default script for ms on Unix is Latin. */
1319 { "ms-Latn", "ms" },
1320 /* Mac OS X has "tg-Cyrl".
1321 The default script for tg on Unix is Cyrillic. */
1322 { "tg-Cyrl", "tg" },
1323 /* Mac OS X has "tk-Cyrl". Does not yet exist on Unix. */
1324 /* Mac OS X has "tt-Cyrl".
1325 The default script for tt on Unix is Cyrillic. */
1326 { "tt-Cyrl", "tt" },
1327 /* Mac OS X has "zh-Hans", "zh-Hant".
1328 Country codes are used to distinguish these on Unix. */
1329 { "zh-Hans", "zh_CN" },
1330 { "zh-Hant", "zh_TW" }
1333 /* Convert script names (ISO 15924) to Unix conventions.
1334 See http://www.unicode.org/iso15924/iso15924-codes.html */
1335 typedef struct { const char script[4+1]; const char unixy[9+1]; }
1337 static const script_entry script_table[] = {
1338 { "Arab", "arabic" },
1339 { "Cyrl", "cyrillic" },
1340 { "Mong", "mongolian" }
1343 /* Step 1: Convert using legacy_table. */
1344 if (name[0] >= 'A' && name[0] <= 'Z')
1346 unsigned int i1, i2;
1348 i2 = sizeof (legacy_table) / sizeof (legacy_entry);
1351 /* At this point we know that if name occurs in legacy_table,
1352 its index must be >= i1 and < i2. */
1353 unsigned int i = (i1 + i2) >> 1;
1354 const legacy_entry *p = &legacy_table[i];
1355 if (strcmp (name, p->legacy) < 0)
1360 if (strcmp (name, legacy_table[i1].legacy) == 0)
1362 strcpy (name, legacy_table[i1].unixy);
1367 /* Step 2: Convert using langtag_table and script_table. */
1368 if (strlen (name) == 7 && name[2] == '-')
1370 unsigned int i1, i2;
1372 i2 = sizeof (langtag_table) / sizeof (langtag_entry);
1375 /* At this point we know that if name occurs in langtag_table,
1376 its index must be >= i1 and < i2. */
1377 unsigned int i = (i1 + i2) >> 1;
1378 const langtag_entry *p = &langtag_table[i];
1379 if (strcmp (name, p->langtag) < 0)
1384 if (strcmp (name, langtag_table[i1].langtag) == 0)
1386 strcpy (name, langtag_table[i1].unixy);
1391 i2 = sizeof (script_table) / sizeof (script_entry);
1394 /* At this point we know that if (name + 3) occurs in script_table,
1395 its index must be >= i1 and < i2. */
1396 unsigned int i = (i1 + i2) >> 1;
1397 const script_entry *p = &script_table[i];
1398 if (strcmp (name + 3, p->script) < 0)
1403 if (strcmp (name + 3, script_table[i1].script) == 0)
1406 strcpy (name + 3, script_table[i1].unixy);
1411 /* Step 3: Convert new-style dash to Unix underscore. */
1414 for (p = name; *p != '\0'; p++)
1423 #if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Native Windows or Cygwin */
1425 /* Canonicalize a Windows native locale name to a Unix locale name.
1426 NAME is a sufficiently large buffer.
1427 On input, it contains the Windows locale name.
1428 On output, it contains the Unix locale name. */
1429 # if !defined IN_LIBINTL
1433 gl_locale_name_canonicalize (char *name)
1435 /* FIXME: This is probably incomplete: it does not handle "zh-Hans" and
1439 for (p = name; *p != '\0'; p++)
1444 for (; *p != '\0'; p++)
1446 if (*p >= 'a' && *p <= 'z')
1458 # if !defined IN_LIBINTL
1462 gl_locale_name_from_win32_LANGID (LANGID langid)
1464 /* Activate the new code only when the GETTEXT_MUI environment variable is
1465 set, for the time being, since the new code is not well tested. */
1466 if (getenv ("GETTEXT_MUI") != NULL)
1468 static char namebuf[256];
1470 /* Query the system's notion of locale name.
1471 On Windows95/98/ME, GetLocaleInfoA returns some incorrect results.
1472 But we don't need to support systems that are so old. */
1473 if (GetLocaleInfoA (MAKELCID (langid, SORT_DEFAULT), LOCALE_SNAME,
1474 namebuf, sizeof (namebuf) - 1))
1476 /* Convert it to a Unix locale name. */
1477 gl_locale_name_canonicalize (namebuf);
1481 /* Internet Explorer has an LCID to RFC3066 name mapping stored in
1482 HKEY_CLASSES_ROOT\Mime\Database\Rfc1766. But we better don't use that
1483 since IE's i18n subsystem is known to be inconsistent with the native
1484 Windows base (e.g. they have different character conversion facilities
1485 that produce different results). */
1486 /* Use our own table. */
1490 /* Split into language and territory part. */
1491 primary = PRIMARYLANGID (langid);
1492 sub = SUBLANGID (langid);
1494 /* Dispatch on language.
1495 See also http://www.unicode.org/unicode/onlinedat/languages.html .
1496 For details about languages, see http://www.ethnologue.com/ . */
1499 case LANG_AFRIKAANS:
1502 case SUBLANG_AFRIKAANS_SOUTH_AFRICA: return "af_ZA";
1508 case SUBLANG_ALBANIAN_ALBANIA: return "sq_AL";
1514 case SUBLANG_ALSATIAN_FRANCE: return "gsw_FR";
1520 case SUBLANG_AMHARIC_ETHIOPIA: return "am_ET";
1526 case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA";
1527 case SUBLANG_ARABIC_IRAQ: return "ar_IQ";
1528 case SUBLANG_ARABIC_EGYPT: return "ar_EG";
1529 case SUBLANG_ARABIC_LIBYA: return "ar_LY";
1530 case SUBLANG_ARABIC_ALGERIA: return "ar_DZ";
1531 case SUBLANG_ARABIC_MOROCCO: return "ar_MA";
1532 case SUBLANG_ARABIC_TUNISIA: return "ar_TN";
1533 case SUBLANG_ARABIC_OMAN: return "ar_OM";
1534 case SUBLANG_ARABIC_YEMEN: return "ar_YE";
1535 case SUBLANG_ARABIC_SYRIA: return "ar_SY";
1536 case SUBLANG_ARABIC_JORDAN: return "ar_JO";
1537 case SUBLANG_ARABIC_LEBANON: return "ar_LB";
1538 case SUBLANG_ARABIC_KUWAIT: return "ar_KW";
1539 case SUBLANG_ARABIC_UAE: return "ar_AE";
1540 case SUBLANG_ARABIC_BAHRAIN: return "ar_BH";
1541 case SUBLANG_ARABIC_QATAR: return "ar_QA";
1547 case SUBLANG_ARMENIAN_ARMENIA: return "hy_AM";
1553 case SUBLANG_ASSAMESE_INDIA: return "as_IN";
1559 /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */
1560 case 0x1e: return "az@latin";
1561 case SUBLANG_AZERI_LATIN: return "az_AZ@latin";
1562 case 0x1d: return "az@cyrillic";
1563 case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic";
1569 case SUBLANG_BASHKIR_RUSSIA: return "ba_RU";
1575 case SUBLANG_BASQUE_BASQUE: return "eu_ES";
1577 return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */
1578 case LANG_BELARUSIAN:
1581 case SUBLANG_BELARUSIAN_BELARUS: return "be_BY";
1587 case SUBLANG_BENGALI_INDIA: return "bn_IN";
1588 case SUBLANG_BENGALI_BANGLADESH: return "bn_BD";
1594 case SUBLANG_BRETON_FRANCE: return "br_FR";
1597 case LANG_BULGARIAN:
1600 case SUBLANG_BULGARIAN_BULGARIA: return "bg_BG";
1606 case SUBLANG_DEFAULT: return "my_MM";
1609 case LANG_CAMBODIAN:
1612 case SUBLANG_CAMBODIAN_CAMBODIA: return "km_KH";
1618 case SUBLANG_CATALAN_SPAIN: return "ca_ES";
1624 case SUBLANG_DEFAULT: return "chr_US";
1630 case SUBLANG_CHINESE_TRADITIONAL: case 0x1f: return "zh_TW";
1631 case SUBLANG_CHINESE_SIMPLIFIED: case 0x00: return "zh_CN";
1632 case SUBLANG_CHINESE_HONGKONG: return "zh_HK"; /* traditional */
1633 case SUBLANG_CHINESE_SINGAPORE: return "zh_SG"; /* simplified */
1634 case SUBLANG_CHINESE_MACAU: return "zh_MO"; /* traditional */
1640 case SUBLANG_CORSICAN_FRANCE: return "co_FR";
1643 case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN == LANG_BOSNIAN
1644 * What used to be called Serbo-Croatian
1645 * should really now be two separate
1646 * languages because of political reasons.
1647 * (Says tml, who knows nothing about Serbian
1649 * (I can feel those flames coming already.)
1654 case 0x00: return "hr";
1655 case SUBLANG_CROATIAN_CROATIA: return "hr_HR";
1656 case SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN: return "hr_BA";
1658 case 0x1f: return "sr";
1659 case 0x1c: return "sr"; /* latin */
1660 case SUBLANG_SERBIAN_LATIN: return "sr_CS"; /* latin */
1661 case 0x09: return "sr_RS"; /* latin */
1662 case 0x0b: return "sr_ME"; /* latin */
1663 case 0x06: return "sr_BA"; /* latin */
1664 case 0x1b: return "sr@cyrillic";
1665 case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic";
1666 case 0x0a: return "sr_RS@cyrillic";
1667 case 0x0c: return "sr_ME@cyrillic";
1668 case 0x07: return "sr_BA@cyrillic";
1670 case 0x1e: return "bs";
1671 case 0x1a: return "bs"; /* latin */
1672 case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN: return "bs_BA"; /* latin */
1673 case 0x19: return "bs@cyrillic";
1674 case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC: return "bs_BA@cyrillic";
1680 case SUBLANG_CZECH_CZECH_REPUBLIC: return "cs_CZ";
1686 case SUBLANG_DANISH_DENMARK: return "da_DK";
1690 /* FIXME: Adjust this when such locales appear on Unix. */
1693 case SUBLANG_DARI_AFGHANISTAN: return "prs_AF";
1699 case SUBLANG_DIVEHI_MALDIVES: return "dv_MV";
1705 case SUBLANG_DUTCH: return "nl_NL";
1706 case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE";
1707 case SUBLANG_DUTCH_SURINAM: return "nl_SR";
1713 case SUBLANG_DEFAULT: return "bin_NG";
1719 /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought
1720 * English was the language spoken in England.
1723 case SUBLANG_ENGLISH_US: return "en_US";
1724 case SUBLANG_ENGLISH_UK: return "en_GB";
1725 case SUBLANG_ENGLISH_AUS: return "en_AU";
1726 case SUBLANG_ENGLISH_CAN: return "en_CA";
1727 case SUBLANG_ENGLISH_NZ: return "en_NZ";
1728 case SUBLANG_ENGLISH_EIRE: return "en_IE";
1729 case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA";
1730 case SUBLANG_ENGLISH_JAMAICA: return "en_JM";
1731 case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */
1732 case SUBLANG_ENGLISH_BELIZE: return "en_BZ";
1733 case SUBLANG_ENGLISH_TRINIDAD: return "en_TT";
1734 case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW";
1735 case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH";
1736 case SUBLANG_ENGLISH_INDONESIA: return "en_ID";
1737 case SUBLANG_ENGLISH_HONGKONG: return "en_HK";
1738 case SUBLANG_ENGLISH_INDIA: return "en_IN";
1739 case SUBLANG_ENGLISH_MALAYSIA: return "en_MY";
1740 case SUBLANG_ENGLISH_SINGAPORE: return "en_SG";
1746 case SUBLANG_ESTONIAN_ESTONIA: return "et_EE";
1752 case SUBLANG_FAEROESE_FAROE_ISLANDS: return "fo_FO";
1758 case SUBLANG_FARSI_IRAN: return "fa_IR";
1764 case SUBLANG_FINNISH_FINLAND: return "fi_FI";
1770 case SUBLANG_FRENCH: return "fr_FR";
1771 case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE";
1772 case SUBLANG_FRENCH_CANADIAN: return "fr_CA";
1773 case SUBLANG_FRENCH_SWISS: return "fr_CH";
1774 case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU";
1775 case SUBLANG_FRENCH_MONACO: return "fr_MC";
1776 case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */
1777 case SUBLANG_FRENCH_REUNION: return "fr_RE";
1778 case SUBLANG_FRENCH_CONGO: return "fr_CG";
1779 case SUBLANG_FRENCH_SENEGAL: return "fr_SN";
1780 case SUBLANG_FRENCH_CAMEROON: return "fr_CM";
1781 case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI";
1782 case SUBLANG_FRENCH_MALI: return "fr_ML";
1783 case SUBLANG_FRENCH_MOROCCO: return "fr_MA";
1784 case SUBLANG_FRENCH_HAITI: return "fr_HT";
1790 case SUBLANG_FRISIAN_NETHERLANDS: return "fy_NL";
1794 /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin. */
1797 case SUBLANG_DEFAULT: return "ff_NG";
1803 case 0x01: /* SCOTTISH */
1804 /* old, superseded by LANG_SCOTTISH_GAELIC */
1806 case SUBLANG_IRISH_IRELAND: return "ga_IE";
1812 case SUBLANG_GALICIAN_SPAIN: return "gl_ES";
1818 case SUBLANG_GEORGIAN_GEORGIA: return "ka_GE";
1824 case SUBLANG_GERMAN: return "de_DE";
1825 case SUBLANG_GERMAN_SWISS: return "de_CH";
1826 case SUBLANG_GERMAN_AUSTRIAN: return "de_AT";
1827 case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU";
1828 case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI";
1834 case SUBLANG_GREEK_GREECE: return "el_GR";
1837 case LANG_GREENLANDIC:
1840 case SUBLANG_GREENLANDIC_GREENLAND: return "kl_GL";
1846 case SUBLANG_DEFAULT: return "gn_PY";
1852 case SUBLANG_GUJARATI_INDIA: return "gu_IN";
1858 case 0x1f: return "ha";
1859 case SUBLANG_HAUSA_NIGERIA_LATIN: return "ha_NG";
1863 /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers)
1864 or Hawaii Creole English ("cpe_US", 600000 speakers)? */
1867 case SUBLANG_DEFAULT: return "cpe_US";
1873 case SUBLANG_HEBREW_ISRAEL: return "he_IL";
1879 case SUBLANG_HINDI_INDIA: return "hi_IN";
1882 case LANG_HUNGARIAN:
1885 case SUBLANG_HUNGARIAN_HUNGARY: return "hu_HU";
1891 case SUBLANG_DEFAULT: return "nic_NG";
1894 case LANG_ICELANDIC:
1897 case SUBLANG_ICELANDIC_ICELAND: return "is_IS";
1903 case SUBLANG_IGBO_NIGERIA: return "ig_NG";
1906 case LANG_INDONESIAN:
1909 case SUBLANG_INDONESIAN_INDONESIA: return "id_ID";
1912 case LANG_INUKTITUT:
1915 case 0x1e: return "iu"; /* syllabic */
1916 case SUBLANG_INUKTITUT_CANADA: return "iu_CA"; /* syllabic */
1917 case 0x1f: return "iu@latin";
1918 case SUBLANG_INUKTITUT_CANADA_LATIN: return "iu_CA@latin";
1924 case SUBLANG_ITALIAN: return "it_IT";
1925 case SUBLANG_ITALIAN_SWISS: return "it_CH";
1931 case SUBLANG_JAPANESE_JAPAN: return "ja_JP";
1937 case SUBLANG_KANNADA_INDIA: return "kn_IN";
1943 case SUBLANG_DEFAULT: return "kr_NG";
1949 case SUBLANG_DEFAULT: return "ks_PK";
1950 case SUBLANG_KASHMIRI_INDIA: return "ks_IN";
1956 case SUBLANG_KAZAK_KAZAKHSTAN: return "kk_KZ";
1960 /* FIXME: Adjust this when such locales appear on Unix. */
1963 case SUBLANG_KICHE_GUATEMALA: return "qut_GT";
1966 case LANG_KINYARWANDA:
1969 case SUBLANG_KINYARWANDA_RWANDA: return "rw_RW";
1973 /* FIXME: Adjust this when such locales appear on Unix. */
1976 case SUBLANG_KONKANI_INDIA: return "kok_IN";
1982 case SUBLANG_DEFAULT: return "ko_KR";
1988 case SUBLANG_KYRGYZ_KYRGYZSTAN: return "ky_KG";
1994 case SUBLANG_LAO_LAOS: return "lo_LA";
2000 case SUBLANG_DEFAULT: return "la_VA";
2006 case SUBLANG_LATVIAN_LATVIA: return "lv_LV";
2009 case LANG_LITHUANIAN:
2012 case SUBLANG_LITHUANIAN_LITHUANIA: return "lt_LT";
2015 case LANG_LUXEMBOURGISH:
2018 case SUBLANG_LUXEMBOURGISH_LUXEMBOURG: return "lb_LU";
2021 case LANG_MACEDONIAN:
2024 case SUBLANG_MACEDONIAN_MACEDONIA: return "mk_MK";
2030 case SUBLANG_MALAY_MALAYSIA: return "ms_MY";
2031 case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN";
2034 case LANG_MALAYALAM:
2037 case SUBLANG_MALAYALAM_INDIA: return "ml_IN";
2043 case SUBLANG_MALTESE_MALTA: return "mt_MT";
2047 /* FIXME: Adjust this when such locales appear on Unix. */
2050 case SUBLANG_DEFAULT: return "mni_IN";
2056 case SUBLANG_MAORI_NEW_ZEALAND: return "mi_NZ";
2059 case LANG_MAPUDUNGUN:
2062 case SUBLANG_MAPUDUNGUN_CHILE: return "arn_CL";
2068 case SUBLANG_MARATHI_INDIA: return "mr_IN";
2074 case SUBLANG_MOHAWK_CANADA: return "moh_CA";
2077 case LANG_MONGOLIAN:
2080 case SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA: case 0x1e: return "mn_MN";
2081 case SUBLANG_MONGOLIAN_PRC: case 0x1f: return "mn_CN";
2083 return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN". */
2087 case SUBLANG_NEPALI_NEPAL: return "ne_NP";
2088 case SUBLANG_NEPALI_INDIA: return "ne_IN";
2091 case LANG_NORWEGIAN:
2094 case 0x1f: return "nb";
2095 case SUBLANG_NORWEGIAN_BOKMAL: return "nb_NO";
2096 case 0x1e: return "nn";
2097 case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO";
2103 case SUBLANG_OCCITAN_FRANCE: return "oc_FR";
2109 case SUBLANG_ORIYA_INDIA: return "or_IN";
2115 case SUBLANG_DEFAULT: return "om_ET";
2118 case LANG_PAPIAMENTU:
2121 case SUBLANG_DEFAULT: return "pap_AN";
2127 case SUBLANG_PASHTO_AFGHANISTAN: return "ps_AF";
2129 return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF". */
2133 case SUBLANG_POLISH_POLAND: return "pl_PL";
2136 case LANG_PORTUGUESE:
2139 /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT.
2140 Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */
2141 case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR";
2142 case SUBLANG_PORTUGUESE: return "pt_PT";
2148 case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */
2149 case SUBLANG_PUNJABI_PAKISTAN: return "pa_PK"; /* Arabic script */
2153 /* Note: Microsoft uses the non-ISO language code "quz". */
2156 case SUBLANG_QUECHUA_BOLIVIA: return "qu_BO";
2157 case SUBLANG_QUECHUA_ECUADOR: return "qu_EC";
2158 case SUBLANG_QUECHUA_PERU: return "qu_PE";
2164 case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO";
2165 case SUBLANG_ROMANIAN_MOLDOVA: return "ro_MD";
2171 case SUBLANG_ROMANSH_SWITZERLAND: return "rm_CH";
2177 case SUBLANG_RUSSIAN_RUSSIA: return "ru_RU";
2178 case SUBLANG_RUSSIAN_MOLDAVIA: return "ru_MD";
2180 return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */
2185 case 0x00: return "se";
2186 case SUBLANG_SAMI_NORTHERN_NORWAY: return "se_NO";
2187 case SUBLANG_SAMI_NORTHERN_SWEDEN: return "se_SE";
2188 case SUBLANG_SAMI_NORTHERN_FINLAND: return "se_FI";
2190 case 0x1f: return "smj";
2191 case SUBLANG_SAMI_LULE_NORWAY: return "smj_NO";
2192 case SUBLANG_SAMI_LULE_SWEDEN: return "smj_SE";
2194 case 0x1e: return "sma";
2195 case SUBLANG_SAMI_SOUTHERN_NORWAY: return "sma_NO";
2196 case SUBLANG_SAMI_SOUTHERN_SWEDEN: return "sma_SE";
2198 case 0x1d: return "sms";
2199 case SUBLANG_SAMI_SKOLT_FINLAND: return "sms_FI";
2201 case 0x1c: return "smn";
2202 case SUBLANG_SAMI_INARI_FINLAND: return "smn_FI";
2204 return "se"; /* or "smi"? */
2208 case SUBLANG_SANSKRIT_INDIA: return "sa_IN";
2211 case LANG_SCOTTISH_GAELIC:
2214 case SUBLANG_DEFAULT: return "gd_GB";
2220 case SUBLANG_SINDHI_INDIA: return "sd_IN";
2221 case SUBLANG_SINDHI_PAKISTAN: return "sd_PK";
2222 /*case SUBLANG_SINDHI_AFGHANISTAN: return "sd_AF";*/
2225 case LANG_SINHALESE:
2228 case SUBLANG_SINHALESE_SRI_LANKA: return "si_LK";
2234 case SUBLANG_SLOVAK_SLOVAKIA: return "sk_SK";
2237 case LANG_SLOVENIAN:
2240 case SUBLANG_SLOVENIAN_SLOVENIA: return "sl_SI";
2246 case SUBLANG_DEFAULT: return "so_SO";
2250 /* FIXME: Adjust this when such locales appear on Unix. */
2254 case 0x00: return "hsb";
2255 case SUBLANG_UPPER_SORBIAN_GERMANY: return "hsb_DE";
2257 case 0x1f: return "dsb";
2258 case SUBLANG_LOWER_SORBIAN_GERMANY: return "dsb_DE";
2262 /* <http://www.microsoft.com/globaldev/reference/lcid-all.mspx> calls
2263 it "Sepedi"; according to
2264 <http://www.ethnologue.com/show_language.asp?code=nso>
2265 <http://www.ethnologue.com/show_language.asp?code=sot>
2266 it's the same as Northern Sotho. */
2269 case SUBLANG_SOTHO_SOUTH_AFRICA: return "nso_ZA";
2275 case SUBLANG_SPANISH: return "es_ES";
2276 case SUBLANG_SPANISH_MEXICAN: return "es_MX";
2277 case SUBLANG_SPANISH_MODERN:
2278 return "es_ES@modern"; /* not seen on Unix */
2279 case SUBLANG_SPANISH_GUATEMALA: return "es_GT";
2280 case SUBLANG_SPANISH_COSTA_RICA: return "es_CR";
2281 case SUBLANG_SPANISH_PANAMA: return "es_PA";
2282 case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO";
2283 case SUBLANG_SPANISH_VENEZUELA: return "es_VE";
2284 case SUBLANG_SPANISH_COLOMBIA: return "es_CO";
2285 case SUBLANG_SPANISH_PERU: return "es_PE";
2286 case SUBLANG_SPANISH_ARGENTINA: return "es_AR";
2287 case SUBLANG_SPANISH_ECUADOR: return "es_EC";
2288 case SUBLANG_SPANISH_CHILE: return "es_CL";
2289 case SUBLANG_SPANISH_URUGUAY: return "es_UY";
2290 case SUBLANG_SPANISH_PARAGUAY: return "es_PY";
2291 case SUBLANG_SPANISH_BOLIVIA: return "es_BO";
2292 case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV";
2293 case SUBLANG_SPANISH_HONDURAS: return "es_HN";
2294 case SUBLANG_SPANISH_NICARAGUA: return "es_NI";
2295 case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR";
2296 case SUBLANG_SPANISH_US: return "es_US";
2302 case SUBLANG_DEFAULT: return "bnt_TZ"; /* or "st_LS" or "nso_ZA"? */
2308 case SUBLANG_SWAHILI_KENYA: return "sw_KE";
2314 case SUBLANG_SWEDISH_SWEDEN: return "sv_SE";
2315 case SUBLANG_SWEDISH_FINLAND: return "sv_FI";
2321 case SUBLANG_SYRIAC_SYRIA: return "syr_SY"; /* An extinct language. */
2327 case SUBLANG_TAGALOG_PHILIPPINES: return "tl_PH"; /* or "fil_PH"? */
2329 return "tl"; /* or "fil"? */
2333 case 0x1f: return "tg";
2334 case SUBLANG_TAJIK_TAJIKISTAN: return "tg_TJ";
2337 case LANG_TAMAZIGHT:
2338 /* Note: Microsoft uses the non-ISO language code "tmz". */
2341 /* FIXME: Adjust this when Tamazight locales appear on Unix. */
2342 case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic";
2343 case 0x1f: return "ber@latin";
2344 case SUBLANG_TAMAZIGHT_ALGERIA_LATIN: return "ber_DZ@latin";
2350 case SUBLANG_TAMIL_INDIA: return "ta_IN";
2352 return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */
2356 case SUBLANG_TATAR_RUSSIA: return "tt_RU";
2362 case SUBLANG_TELUGU_INDIA: return "te_IN";
2368 case SUBLANG_THAI_THAILAND: return "th_TH";
2374 case SUBLANG_TIBETAN_PRC:
2375 /* Most Tibetans would not like "bo_CN". But Tibet does not yet
2376 have a country code of its own. */
2378 case SUBLANG_TIBETAN_BHUTAN: return "bo_BT";
2384 case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET";
2385 case SUBLANG_TIGRINYA_ERITREA: return "ti_ER";
2391 case SUBLANG_DEFAULT: return "ts_ZA";
2395 /* Spoken in South Africa, Botswana. */
2398 case SUBLANG_TSWANA_SOUTH_AFRICA: return "tn_ZA";
2404 case SUBLANG_TURKISH_TURKEY: return "tr_TR";
2410 case SUBLANG_TURKMEN_TURKMENISTAN: return "tk_TM";
2416 case SUBLANG_UIGHUR_PRC: return "ug_CN";
2419 case LANG_UKRAINIAN:
2422 case SUBLANG_UKRAINIAN_UKRAINE: return "uk_UA";
2428 case SUBLANG_URDU_PAKISTAN: return "ur_PK";
2429 case SUBLANG_URDU_INDIA: return "ur_IN";
2435 case 0x1f: return "uz";
2436 case SUBLANG_UZBEK_LATIN: return "uz_UZ";
2437 case 0x1e: return "uz@cyrillic";
2438 case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic";
2444 case SUBLANG_DEFAULT: return "ve_ZA";
2447 case LANG_VIETNAMESE:
2450 case SUBLANG_VIETNAMESE_VIETNAM: return "vi_VN";
2456 case SUBLANG_WELSH_UNITED_KINGDOM: return "cy_GB";
2462 case SUBLANG_WOLOF_SENEGAL: return "wo_SN";
2468 case SUBLANG_XHOSA_SOUTH_AFRICA: return "xh_ZA";
2474 case SUBLANG_YAKUT_RUSSIA: return "sah_RU";
2480 case SUBLANG_YI_PRC: return "ii_CN";
2486 case SUBLANG_DEFAULT: return "yi_IL";
2492 case SUBLANG_YORUBA_NIGERIA: return "yo_NG";
2498 case SUBLANG_ZULU_SOUTH_AFRICA: return "zu_ZA";
2501 default: return "C";
2506 # if !defined IN_LIBINTL
2510 gl_locale_name_from_win32_LCID (LCID lcid)
2514 /* Strip off the sorting rules, keep only the language part. */
2515 langid = LANGIDFROMLCID (lcid);
2517 return gl_locale_name_from_win32_LANGID (langid);
2520 # ifdef WINDOWS_NATIVE
2522 /* Two variables to interface between get_lcid and the EnumLocales
2523 callback function below. */
2524 static LCID found_lcid;
2525 static char lname[LC_MAX * (LOCALE_NAME_MAX_LENGTH + 1) + 1];
2527 /* Callback function for EnumLocales. */
2528 static BOOL CALLBACK
2529 enum_locales_fn (LPTSTR locale_num_str)
2532 char locval[2 * LOCALE_NAME_MAX_LENGTH + 1 + 1];
2533 LCID try_lcid = strtoul (locale_num_str, &endp, 16);
2535 if (GetLocaleInfo (try_lcid, LOCALE_SENGLANGUAGE,
2536 locval, LOCALE_NAME_MAX_LENGTH))
2538 strcat (locval, "_");
2539 if (GetLocaleInfo (try_lcid, LOCALE_SENGCOUNTRY,
2540 locval + strlen (locval), LOCALE_NAME_MAX_LENGTH))
2542 size_t locval_len = strlen (locval);
2544 if (strncmp (locval, lname, locval_len) == 0
2545 && (lname[locval_len] == '.'
2546 || lname[locval_len] == '\0'))
2548 found_lcid = try_lcid;
2556 /* This lock protects the get_lcid against multiple simultaneous calls. */
2557 gl_lock_define_initialized(static, get_lcid_lock)
2559 /* Return the Locale ID (LCID) number given the locale's name, a
2560 string, in LOCALE_NAME. This works by enumerating all the locales
2561 supported by the system, until we find one whose name matches
2564 get_lcid (const char *locale_name)
2566 /* A simple cache. */
2567 static LCID last_lcid;
2568 static char last_locale[1000];
2570 /* Lock while looking for an LCID, to protect access to static
2571 variables: last_lcid, last_locale, found_lcid, and lname. */
2572 gl_lock_lock (get_lcid_lock);
2573 if (last_lcid > 0 && strcmp (locale_name, last_locale) == 0)
2575 gl_lock_unlock (get_lcid_lock);
2578 strncpy (lname, locale_name, sizeof (lname) - 1);
2579 lname[sizeof (lname) - 1] = '\0';
2581 EnumSystemLocales (enum_locales_fn, LCID_SUPPORTED);
2584 last_lcid = found_lcid;
2585 strcpy (last_locale, locale_name);
2587 gl_lock_unlock (get_lcid_lock);
2595 #if HAVE_USELOCALE /* glibc, Solaris >= 12 or Mac OS X */
2597 /* Simple hash set of strings. We don't want to drag in lots of hash table
2600 # define SIZE_BITS (sizeof (size_t) * CHAR_BIT)
2602 /* A hash function for NUL-terminated char* strings using
2603 the method described by Bruno Haible.
2604 See http://www.haible.de/bruno/hashfunc.html. */
2605 static size_t _GL_ATTRIBUTE_PURE
2606 string_hash (const void *x)
2608 const char *s = (const char *) x;
2612 h = *s + ((h << 9) | (h >> (SIZE_BITS - 9)));
2617 /* A hash table of fixed size. Multiple threads can access it read-only
2618 simultaneously, but only one thread can insert into it at the same time. */
2620 /* A node in a hash bucket collision list. */
2623 struct hash_node * volatile next;
2624 char contents[FLEXIBLE_ARRAY_MEMBER];
2627 # define HASH_TABLE_SIZE 257
2628 static struct hash_node * volatile struniq_hash_table[HASH_TABLE_SIZE]
2629 /* = { NULL, ..., NULL } */;
2631 /* This lock protects the struniq_hash_table against multiple simultaneous
2633 gl_lock_define_initialized(static, struniq_lock)
2635 /* Store a copy of the given string in a string pool with indefinite extent.
2636 Return a pointer to this copy. */
2638 struniq (const char *string)
2640 size_t hashcode = string_hash (string);
2641 size_t slot = hashcode % HASH_TABLE_SIZE;
2643 struct hash_node *new_node;
2644 struct hash_node *p;
2645 for (p = struniq_hash_table[slot]; p != NULL; p = p->next)
2646 if (strcmp (p->contents, string) == 0)
2648 size = strlen (string) + 1;
2650 (struct hash_node *)
2651 malloc (FLEXSIZEOF (struct hash_node, contents, size));
2652 if (new_node == NULL)
2653 /* Out of memory. Return a statically allocated string. */
2655 memcpy (new_node->contents, string, size);
2656 /* Lock while inserting new_node. */
2657 gl_lock_lock (struniq_lock);
2658 /* Check whether another thread already added the string while we were
2659 waiting on the lock. */
2660 for (p = struniq_hash_table[slot]; p != NULL; p = p->next)
2661 if (strcmp (p->contents, string) == 0)
2667 /* Really insert new_node into the hash table. Fill new_node entirely first,
2668 because other threads may be iterating over the linked list. */
2669 new_node->next = struniq_hash_table[slot];
2670 struniq_hash_table[slot] = new_node;
2672 /* Unlock after new_node is inserted. */
2673 gl_lock_unlock (struniq_lock);
2674 return new_node->contents;
2680 #if defined IN_LIBINTL || HAVE_USELOCALE
2682 /* Like gl_locale_name_thread, except that the result is not in storage of
2683 indefinite extent. */
2684 # if !defined IN_LIBINTL
2688 gl_locale_name_thread_unsafe (int category, const char *categoryname)
2692 locale_t thread_locale = uselocale (NULL);
2693 if (thread_locale != LC_GLOBAL_LOCALE)
2695 # if __GLIBC__ >= 2 && !defined __UCLIBC__
2696 /* Work around an incorrect definition of the _NL_LOCALE_NAME macro in
2698 See <http://sourceware.org/bugzilla/show_bug.cgi?id=10968>. */
2700 nl_langinfo (_NL_ITEM ((category), _NL_ITEM_INDEX (-1)));
2701 if (name[0] == '\0')
2702 /* Fallback code for glibc < 2.4, which did not implement
2703 nl_langinfo (_NL_LOCALE_NAME (category)). */
2704 name = thread_locale->__names[category];
2706 # elif defined __FreeBSD__ || (defined __APPLE__ && defined __MACH__)
2707 /* FreeBSD, Mac OS X */
2713 mask = LC_CTYPE_MASK;
2716 mask = LC_NUMERIC_MASK;
2719 mask = LC_TIME_MASK;
2722 mask = LC_COLLATE_MASK;
2725 mask = LC_MONETARY_MASK;
2728 mask = LC_MESSAGES_MASK;
2730 default: /* We shouldn't get here. */
2733 return querylocale (mask, thread_locale);
2734 # elif defined __sun && HAVE_GETLOCALENAME_L
2735 /* Solaris >= 12. */
2736 return getlocalename_l (category, thread_locale);
2737 # elif defined __ANDROID__
2738 return MB_CUR_MAX == 4 ? "C.UTF-8" : "C";
2749 gl_locale_name_thread (int category, const char *categoryname)
2752 const char *name = gl_locale_name_thread_unsafe (category, categoryname);
2754 return struniq (name);
2755 #elif defined WINDOWS_NATIVE
2756 if (LC_MIN <= category && category <= LC_MAX)
2758 char *locname = setlocale (category, NULL);
2761 /* If CATEGORY is LC_ALL, the result might be a semi-colon
2762 separated list of locales. We need only one, so we take the
2763 one corresponding to LC_CTYPE, as the most important for
2764 character translations. */
2765 if (strchr (locname, ';'))
2766 locname = setlocale (LC_CTYPE, NULL);
2768 /* Convert locale name to LCID. We don't want to use
2769 LocaleNameToLCID because (a) it is only available since Vista,
2770 and (b) it doesn't accept locale names returned by 'setlocale'. */
2771 lcid = get_lcid (locname);
2774 return gl_locale_name_from_win32_LCID (lcid);
2780 /* XPG3 defines the result of 'setlocale (category, NULL)' as:
2781 "Directs 'setlocale()' to query 'category' and return the current
2782 setting of 'local'."
2783 However it does not specify the exact format. Neither do SUSV2 and
2784 ISO C 99. So we can use this feature only on selected systems (e.g.
2785 those using GNU C Library). */
2786 #if defined _LIBC || ((defined __GLIBC__ && __GLIBC__ >= 2) && !defined __UCLIBC__)
2787 # define HAVE_LOCALE_NULL
2791 gl_locale_name_posix (int category, const char *categoryname)
2793 /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
2794 On some systems this can be done by the 'setlocale' function itself. */
2795 #if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
2796 return setlocale (category, NULL);
2798 /* On other systems we ignore what setlocale reports and instead look at the
2799 environment variables directly. This is necessary
2800 1. on systems which have a facility for customizing the default locale
2801 (Mac OS X, native Windows, Cygwin) and where the system's setlocale()
2802 function ignores this default locale (Mac OS X, Cygwin), in two cases:
2803 a. when the user missed to use the setlocale() override from libintl
2804 (for example by not including <libintl.h>),
2805 b. when setlocale supports only the "C" locale, such as on Cygwin
2806 1.5.x. In this case even the override from libintl cannot help.
2807 2. on all systems where setlocale supports only the "C" locale. */
2808 /* Strictly speaking, it is a POSIX violation to look at the environment
2809 variables regardless whether setlocale has been called or not. POSIX
2811 "For C-language programs, the POSIX locale shall be the
2812 default locale when the setlocale() function is not called."
2813 But we assume that all programs that use internationalized APIs call
2814 setlocale (LC_ALL, ""). */
2815 return gl_locale_name_environ (category, categoryname);
2820 gl_locale_name_environ (int category, const char *categoryname)
2824 /* Setting of LC_ALL overrides all other. */
2825 retval = getenv ("LC_ALL");
2826 if (retval != NULL && retval[0] != '\0')
2828 /* Next comes the name of the desired category. */
2829 retval = getenv (categoryname);
2830 if (retval != NULL && retval[0] != '\0')
2832 /* Last possibility is the LANG environment variable. */
2833 retval = getenv ("LANG");
2834 if (retval != NULL && retval[0] != '\0')
2836 #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
2837 /* Mac OS X 10.2 or newer.
2838 Ignore invalid LANG value set by the Terminal application. */
2839 if (strcmp (retval, "UTF-8") != 0)
2841 #if defined __CYGWIN__
2843 Ignore dummy LANG value set by ~/.profile. */
2844 if (strcmp (retval, "C.UTF-8") != 0)
2853 gl_locale_name_default (void)
2856 "All implementations shall define a locale as the default locale, to be
2857 invoked when no environment variables are set, or set to the empty
2858 string. This default locale can be the POSIX locale or any other
2859 implementation-defined locale. Some implementations may provide
2860 facilities for local installation administrators to set the default
2861 locale, customizing it for each location. POSIX:2001 does not require
2864 The systems with such a facility are Mac OS X and Windows: They provide a
2865 GUI that allows the user to choose a locale.
2866 - On Mac OS X, by default, none of LC_* or LANG are set. Starting with
2867 Mac OS X 10.4 or 10.5, LANG is set for processes launched by the
2868 'Terminal' application (but sometimes to an incorrect value "UTF-8").
2869 When no environment variable is set, setlocale (LC_ALL, "") uses the
2871 - On native Windows, by default, none of LC_* or LANG are set.
2872 When no environment variable is set, setlocale (LC_ALL, "") uses the
2873 locale chosen by the user.
2874 - On Cygwin 1.5.x, by default, none of LC_* or LANG are set.
2875 When no environment variable is set, setlocale (LC_ALL, "") uses the
2877 - On Cygwin 1.7, by default, LANG is set to "C.UTF-8" when the default
2878 ~/.profile is executed.
2879 When no environment variable is set, setlocale (LC_ALL, "") uses the
2880 "C.UTF-8" locale, which operates in the same way as the "C" locale.
2883 #if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined WINDOWS_NATIVE || defined __CYGWIN__)
2885 /* The system does not have a way of setting the locale, other than the
2886 POSIX specified environment variables. We use C as default locale. */
2891 /* Return an XPG style locale name language[_territory][@modifier].
2892 Don't even bother determining the codeset; it's not useful in this
2893 context, because message catalogs are not specific to a single
2896 # if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
2897 /* Mac OS X 10.2 or newer */
2899 /* Cache the locale name, since CoreFoundation calls are expensive. */
2900 static const char *cached_localename;
2902 if (cached_localename == NULL)
2905 # if HAVE_CFLOCALECOPYCURRENT /* Mac OS X 10.3 or newer */
2906 CFLocaleRef locale = CFLocaleCopyCurrent ();
2907 CFStringRef name = CFLocaleGetIdentifier (locale);
2909 if (CFStringGetCString (name, namebuf, sizeof (namebuf),
2910 kCFStringEncodingASCII))
2912 gl_locale_name_canonicalize (namebuf);
2913 cached_localename = strdup (namebuf);
2916 # elif HAVE_CFPREFERENCESCOPYAPPVALUE /* Mac OS X 10.2 or newer */
2918 CFPreferencesCopyAppValue (CFSTR ("AppleLocale"),
2919 kCFPreferencesCurrentApplication);
2921 && CFGetTypeID (value) == CFStringGetTypeID ()
2922 && CFStringGetCString ((CFStringRef)value,
2923 namebuf, sizeof (namebuf),
2924 kCFStringEncodingASCII))
2926 gl_locale_name_canonicalize (namebuf);
2927 cached_localename = strdup (namebuf);
2930 if (cached_localename == NULL)
2931 cached_localename = "C";
2933 return cached_localename;
2938 # if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Native Windows or Cygwin */
2942 /* Use native Windows API locale ID. */
2943 lcid = GetThreadLocale ();
2945 return gl_locale_name_from_win32_LCID (lcid);
2951 /* Determine the current locale's name, and canonicalize it into XPG syntax
2952 language[_territory][.codeset][@modifier]
2953 The codeset part in the result is not reliable; the locale_charset()
2954 should be used for codeset information instead.
2955 The result must not be freed; it is statically allocated. */
2958 gl_locale_name (int category, const char *categoryname)
2962 retval = gl_locale_name_thread (category, categoryname);
2966 retval = gl_locale_name_posix (category, categoryname);
2970 return gl_locale_name_default ();