1 /* Determine name of the currently selected locale.
2 Copyright (C) 1995-1999, 2000-2009 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published
6 by the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 /* Written by Ulrich Drepper <drepper@gnu.org>, 1995. */
20 /* Win32 code written by Tor Lillqvist <tml@iki.fi>. */
21 /* MacOS X code written by Bruno Haible <bruno@clisp.org>. */
27 # include "gettextP.h"
29 # include "localename.h"
36 #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
37 # include <CoreFoundation/CFString.h>
38 # if HAVE_CFLOCALECOPYCURRENT
39 # include <CoreFoundation/CFLocale.h>
40 # elif HAVE_CFPREFERENCESCOPYAPPVALUE
41 # include <CoreFoundation/CFPreferences.h>
45 #if defined _WIN32 || defined __WIN32__
49 #if defined WIN32_NATIVE || defined __CYGWIN__ /* WIN32 or Cygwin */
50 # define WIN32_LEAN_AND_MEAN
52 /* List of language codes, sorted by value:
78 0x1a LANG_CROATIAN == LANG_SERBIAN
160 0x6e LANG_LUXEMBOURGISH
161 0x6f LANG_GREENLANDIC
180 0x87 LANG_KINYARWANDA
183 0x91 LANG_SCOTTISH_GAELIC
185 /* Mingw headers don't have latest language and sublanguage codes. */
186 # ifndef LANG_AFRIKAANS
187 # define LANG_AFRIKAANS 0x36
189 # ifndef LANG_ALBANIAN
190 # define LANG_ALBANIAN 0x1c
192 # ifndef LANG_ALSATIAN
193 # define LANG_ALSATIAN 0x84
195 # ifndef LANG_AMHARIC
196 # define LANG_AMHARIC 0x5e
199 # define LANG_ARABIC 0x01
201 # ifndef LANG_ARMENIAN
202 # define LANG_ARMENIAN 0x2b
204 # ifndef LANG_ASSAMESE
205 # define LANG_ASSAMESE 0x4d
208 # define LANG_AZERI 0x2c
210 # ifndef LANG_BASHKIR
211 # define LANG_BASHKIR 0x6d
214 # define LANG_BASQUE 0x2d
216 # ifndef LANG_BELARUSIAN
217 # define LANG_BELARUSIAN 0x23
219 # ifndef LANG_BENGALI
220 # define LANG_BENGALI 0x45
223 # define LANG_BRETON 0x7e
225 # ifndef LANG_BURMESE
226 # define LANG_BURMESE 0x55
228 # ifndef LANG_CAMBODIAN
229 # define LANG_CAMBODIAN 0x53
231 # ifndef LANG_CATALAN
232 # define LANG_CATALAN 0x03
234 # ifndef LANG_CHEROKEE
235 # define LANG_CHEROKEE 0x5c
237 # ifndef LANG_CORSICAN
238 # define LANG_CORSICAN 0x83
241 # define LANG_DARI 0x8c
244 # define LANG_DIVEHI 0x65
247 # define LANG_EDO 0x66
249 # ifndef LANG_ESTONIAN
250 # define LANG_ESTONIAN 0x25
252 # ifndef LANG_FAEROESE
253 # define LANG_FAEROESE 0x38
256 # define LANG_FARSI 0x29
258 # ifndef LANG_FRISIAN
259 # define LANG_FRISIAN 0x62
261 # ifndef LANG_FULFULDE
262 # define LANG_FULFULDE 0x67
265 # define LANG_GAELIC 0x3c
267 # ifndef LANG_GALICIAN
268 # define LANG_GALICIAN 0x56
270 # ifndef LANG_GEORGIAN
271 # define LANG_GEORGIAN 0x37
273 # ifndef LANG_GREENLANDIC
274 # define LANG_GREENLANDIC 0x6f
276 # ifndef LANG_GUARANI
277 # define LANG_GUARANI 0x74
279 # ifndef LANG_GUJARATI
280 # define LANG_GUJARATI 0x47
283 # define LANG_HAUSA 0x68
285 # ifndef LANG_HAWAIIAN
286 # define LANG_HAWAIIAN 0x75
289 # define LANG_HEBREW 0x0d
292 # define LANG_HINDI 0x39
295 # define LANG_IBIBIO 0x69
298 # define LANG_IGBO 0x70
300 # ifndef LANG_INDONESIAN
301 # define LANG_INDONESIAN 0x21
303 # ifndef LANG_INUKTITUT
304 # define LANG_INUKTITUT 0x5d
306 # ifndef LANG_KANNADA
307 # define LANG_KANNADA 0x4b
310 # define LANG_KANURI 0x71
312 # ifndef LANG_KASHMIRI
313 # define LANG_KASHMIRI 0x60
316 # define LANG_KAZAK 0x3f
319 # define LANG_KICHE 0x86
321 # ifndef LANG_KINYARWANDA
322 # define LANG_KINYARWANDA 0x87
324 # ifndef LANG_KONKANI
325 # define LANG_KONKANI 0x57
328 # define LANG_KYRGYZ 0x40
331 # define LANG_LAO 0x54
334 # define LANG_LATIN 0x76
336 # ifndef LANG_LATVIAN
337 # define LANG_LATVIAN 0x26
339 # ifndef LANG_LITHUANIAN
340 # define LANG_LITHUANIAN 0x27
342 # ifndef LANG_LUXEMBOURGISH
343 # define LANG_LUXEMBOURGISH 0x6e
345 # ifndef LANG_MACEDONIAN
346 # define LANG_MACEDONIAN 0x2f
349 # define LANG_MALAY 0x3e
351 # ifndef LANG_MALAYALAM
352 # define LANG_MALAYALAM 0x4c
354 # ifndef LANG_MALTESE
355 # define LANG_MALTESE 0x3a
357 # ifndef LANG_MANIPURI
358 # define LANG_MANIPURI 0x58
361 # define LANG_MAORI 0x81
363 # ifndef LANG_MAPUDUNGUN
364 # define LANG_MAPUDUNGUN 0x7a
366 # ifndef LANG_MARATHI
367 # define LANG_MARATHI 0x4e
370 # define LANG_MOHAWK 0x7c
372 # ifndef LANG_MONGOLIAN
373 # define LANG_MONGOLIAN 0x50
376 # define LANG_NEPALI 0x61
378 # ifndef LANG_OCCITAN
379 # define LANG_OCCITAN 0x82
382 # define LANG_ORIYA 0x48
385 # define LANG_OROMO 0x72
387 # ifndef LANG_PAPIAMENTU
388 # define LANG_PAPIAMENTU 0x79
391 # define LANG_PASHTO 0x63
393 # ifndef LANG_PUNJABI
394 # define LANG_PUNJABI 0x46
396 # ifndef LANG_QUECHUA
397 # define LANG_QUECHUA 0x6b
399 # ifndef LANG_ROMANSH
400 # define LANG_ROMANSH 0x17
403 # define LANG_SAMI 0x3b
405 # ifndef LANG_SANSKRIT
406 # define LANG_SANSKRIT 0x4f
408 # ifndef LANG_SCOTTISH_GAELIC
409 # define LANG_SCOTTISH_GAELIC 0x91
411 # ifndef LANG_SERBIAN
412 # define LANG_SERBIAN 0x1a
415 # define LANG_SINDHI 0x59
417 # ifndef LANG_SINHALESE
418 # define LANG_SINHALESE 0x5b
421 # define LANG_SLOVAK 0x1b
424 # define LANG_SOMALI 0x77
426 # ifndef LANG_SORBIAN
427 # define LANG_SORBIAN 0x2e
430 # define LANG_SOTHO 0x6c
433 # define LANG_SUTU 0x30
435 # ifndef LANG_SWAHILI
436 # define LANG_SWAHILI 0x41
439 # define LANG_SYRIAC 0x5a
441 # ifndef LANG_TAGALOG
442 # define LANG_TAGALOG 0x64
445 # define LANG_TAJIK 0x28
447 # ifndef LANG_TAMAZIGHT
448 # define LANG_TAMAZIGHT 0x5f
451 # define LANG_TAMIL 0x49
454 # define LANG_TATAR 0x44
457 # define LANG_TELUGU 0x4a
460 # define LANG_THAI 0x1e
462 # ifndef LANG_TIBETAN
463 # define LANG_TIBETAN 0x51
465 # ifndef LANG_TIGRINYA
466 # define LANG_TIGRINYA 0x73
469 # define LANG_TSONGA 0x31
472 # define LANG_TSWANA 0x32
474 # ifndef LANG_TURKMEN
475 # define LANG_TURKMEN 0x42
478 # define LANG_UIGHUR 0x80
480 # ifndef LANG_UKRAINIAN
481 # define LANG_UKRAINIAN 0x22
484 # define LANG_URDU 0x20
487 # define LANG_UZBEK 0x43
490 # define LANG_VENDA 0x33
492 # ifndef LANG_VIETNAMESE
493 # define LANG_VIETNAMESE 0x2a
496 # define LANG_WELSH 0x52
499 # define LANG_WOLOF 0x88
502 # define LANG_XHOSA 0x34
505 # define LANG_YAKUT 0x85
508 # define LANG_YI 0x78
510 # ifndef LANG_YIDDISH
511 # define LANG_YIDDISH 0x3d
514 # define LANG_YORUBA 0x6a
517 # define LANG_ZULU 0x35
519 # ifndef SUBLANG_AFRIKAANS_SOUTH_AFRICA
520 # define SUBLANG_AFRIKAANS_SOUTH_AFRICA 0x01
522 # ifndef SUBLANG_ALBANIAN_ALBANIA
523 # define SUBLANG_ALBANIAN_ALBANIA 0x01
525 # ifndef SUBLANG_ALSATIAN_FRANCE
526 # define SUBLANG_ALSATIAN_FRANCE 0x01
528 # ifndef SUBLANG_AMHARIC_ETHIOPIA
529 # define SUBLANG_AMHARIC_ETHIOPIA 0x01
531 # ifndef SUBLANG_ARABIC_SAUDI_ARABIA
532 # define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
534 # ifndef SUBLANG_ARABIC_IRAQ
535 # define SUBLANG_ARABIC_IRAQ 0x02
537 # ifndef SUBLANG_ARABIC_EGYPT
538 # define SUBLANG_ARABIC_EGYPT 0x03
540 # ifndef SUBLANG_ARABIC_LIBYA
541 # define SUBLANG_ARABIC_LIBYA 0x04
543 # ifndef SUBLANG_ARABIC_ALGERIA
544 # define SUBLANG_ARABIC_ALGERIA 0x05
546 # ifndef SUBLANG_ARABIC_MOROCCO
547 # define SUBLANG_ARABIC_MOROCCO 0x06
549 # ifndef SUBLANG_ARABIC_TUNISIA
550 # define SUBLANG_ARABIC_TUNISIA 0x07
552 # ifndef SUBLANG_ARABIC_OMAN
553 # define SUBLANG_ARABIC_OMAN 0x08
555 # ifndef SUBLANG_ARABIC_YEMEN
556 # define SUBLANG_ARABIC_YEMEN 0x09
558 # ifndef SUBLANG_ARABIC_SYRIA
559 # define SUBLANG_ARABIC_SYRIA 0x0a
561 # ifndef SUBLANG_ARABIC_JORDAN
562 # define SUBLANG_ARABIC_JORDAN 0x0b
564 # ifndef SUBLANG_ARABIC_LEBANON
565 # define SUBLANG_ARABIC_LEBANON 0x0c
567 # ifndef SUBLANG_ARABIC_KUWAIT
568 # define SUBLANG_ARABIC_KUWAIT 0x0d
570 # ifndef SUBLANG_ARABIC_UAE
571 # define SUBLANG_ARABIC_UAE 0x0e
573 # ifndef SUBLANG_ARABIC_BAHRAIN
574 # define SUBLANG_ARABIC_BAHRAIN 0x0f
576 # ifndef SUBLANG_ARABIC_QATAR
577 # define SUBLANG_ARABIC_QATAR 0x10
579 # ifndef SUBLANG_ARMENIAN_ARMENIA
580 # define SUBLANG_ARMENIAN_ARMENIA 0x01
582 # ifndef SUBLANG_ASSAMESE_INDIA
583 # define SUBLANG_ASSAMESE_INDIA 0x01
585 # ifndef SUBLANG_AZERI_LATIN
586 # define SUBLANG_AZERI_LATIN 0x01
588 # ifndef SUBLANG_AZERI_CYRILLIC
589 # define SUBLANG_AZERI_CYRILLIC 0x02
591 # ifndef SUBLANG_BASHKIR_RUSSIA
592 # define SUBLANG_BASHKIR_RUSSIA 0x01
594 # ifndef SUBLANG_BASQUE_BASQUE
595 # define SUBLANG_BASQUE_BASQUE 0x01
597 # ifndef SUBLANG_BELARUSIAN_BELARUS
598 # define SUBLANG_BELARUSIAN_BELARUS 0x01
600 # ifndef SUBLANG_BENGALI_INDIA
601 # define SUBLANG_BENGALI_INDIA 0x01
603 # ifndef SUBLANG_BENGALI_BANGLADESH
604 # define SUBLANG_BENGALI_BANGLADESH 0x02
606 # ifndef SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN
607 # define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN 0x05
609 # ifndef SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC
610 # define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC 0x08
612 # ifndef SUBLANG_BRETON_FRANCE
613 # define SUBLANG_BRETON_FRANCE 0x01
615 # ifndef SUBLANG_BULGARIAN_BULGARIA
616 # define SUBLANG_BULGARIAN_BULGARIA 0x01
618 # ifndef SUBLANG_CAMBODIAN_CAMBODIA
619 # define SUBLANG_CAMBODIAN_CAMBODIA 0x01
621 # ifndef SUBLANG_CATALAN_SPAIN
622 # define SUBLANG_CATALAN_SPAIN 0x01
624 # ifndef SUBLANG_CORSICAN_FRANCE
625 # define SUBLANG_CORSICAN_FRANCE 0x01
627 # ifndef SUBLANG_CROATIAN_CROATIA
628 # define SUBLANG_CROATIAN_CROATIA 0x01
630 # ifndef SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN
631 # define SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN 0x04
633 # ifndef SUBLANG_CHINESE_MACAU
634 # define SUBLANG_CHINESE_MACAU 0x05
636 # ifndef SUBLANG_CZECH_CZECH_REPUBLIC
637 # define SUBLANG_CZECH_CZECH_REPUBLIC 0x01
639 # ifndef SUBLANG_DANISH_DENMARK
640 # define SUBLANG_DANISH_DENMARK 0x01
642 # ifndef SUBLANG_DARI_AFGHANISTAN
643 # define SUBLANG_DARI_AFGHANISTAN 0x01
645 # ifndef SUBLANG_DIVEHI_MALDIVES
646 # define SUBLANG_DIVEHI_MALDIVES 0x01
648 # ifndef SUBLANG_DUTCH_SURINAM
649 # define SUBLANG_DUTCH_SURINAM 0x03
651 # ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
652 # define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
654 # ifndef SUBLANG_ENGLISH_JAMAICA
655 # define SUBLANG_ENGLISH_JAMAICA 0x08
657 # ifndef SUBLANG_ENGLISH_CARIBBEAN
658 # define SUBLANG_ENGLISH_CARIBBEAN 0x09
660 # ifndef SUBLANG_ENGLISH_BELIZE
661 # define SUBLANG_ENGLISH_BELIZE 0x0a
663 # ifndef SUBLANG_ENGLISH_TRINIDAD
664 # define SUBLANG_ENGLISH_TRINIDAD 0x0b
666 # ifndef SUBLANG_ENGLISH_ZIMBABWE
667 # define SUBLANG_ENGLISH_ZIMBABWE 0x0c
669 # ifndef SUBLANG_ENGLISH_PHILIPPINES
670 # define SUBLANG_ENGLISH_PHILIPPINES 0x0d
672 # ifndef SUBLANG_ENGLISH_INDONESIA
673 # define SUBLANG_ENGLISH_INDONESIA 0x0e
675 # ifndef SUBLANG_ENGLISH_HONGKONG
676 # define SUBLANG_ENGLISH_HONGKONG 0x0f
678 # ifndef SUBLANG_ENGLISH_INDIA
679 # define SUBLANG_ENGLISH_INDIA 0x10
681 # ifndef SUBLANG_ENGLISH_MALAYSIA
682 # define SUBLANG_ENGLISH_MALAYSIA 0x11
684 # ifndef SUBLANG_ENGLISH_SINGAPORE
685 # define SUBLANG_ENGLISH_SINGAPORE 0x12
687 # ifndef SUBLANG_ESTONIAN_ESTONIA
688 # define SUBLANG_ESTONIAN_ESTONIA 0x01
690 # ifndef SUBLANG_FAEROESE_FAROE_ISLANDS
691 # define SUBLANG_FAEROESE_FAROE_ISLANDS 0x01
693 # ifndef SUBLANG_FARSI_IRAN
694 # define SUBLANG_FARSI_IRAN 0x01
696 # ifndef SUBLANG_FINNISH_FINLAND
697 # define SUBLANG_FINNISH_FINLAND 0x01
699 # ifndef SUBLANG_FRENCH_LUXEMBOURG
700 # define SUBLANG_FRENCH_LUXEMBOURG 0x05
702 # ifndef SUBLANG_FRENCH_MONACO
703 # define SUBLANG_FRENCH_MONACO 0x06
705 # ifndef SUBLANG_FRENCH_WESTINDIES
706 # define SUBLANG_FRENCH_WESTINDIES 0x07
708 # ifndef SUBLANG_FRENCH_REUNION
709 # define SUBLANG_FRENCH_REUNION 0x08
711 # ifndef SUBLANG_FRENCH_CONGO
712 # define SUBLANG_FRENCH_CONGO 0x09
714 # ifndef SUBLANG_FRENCH_SENEGAL
715 # define SUBLANG_FRENCH_SENEGAL 0x0a
717 # ifndef SUBLANG_FRENCH_CAMEROON
718 # define SUBLANG_FRENCH_CAMEROON 0x0b
720 # ifndef SUBLANG_FRENCH_COTEDIVOIRE
721 # define SUBLANG_FRENCH_COTEDIVOIRE 0x0c
723 # ifndef SUBLANG_FRENCH_MALI
724 # define SUBLANG_FRENCH_MALI 0x0d
726 # ifndef SUBLANG_FRENCH_MOROCCO
727 # define SUBLANG_FRENCH_MOROCCO 0x0e
729 # ifndef SUBLANG_FRENCH_HAITI
730 # define SUBLANG_FRENCH_HAITI 0x0f
732 # ifndef SUBLANG_FRISIAN_NETHERLANDS
733 # define SUBLANG_FRISIAN_NETHERLANDS 0x01
735 # ifndef SUBLANG_GALICIAN_SPAIN
736 # define SUBLANG_GALICIAN_SPAIN 0x01
738 # ifndef SUBLANG_GEORGIAN_GEORGIA
739 # define SUBLANG_GEORGIAN_GEORGIA 0x01
741 # ifndef SUBLANG_GERMAN_LUXEMBOURG
742 # define SUBLANG_GERMAN_LUXEMBOURG 0x04
744 # ifndef SUBLANG_GERMAN_LIECHTENSTEIN
745 # define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
747 # ifndef SUBLANG_GREEK_GREECE
748 # define SUBLANG_GREEK_GREECE 0x01
750 # ifndef SUBLANG_GREENLANDIC_GREENLAND
751 # define SUBLANG_GREENLANDIC_GREENLAND 0x01
753 # ifndef SUBLANG_GUJARATI_INDIA
754 # define SUBLANG_GUJARATI_INDIA 0x01
756 # ifndef SUBLANG_HAUSA_NIGERIA_LATIN
757 # define SUBLANG_HAUSA_NIGERIA_LATIN 0x01
759 # ifndef SUBLANG_HEBREW_ISRAEL
760 # define SUBLANG_HEBREW_ISRAEL 0x01
762 # ifndef SUBLANG_HINDI_INDIA
763 # define SUBLANG_HINDI_INDIA 0x01
765 # ifndef SUBLANG_HUNGARIAN_HUNGARY
766 # define SUBLANG_HUNGARIAN_HUNGARY 0x01
768 # ifndef SUBLANG_ICELANDIC_ICELAND
769 # define SUBLANG_ICELANDIC_ICELAND 0x01
771 # ifndef SUBLANG_IGBO_NIGERIA
772 # define SUBLANG_IGBO_NIGERIA 0x01
774 # ifndef SUBLANG_INDONESIAN_INDONESIA
775 # define SUBLANG_INDONESIAN_INDONESIA 0x01
777 # ifndef SUBLANG_INUKTITUT_CANADA
778 # define SUBLANG_INUKTITUT_CANADA 0x01
780 # undef SUBLANG_INUKTITUT_CANADA_LATIN
781 # define SUBLANG_INUKTITUT_CANADA_LATIN 0x02
782 # undef SUBLANG_IRISH_IRELAND
783 # define SUBLANG_IRISH_IRELAND 0x02
784 # ifndef SUBLANG_JAPANESE_JAPAN
785 # define SUBLANG_JAPANESE_JAPAN 0x01
787 # ifndef SUBLANG_KANNADA_INDIA
788 # define SUBLANG_KANNADA_INDIA 0x01
790 # ifndef SUBLANG_KASHMIRI_INDIA
791 # define SUBLANG_KASHMIRI_INDIA 0x02
793 # ifndef SUBLANG_KAZAK_KAZAKHSTAN
794 # define SUBLANG_KAZAK_KAZAKHSTAN 0x01
796 # ifndef SUBLANG_KICHE_GUATEMALA
797 # define SUBLANG_KICHE_GUATEMALA 0x01
799 # ifndef SUBLANG_KINYARWANDA_RWANDA
800 # define SUBLANG_KINYARWANDA_RWANDA 0x01
802 # ifndef SUBLANG_KONKANI_INDIA
803 # define SUBLANG_KONKANI_INDIA 0x01
805 # ifndef SUBLANG_KYRGYZ_KYRGYZSTAN
806 # define SUBLANG_KYRGYZ_KYRGYZSTAN 0x01
808 # ifndef SUBLANG_LAO_LAOS
809 # define SUBLANG_LAO_LAOS 0x01
811 # ifndef SUBLANG_LATVIAN_LATVIA
812 # define SUBLANG_LATVIAN_LATVIA 0x01
814 # ifndef SUBLANG_LITHUANIAN_LITHUANIA
815 # define SUBLANG_LITHUANIAN_LITHUANIA 0x01
817 # undef SUBLANG_LOWER_SORBIAN_GERMANY
818 # define SUBLANG_LOWER_SORBIAN_GERMANY 0x02
819 # ifndef SUBLANG_LUXEMBOURGISH_LUXEMBOURG
820 # define SUBLANG_LUXEMBOURGISH_LUXEMBOURG 0x01
822 # ifndef SUBLANG_MACEDONIAN_MACEDONIA
823 # define SUBLANG_MACEDONIAN_MACEDONIA 0x01
825 # ifndef SUBLANG_MALAY_MALAYSIA
826 # define SUBLANG_MALAY_MALAYSIA 0x01
828 # ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
829 # define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
831 # ifndef SUBLANG_MALAYALAM_INDIA
832 # define SUBLANG_MALAYALAM_INDIA 0x01
834 # ifndef SUBLANG_MALTESE_MALTA
835 # define SUBLANG_MALTESE_MALTA 0x01
837 # ifndef SUBLANG_MAORI_NEW_ZEALAND
838 # define SUBLANG_MAORI_NEW_ZEALAND 0x01
840 # ifndef SUBLANG_MAPUDUNGUN_CHILE
841 # define SUBLANG_MAPUDUNGUN_CHILE 0x01
843 # ifndef SUBLANG_MARATHI_INDIA
844 # define SUBLANG_MARATHI_INDIA 0x01
846 # ifndef SUBLANG_MOHAWK_CANADA
847 # define SUBLANG_MOHAWK_CANADA 0x01
849 # ifndef SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA
850 # define SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA 0x01
852 # ifndef SUBLANG_MONGOLIAN_PRC
853 # define SUBLANG_MONGOLIAN_PRC 0x02
855 # ifndef SUBLANG_NEPALI_NEPAL
856 # define SUBLANG_NEPALI_NEPAL 0x01
858 # ifndef SUBLANG_NEPALI_INDIA
859 # define SUBLANG_NEPALI_INDIA 0x02
861 # ifndef SUBLANG_OCCITAN_FRANCE
862 # define SUBLANG_OCCITAN_FRANCE 0x01
864 # ifndef SUBLANG_ORIYA_INDIA
865 # define SUBLANG_ORIYA_INDIA 0x01
867 # ifndef SUBLANG_PASHTO_AFGHANISTAN
868 # define SUBLANG_PASHTO_AFGHANISTAN 0x01
870 # ifndef SUBLANG_POLISH_POLAND
871 # define SUBLANG_POLISH_POLAND 0x01
873 # ifndef SUBLANG_PUNJABI_INDIA
874 # define SUBLANG_PUNJABI_INDIA 0x01
876 # ifndef SUBLANG_PUNJABI_PAKISTAN
877 # define SUBLANG_PUNJABI_PAKISTAN 0x02
879 # ifndef SUBLANG_QUECHUA_BOLIVIA
880 # define SUBLANG_QUECHUA_BOLIVIA 0x01
882 # ifndef SUBLANG_QUECHUA_ECUADOR
883 # define SUBLANG_QUECHUA_ECUADOR 0x02
885 # ifndef SUBLANG_QUECHUA_PERU
886 # define SUBLANG_QUECHUA_PERU 0x03
888 # ifndef SUBLANG_ROMANIAN_ROMANIA
889 # define SUBLANG_ROMANIAN_ROMANIA 0x01
891 # ifndef SUBLANG_ROMANIAN_MOLDOVA
892 # define SUBLANG_ROMANIAN_MOLDOVA 0x02
894 # ifndef SUBLANG_ROMANSH_SWITZERLAND
895 # define SUBLANG_ROMANSH_SWITZERLAND 0x01
897 # ifndef SUBLANG_RUSSIAN_RUSSIA
898 # define SUBLANG_RUSSIAN_RUSSIA 0x01
900 # ifndef SUBLANG_RUSSIAN_MOLDAVIA
901 # define SUBLANG_RUSSIAN_MOLDAVIA 0x02
903 # ifndef SUBLANG_SAMI_NORTHERN_NORWAY
904 # define SUBLANG_SAMI_NORTHERN_NORWAY 0x01
906 # ifndef SUBLANG_SAMI_NORTHERN_SWEDEN
907 # define SUBLANG_SAMI_NORTHERN_SWEDEN 0x02
909 # ifndef SUBLANG_SAMI_NORTHERN_FINLAND
910 # define SUBLANG_SAMI_NORTHERN_FINLAND 0x03
912 # ifndef SUBLANG_SAMI_LULE_NORWAY
913 # define SUBLANG_SAMI_LULE_NORWAY 0x04
915 # ifndef SUBLANG_SAMI_LULE_SWEDEN
916 # define SUBLANG_SAMI_LULE_SWEDEN 0x05
918 # ifndef SUBLANG_SAMI_SOUTHERN_NORWAY
919 # define SUBLANG_SAMI_SOUTHERN_NORWAY 0x06
921 # ifndef SUBLANG_SAMI_SOUTHERN_SWEDEN
922 # define SUBLANG_SAMI_SOUTHERN_SWEDEN 0x07
924 # undef SUBLANG_SAMI_SKOLT_FINLAND
925 # define SUBLANG_SAMI_SKOLT_FINLAND 0x08
926 # undef SUBLANG_SAMI_INARI_FINLAND
927 # define SUBLANG_SAMI_INARI_FINLAND 0x09
928 # ifndef SUBLANG_SANSKRIT_INDIA
929 # define SUBLANG_SANSKRIT_INDIA 0x01
931 # ifndef SUBLANG_SERBIAN_LATIN
932 # define SUBLANG_SERBIAN_LATIN 0x02
934 # ifndef SUBLANG_SERBIAN_CYRILLIC
935 # define SUBLANG_SERBIAN_CYRILLIC 0x03
937 # ifndef SUBLANG_SINDHI_INDIA
938 # define SUBLANG_SINDHI_INDIA 0x01
940 # undef SUBLANG_SINDHI_PAKISTAN
941 # define SUBLANG_SINDHI_PAKISTAN 0x02
942 # ifndef SUBLANG_SINDHI_AFGHANISTAN
943 # define SUBLANG_SINDHI_AFGHANISTAN 0x02
945 # ifndef SUBLANG_SINHALESE_SRI_LANKA
946 # define SUBLANG_SINHALESE_SRI_LANKA 0x01
948 # ifndef SUBLANG_SLOVAK_SLOVAKIA
949 # define SUBLANG_SLOVAK_SLOVAKIA 0x01
951 # ifndef SUBLANG_SLOVENIAN_SLOVENIA
952 # define SUBLANG_SLOVENIAN_SLOVENIA 0x01
954 # ifndef SUBLANG_SOTHO_SOUTH_AFRICA
955 # define SUBLANG_SOTHO_SOUTH_AFRICA 0x01
957 # ifndef SUBLANG_SPANISH_GUATEMALA
958 # define SUBLANG_SPANISH_GUATEMALA 0x04
960 # ifndef SUBLANG_SPANISH_COSTA_RICA
961 # define SUBLANG_SPANISH_COSTA_RICA 0x05
963 # ifndef SUBLANG_SPANISH_PANAMA
964 # define SUBLANG_SPANISH_PANAMA 0x06
966 # ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
967 # define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
969 # ifndef SUBLANG_SPANISH_VENEZUELA
970 # define SUBLANG_SPANISH_VENEZUELA 0x08
972 # ifndef SUBLANG_SPANISH_COLOMBIA
973 # define SUBLANG_SPANISH_COLOMBIA 0x09
975 # ifndef SUBLANG_SPANISH_PERU
976 # define SUBLANG_SPANISH_PERU 0x0a
978 # ifndef SUBLANG_SPANISH_ARGENTINA
979 # define SUBLANG_SPANISH_ARGENTINA 0x0b
981 # ifndef SUBLANG_SPANISH_ECUADOR
982 # define SUBLANG_SPANISH_ECUADOR 0x0c
984 # ifndef SUBLANG_SPANISH_CHILE
985 # define SUBLANG_SPANISH_CHILE 0x0d
987 # ifndef SUBLANG_SPANISH_URUGUAY
988 # define SUBLANG_SPANISH_URUGUAY 0x0e
990 # ifndef SUBLANG_SPANISH_PARAGUAY
991 # define SUBLANG_SPANISH_PARAGUAY 0x0f
993 # ifndef SUBLANG_SPANISH_BOLIVIA
994 # define SUBLANG_SPANISH_BOLIVIA 0x10
996 # ifndef SUBLANG_SPANISH_EL_SALVADOR
997 # define SUBLANG_SPANISH_EL_SALVADOR 0x11
999 # ifndef SUBLANG_SPANISH_HONDURAS
1000 # define SUBLANG_SPANISH_HONDURAS 0x12
1002 # ifndef SUBLANG_SPANISH_NICARAGUA
1003 # define SUBLANG_SPANISH_NICARAGUA 0x13
1005 # ifndef SUBLANG_SPANISH_PUERTO_RICO
1006 # define SUBLANG_SPANISH_PUERTO_RICO 0x14
1008 # ifndef SUBLANG_SPANISH_US
1009 # define SUBLANG_SPANISH_US 0x15
1011 # ifndef SUBLANG_SWAHILI_KENYA
1012 # define SUBLANG_SWAHILI_KENYA 0x01
1014 # ifndef SUBLANG_SWEDISH_SWEDEN
1015 # define SUBLANG_SWEDISH_SWEDEN 0x01
1017 # ifndef SUBLANG_SWEDISH_FINLAND
1018 # define SUBLANG_SWEDISH_FINLAND 0x02
1020 # ifndef SUBLANG_SYRIAC_SYRIA
1021 # define SUBLANG_SYRIAC_SYRIA 0x01
1023 # ifndef SUBLANG_TAGALOG_PHILIPPINES
1024 # define SUBLANG_TAGALOG_PHILIPPINES 0x01
1026 # ifndef SUBLANG_TAJIK_TAJIKISTAN
1027 # define SUBLANG_TAJIK_TAJIKISTAN 0x01
1029 # ifndef SUBLANG_TAMAZIGHT_ARABIC
1030 # define SUBLANG_TAMAZIGHT_ARABIC 0x01
1032 # ifndef SUBLANG_TAMAZIGHT_ALGERIA_LATIN
1033 # define SUBLANG_TAMAZIGHT_ALGERIA_LATIN 0x02
1035 # ifndef SUBLANG_TAMIL_INDIA
1036 # define SUBLANG_TAMIL_INDIA 0x01
1038 # ifndef SUBLANG_TATAR_RUSSIA
1039 # define SUBLANG_TATAR_RUSSIA 0x01
1041 # ifndef SUBLANG_TELUGU_INDIA
1042 # define SUBLANG_TELUGU_INDIA 0x01
1044 # ifndef SUBLANG_THAI_THAILAND
1045 # define SUBLANG_THAI_THAILAND 0x01
1047 # ifndef SUBLANG_TIBETAN_PRC
1048 # define SUBLANG_TIBETAN_PRC 0x01
1050 # undef SUBLANG_TIBETAN_BHUTAN
1051 # define SUBLANG_TIBETAN_BHUTAN 0x02
1052 # ifndef SUBLANG_TIGRINYA_ETHIOPIA
1053 # define SUBLANG_TIGRINYA_ETHIOPIA 0x01
1055 # ifndef SUBLANG_TIGRINYA_ERITREA
1056 # define SUBLANG_TIGRINYA_ERITREA 0x02
1058 # ifndef SUBLANG_TSWANA_SOUTH_AFRICA
1059 # define SUBLANG_TSWANA_SOUTH_AFRICA 0x01
1061 # ifndef SUBLANG_TURKISH_TURKEY
1062 # define SUBLANG_TURKISH_TURKEY 0x01
1064 # ifndef SUBLANG_TURKMEN_TURKMENISTAN
1065 # define SUBLANG_TURKMEN_TURKMENISTAN 0x01
1067 # ifndef SUBLANG_UIGHUR_PRC
1068 # define SUBLANG_UIGHUR_PRC 0x01
1070 # ifndef SUBLANG_UKRAINIAN_UKRAINE
1071 # define SUBLANG_UKRAINIAN_UKRAINE 0x01
1073 # ifndef SUBLANG_UPPER_SORBIAN_GERMANY
1074 # define SUBLANG_UPPER_SORBIAN_GERMANY 0x01
1076 # ifndef SUBLANG_URDU_PAKISTAN
1077 # define SUBLANG_URDU_PAKISTAN 0x01
1079 # ifndef SUBLANG_URDU_INDIA
1080 # define SUBLANG_URDU_INDIA 0x02
1082 # ifndef SUBLANG_UZBEK_LATIN
1083 # define SUBLANG_UZBEK_LATIN 0x01
1085 # ifndef SUBLANG_UZBEK_CYRILLIC
1086 # define SUBLANG_UZBEK_CYRILLIC 0x02
1088 # ifndef SUBLANG_VIETNAMESE_VIETNAM
1089 # define SUBLANG_VIETNAMESE_VIETNAM 0x01
1091 # ifndef SUBLANG_WELSH_UNITED_KINGDOM
1092 # define SUBLANG_WELSH_UNITED_KINGDOM 0x01
1094 # ifndef SUBLANG_WOLOF_SENEGAL
1095 # define SUBLANG_WOLOF_SENEGAL 0x01
1097 # ifndef SUBLANG_XHOSA_SOUTH_AFRICA
1098 # define SUBLANG_XHOSA_SOUTH_AFRICA 0x01
1100 # ifndef SUBLANG_YAKUT_RUSSIA
1101 # define SUBLANG_YAKUT_RUSSIA 0x01
1103 # ifndef SUBLANG_YI_PRC
1104 # define SUBLANG_YI_PRC 0x01
1106 # ifndef SUBLANG_YORUBA_NIGERIA
1107 # define SUBLANG_YORUBA_NIGERIA 0x01
1109 # ifndef SUBLANG_ZULU_SOUTH_AFRICA
1110 # define SUBLANG_ZULU_SOUTH_AFRICA 0x01
1112 /* GetLocaleInfoA operations. */
1113 # ifndef LOCALE_SNAME
1114 # define LOCALE_SNAME 0x5c
1119 #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
1120 /* MacOS X 10.2 or newer */
1122 /* Canonicalize a MacOS X locale name to a Unix locale name.
1123 NAME is a sufficiently large buffer.
1124 On input, it contains the MacOS X locale name.
1125 On output, it contains the Unix locale name. */
1126 # if !defined IN_LIBINTL
1130 gl_locale_name_canonicalize (char *name)
1132 /* This conversion is based on a posting by
1133 Deborah GoldSmith <goldsmit@apple.com> on 2005-03-08,
1134 http://lists.apple.com/archives/carbon-dev/2005/Mar/msg00293.html */
1136 /* Convert legacy (NeXTstep inherited) English names to Unix (ISO 639 and
1137 ISO 3166) names. Prior to MacOS X 10.3, there is no API for doing this.
1138 Therefore we do it ourselves, using a table based on the results of the
1139 MacOS X 10.3.8 function
1140 CFLocaleCreateCanonicalLocaleIdentifierFromString(). */
1141 typedef struct { const char legacy[21+1]; const char unixy[5+1]; }
1143 static const legacy_entry legacy_table[] = {
1144 { "Afrikaans", "af" },
1145 { "Albanian", "sq" },
1146 { "Amharic", "am" },
1148 { "Armenian", "hy" },
1149 { "Assamese", "as" },
1151 { "Azerbaijani", "az" },
1153 { "Belarusian", "be" },
1154 { "Belorussian", "be" },
1155 { "Bengali", "bn" },
1156 { "Brazilian Portugese", "pt_BR" },
1157 { "Brazilian Portuguese", "pt_BR" },
1159 { "Bulgarian", "bg" },
1160 { "Burmese", "my" },
1161 { "Byelorussian", "be" },
1162 { "Catalan", "ca" },
1164 { "Chichewa", "ny" },
1165 { "Chinese", "zh" },
1166 { "Chinese, Simplified", "zh_CN" },
1167 { "Chinese, Traditional", "zh_TW" },
1168 { "Chinese, Tradtional", "zh_TW" },
1169 { "Croatian", "hr" },
1173 { "Dzongkha", "dz" },
1174 { "English", "en" },
1175 { "Esperanto", "eo" },
1176 { "Estonian", "et" },
1177 { "Faroese", "fo" },
1179 { "Finnish", "fi" },
1180 { "Flemish", "nl_BE" },
1182 { "Galician", "gl" },
1183 { "Gallegan", "gl" },
1184 { "Georgian", "ka" },
1187 { "Greenlandic", "kl" },
1188 { "Guarani", "gn" },
1189 { "Gujarati", "gu" },
1190 { "Hawaiian", "haw" }, /* Yes, "haw", not "cpe". */
1193 { "Hungarian", "hu" },
1194 { "Icelandic", "is" },
1195 { "Indonesian", "id" },
1196 { "Inuktitut", "iu" },
1198 { "Italian", "it" },
1199 { "Japanese", "ja" },
1200 { "Javanese", "jv" },
1201 { "Kalaallisut", "kl" },
1202 { "Kannada", "kn" },
1203 { "Kashmiri", "ks" },
1206 { "Kinyarwanda", "rw" },
1207 { "Kirghiz", "ky" },
1209 { "Kurdish", "ku" },
1211 { "Latvian", "lv" },
1212 { "Lithuanian", "lt" },
1213 { "Macedonian", "mk" },
1214 { "Malagasy", "mg" },
1216 { "Malayalam", "ml" },
1217 { "Maltese", "mt" },
1219 { "Marathi", "mr" },
1220 { "Moldavian", "mo" },
1221 { "Mongolian", "mn" },
1223 { "Norwegian", "nb" }, /* Yes, "nb", not the obsolete "no". */
1225 { "Nynorsk", "nn" },
1228 { "Panjabi", "pa" },
1230 { "Persian", "fa" },
1232 { "Portuguese", "pt" },
1233 { "Portuguese, Brazilian", "pt_BR" },
1234 { "Punjabi", "pa" },
1236 { "Quechua", "qu" },
1237 { "Romanian", "ro" },
1240 { "Russian", "ru" },
1241 { "Sami", "se_NO" }, /* Not just "se". */
1242 { "Sanskrit", "sa" },
1243 { "Scottish", "gd" },
1244 { "Serbian", "sr" },
1245 { "Simplified Chinese", "zh_CN" },
1247 { "Sinhalese", "si" },
1249 { "Slovenian", "sl" },
1251 { "Spanish", "es" },
1252 { "Sundanese", "su" },
1253 { "Swahili", "sw" },
1254 { "Swedish", "sv" },
1255 { "Tagalog", "tl" },
1262 { "Tibetan", "bo" },
1263 { "Tigrinya", "ti" },
1265 { "Traditional Chinese", "zh_TW" },
1266 { "Turkish", "tr" },
1267 { "Turkmen", "tk" },
1269 { "Ukrainian", "uk" },
1272 { "Vietnamese", "vi" },
1277 /* Convert new-style locale names with language tags (ISO 639 and ISO 15924)
1278 to Unix (ISO 639 and ISO 3166) names. */
1279 typedef struct { const char langtag[7+1]; const char unixy[12+1]; }
1281 static const langtag_entry langtag_table[] = {
1282 /* MacOS X has "az-Arab", "az-Cyrl", "az-Latn".
1283 The default script for az on Unix is Latin. */
1284 { "az-Latn", "az" },
1285 /* MacOS X has "ga-dots". Does not yet exist on Unix. */
1286 { "ga-dots", "ga" },
1287 /* MacOS X has "kk-Cyrl". Does not yet exist on Unix. */
1288 /* MacOS X has "mn-Cyrl", "mn-Mong".
1289 The default script for mn on Unix is Cyrillic. */
1290 { "mn-Cyrl", "mn" },
1291 /* MacOS X has "ms-Arab", "ms-Latn".
1292 The default script for ms on Unix is Latin. */
1293 { "ms-Latn", "ms" },
1294 /* MacOS X has "tg-Cyrl".
1295 The default script for tg on Unix is Cyrillic. */
1296 { "tg-Cyrl", "tg" },
1297 /* MacOS X has "tk-Cyrl". Does not yet exist on Unix. */
1298 /* MacOS X has "tt-Cyrl".
1299 The default script for tt on Unix is Cyrillic. */
1300 { "tt-Cyrl", "tt" },
1301 /* MacOS X has "zh-Hans", "zh-Hant".
1302 Country codes are used to distinguish these on Unix. */
1303 { "zh-Hans", "zh_CN" },
1304 { "zh-Hant", "zh_TW" }
1307 /* Convert script names (ISO 15924) to Unix conventions.
1308 See http://www.unicode.org/iso15924/iso15924-codes.html */
1309 typedef struct { const char script[4+1]; const char unixy[9+1]; }
1311 static const script_entry script_table[] = {
1312 { "Arab", "arabic" },
1313 { "Cyrl", "cyrillic" },
1314 { "Mong", "mongolian" }
1317 /* Step 1: Convert using legacy_table. */
1318 if (name[0] >= 'A' && name[0] <= 'Z')
1320 unsigned int i1, i2;
1322 i2 = sizeof (legacy_table) / sizeof (legacy_entry);
1325 /* At this point we know that if name occurs in legacy_table,
1326 its index must be >= i1 and < i2. */
1327 unsigned int i = (i1 + i2) >> 1;
1328 const legacy_entry *p = &legacy_table[i];
1329 if (strcmp (name, p->legacy) < 0)
1334 if (strcmp (name, legacy_table[i1].legacy) == 0)
1336 strcpy (name, legacy_table[i1].unixy);
1341 /* Step 2: Convert using langtag_table and script_table. */
1342 if (strlen (name) == 7 && name[2] == '-')
1344 unsigned int i1, i2;
1346 i2 = sizeof (langtag_table) / sizeof (langtag_entry);
1349 /* At this point we know that if name occurs in langtag_table,
1350 its index must be >= i1 and < i2. */
1351 unsigned int i = (i1 + i2) >> 1;
1352 const langtag_entry *p = &langtag_table[i];
1353 if (strcmp (name, p->langtag) < 0)
1358 if (strcmp (name, langtag_table[i1].langtag) == 0)
1360 strcpy (name, langtag_table[i1].unixy);
1365 i2 = sizeof (script_table) / sizeof (script_entry);
1368 /* At this point we know that if (name + 3) occurs in script_table,
1369 its index must be >= i1 and < i2. */
1370 unsigned int i = (i1 + i2) >> 1;
1371 const script_entry *p = &script_table[i];
1372 if (strcmp (name + 3, p->script) < 0)
1377 if (strcmp (name + 3, script_table[i1].script) == 0)
1380 strcpy (name + 3, script_table[i1].unixy);
1385 /* Step 3: Convert new-style dash to Unix underscore. */
1388 for (p = name; *p != '\0'; p++)
1397 #if defined WIN32_NATIVE || defined __CYGWIN__ /* WIN32 or Cygwin */
1399 /* Canonicalize a Win32 native locale name to a Unix locale name.
1400 NAME is a sufficiently large buffer.
1401 On input, it contains the Win32 locale name.
1402 On output, it contains the Unix locale name. */
1403 # if !defined IN_LIBINTL
1407 gl_locale_name_canonicalize (char *name)
1409 /* FIXME: This is probably incomplete: it does not handle "zh-Hans" and
1413 for (p = name; *p != '\0'; p++)
1418 for (; *p != '\0'; p++)
1420 if (*p >= 'a' && *p <= 'z')
1432 # if !defined IN_LIBINTL
1436 gl_locale_name_from_win32_LANGID (LANGID langid)
1438 /* Activate the new code only when the GETTEXT_MUI environment variable is
1439 set, for the time being, since the new code is not well tested. */
1440 if (getenv ("GETTEXT_MUI") != NULL)
1442 static char namebuf[256];
1444 /* Query the system's notion of locale name.
1445 On Windows95/98/ME, GetLocaleInfoA returns some incorrect results.
1446 But we don't need to support systems that are so old. */
1447 if (GetLocaleInfoA (MAKELCID (langid, SORT_DEFAULT), LOCALE_SNAME,
1448 namebuf, sizeof (namebuf) - 1))
1450 /* Convert it to a Unix locale name. */
1451 gl_locale_name_canonicalize (namebuf);
1455 /* Internet Explorer has an LCID to RFC3066 name mapping stored in
1456 HKEY_CLASSES_ROOT\Mime\Database\Rfc1766. But we better don't use that
1457 since IE's i18n subsystem is known to be inconsistent with the Win32 base
1458 (e.g. they have different character conversion facilities that produce
1459 different results). */
1460 /* Use our own table. */
1464 /* Split into language and territory part. */
1465 primary = PRIMARYLANGID (langid);
1466 sub = SUBLANGID (langid);
1468 /* Dispatch on language.
1469 See also http://www.unicode.org/unicode/onlinedat/languages.html .
1470 For details about languages, see http://www.ethnologue.com/ . */
1473 case LANG_AFRIKAANS:
1476 case SUBLANG_AFRIKAANS_SOUTH_AFRICA: return "af_ZA";
1482 case SUBLANG_ALBANIAN_ALBANIA: return "sq_AL";
1488 case SUBLANG_ALSATIAN_FRANCE: return "gsw_FR";
1494 case SUBLANG_AMHARIC_ETHIOPIA: return "am_ET";
1500 case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA";
1501 case SUBLANG_ARABIC_IRAQ: return "ar_IQ";
1502 case SUBLANG_ARABIC_EGYPT: return "ar_EG";
1503 case SUBLANG_ARABIC_LIBYA: return "ar_LY";
1504 case SUBLANG_ARABIC_ALGERIA: return "ar_DZ";
1505 case SUBLANG_ARABIC_MOROCCO: return "ar_MA";
1506 case SUBLANG_ARABIC_TUNISIA: return "ar_TN";
1507 case SUBLANG_ARABIC_OMAN: return "ar_OM";
1508 case SUBLANG_ARABIC_YEMEN: return "ar_YE";
1509 case SUBLANG_ARABIC_SYRIA: return "ar_SY";
1510 case SUBLANG_ARABIC_JORDAN: return "ar_JO";
1511 case SUBLANG_ARABIC_LEBANON: return "ar_LB";
1512 case SUBLANG_ARABIC_KUWAIT: return "ar_KW";
1513 case SUBLANG_ARABIC_UAE: return "ar_AE";
1514 case SUBLANG_ARABIC_BAHRAIN: return "ar_BH";
1515 case SUBLANG_ARABIC_QATAR: return "ar_QA";
1521 case SUBLANG_ARMENIAN_ARMENIA: return "hy_AM";
1527 case SUBLANG_ASSAMESE_INDIA: return "as_IN";
1533 /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */
1534 case 0x1e: return "az@latin";
1535 case SUBLANG_AZERI_LATIN: return "az_AZ@latin";
1536 case 0x1d: return "az@cyrillic";
1537 case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic";
1543 case SUBLANG_BASHKIR_RUSSIA: return "ba_RU";
1549 case SUBLANG_BASQUE_BASQUE: return "eu_ES";
1551 return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */
1552 case LANG_BELARUSIAN:
1555 case SUBLANG_BELARUSIAN_BELARUS: return "be_BY";
1561 case SUBLANG_BENGALI_INDIA: return "bn_IN";
1562 case SUBLANG_BENGALI_BANGLADESH: return "bn_BD";
1568 case SUBLANG_BRETON_FRANCE: return "br_FR";
1571 case LANG_BULGARIAN:
1574 case SUBLANG_BULGARIAN_BULGARIA: return "bg_BG";
1580 case SUBLANG_DEFAULT: return "my_MM";
1583 case LANG_CAMBODIAN:
1586 case SUBLANG_CAMBODIAN_CAMBODIA: return "km_KH";
1592 case SUBLANG_CATALAN_SPAIN: return "ca_ES";
1598 case SUBLANG_DEFAULT: return "chr_US";
1604 case SUBLANG_CHINESE_TRADITIONAL: case 0x1f: return "zh_TW";
1605 case SUBLANG_CHINESE_SIMPLIFIED: case 0x00: return "zh_CN";
1606 case SUBLANG_CHINESE_HONGKONG: return "zh_HK"; /* traditional */
1607 case SUBLANG_CHINESE_SINGAPORE: return "zh_SG"; /* simplified */
1608 case SUBLANG_CHINESE_MACAU: return "zh_MO"; /* traditional */
1614 case SUBLANG_CORSICAN_FRANCE: return "co_FR";
1617 case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN == LANG_BOSNIAN
1618 * What used to be called Serbo-Croatian
1619 * should really now be two separate
1620 * languages because of political reasons.
1621 * (Says tml, who knows nothing about Serbian
1623 * (I can feel those flames coming already.)
1628 case 0x00: return "hr";
1629 case SUBLANG_CROATIAN_CROATIA: return "hr_HR";
1630 case SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN: return "hr_BA";
1632 case 0x1f: return "sr";
1633 case 0x1c: return "sr"; /* latin */
1634 case SUBLANG_SERBIAN_LATIN: return "sr_CS"; /* latin */
1635 case 0x09: return "sr_RS"; /* latin */
1636 case 0x0b: return "sr_ME"; /* latin */
1637 case 0x06: return "sr_BA"; /* latin */
1638 case 0x1b: return "sr@cyrillic";
1639 case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic";
1640 case 0x0a: return "sr_RS@cyrillic";
1641 case 0x0c: return "sr_ME@cyrillic";
1642 case 0x07: return "sr_BA@cyrillic";
1644 case 0x1e: return "bs";
1645 case 0x1a: return "bs"; /* latin */
1646 case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN: return "bs_BA"; /* latin */
1647 case 0x19: return "bs@cyrillic";
1648 case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC: return "bs_BA@cyrillic";
1654 case SUBLANG_CZECH_CZECH_REPUBLIC: return "cs_CZ";
1660 case SUBLANG_DANISH_DENMARK: return "da_DK";
1664 /* FIXME: Adjust this when such locales appear on Unix. */
1667 case SUBLANG_DARI_AFGHANISTAN: return "prs_AF";
1673 case SUBLANG_DIVEHI_MALDIVES: return "dv_MV";
1679 case SUBLANG_DUTCH: return "nl_NL";
1680 case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE";
1681 case SUBLANG_DUTCH_SURINAM: return "nl_SR";
1687 case SUBLANG_DEFAULT: return "bin_NG";
1693 /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought
1694 * English was the language spoken in England.
1697 case SUBLANG_ENGLISH_US: return "en_US";
1698 case SUBLANG_ENGLISH_UK: return "en_GB";
1699 case SUBLANG_ENGLISH_AUS: return "en_AU";
1700 case SUBLANG_ENGLISH_CAN: return "en_CA";
1701 case SUBLANG_ENGLISH_NZ: return "en_NZ";
1702 case SUBLANG_ENGLISH_EIRE: return "en_IE";
1703 case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA";
1704 case SUBLANG_ENGLISH_JAMAICA: return "en_JM";
1705 case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */
1706 case SUBLANG_ENGLISH_BELIZE: return "en_BZ";
1707 case SUBLANG_ENGLISH_TRINIDAD: return "en_TT";
1708 case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW";
1709 case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH";
1710 case SUBLANG_ENGLISH_INDONESIA: return "en_ID";
1711 case SUBLANG_ENGLISH_HONGKONG: return "en_HK";
1712 case SUBLANG_ENGLISH_INDIA: return "en_IN";
1713 case SUBLANG_ENGLISH_MALAYSIA: return "en_MY";
1714 case SUBLANG_ENGLISH_SINGAPORE: return "en_SG";
1720 case SUBLANG_ESTONIAN_ESTONIA: return "et_EE";
1726 case SUBLANG_FAEROESE_FAROE_ISLANDS: return "fo_FO";
1732 case SUBLANG_FARSI_IRAN: return "fa_IR";
1738 case SUBLANG_FINNISH_FINLAND: return "fi_FI";
1744 case SUBLANG_FRENCH: return "fr_FR";
1745 case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE";
1746 case SUBLANG_FRENCH_CANADIAN: return "fr_CA";
1747 case SUBLANG_FRENCH_SWISS: return "fr_CH";
1748 case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU";
1749 case SUBLANG_FRENCH_MONACO: return "fr_MC";
1750 case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */
1751 case SUBLANG_FRENCH_REUNION: return "fr_RE";
1752 case SUBLANG_FRENCH_CONGO: return "fr_CG";
1753 case SUBLANG_FRENCH_SENEGAL: return "fr_SN";
1754 case SUBLANG_FRENCH_CAMEROON: return "fr_CM";
1755 case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI";
1756 case SUBLANG_FRENCH_MALI: return "fr_ML";
1757 case SUBLANG_FRENCH_MOROCCO: return "fr_MA";
1758 case SUBLANG_FRENCH_HAITI: return "fr_HT";
1764 case SUBLANG_FRISIAN_NETHERLANDS: return "fy_NL";
1768 /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin. */
1771 case SUBLANG_DEFAULT: return "ff_NG";
1777 case 0x01: /* SCOTTISH */
1778 /* old, superseded by LANG_SCOTTISH_GAELIC */
1780 case SUBLANG_IRISH_IRELAND: return "ga_IE";
1786 case SUBLANG_GALICIAN_SPAIN: return "gl_ES";
1792 case SUBLANG_GEORGIAN_GEORGIA: return "ka_GE";
1798 case SUBLANG_GERMAN: return "de_DE";
1799 case SUBLANG_GERMAN_SWISS: return "de_CH";
1800 case SUBLANG_GERMAN_AUSTRIAN: return "de_AT";
1801 case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU";
1802 case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI";
1808 case SUBLANG_GREEK_GREECE: return "el_GR";
1811 case LANG_GREENLANDIC:
1814 case SUBLANG_GREENLANDIC_GREENLAND: return "kl_GL";
1820 case SUBLANG_DEFAULT: return "gn_PY";
1826 case SUBLANG_GUJARATI_INDIA: return "gu_IN";
1832 case 0x1f: return "ha";
1833 case SUBLANG_HAUSA_NIGERIA_LATIN: return "ha_NG";
1837 /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers)
1838 or Hawaii Creole English ("cpe_US", 600000 speakers)? */
1841 case SUBLANG_DEFAULT: return "cpe_US";
1847 case SUBLANG_HEBREW_ISRAEL: return "he_IL";
1853 case SUBLANG_HINDI_INDIA: return "hi_IN";
1856 case LANG_HUNGARIAN:
1859 case SUBLANG_HUNGARIAN_HUNGARY: return "hu_HU";
1865 case SUBLANG_DEFAULT: return "nic_NG";
1868 case LANG_ICELANDIC:
1871 case SUBLANG_ICELANDIC_ICELAND: return "is_IS";
1877 case SUBLANG_IGBO_NIGERIA: return "ig_NG";
1880 case LANG_INDONESIAN:
1883 case SUBLANG_INDONESIAN_INDONESIA: return "id_ID";
1886 case LANG_INUKTITUT:
1889 case 0x1e: return "iu"; /* syllabic */
1890 case SUBLANG_INUKTITUT_CANADA: return "iu_CA"; /* syllabic */
1891 case 0x1f: return "iu@latin";
1892 case SUBLANG_INUKTITUT_CANADA_LATIN: return "iu_CA@latin";
1898 case SUBLANG_ITALIAN: return "it_IT";
1899 case SUBLANG_ITALIAN_SWISS: return "it_CH";
1905 case SUBLANG_JAPANESE_JAPAN: return "ja_JP";
1911 case SUBLANG_KANNADA_INDIA: return "kn_IN";
1917 case SUBLANG_DEFAULT: return "kr_NG";
1923 case SUBLANG_DEFAULT: return "ks_PK";
1924 case SUBLANG_KASHMIRI_INDIA: return "ks_IN";
1930 case SUBLANG_KAZAK_KAZAKHSTAN: return "kk_KZ";
1934 /* FIXME: Adjust this when such locales appear on Unix. */
1937 case SUBLANG_KICHE_GUATEMALA: return "qut_GT";
1940 case LANG_KINYARWANDA:
1943 case SUBLANG_KINYARWANDA_RWANDA: return "rw_RW";
1947 /* FIXME: Adjust this when such locales appear on Unix. */
1950 case SUBLANG_KONKANI_INDIA: return "kok_IN";
1956 case SUBLANG_DEFAULT: return "ko_KR";
1962 case SUBLANG_KYRGYZ_KYRGYZSTAN: return "ky_KG";
1968 case SUBLANG_LAO_LAOS: return "lo_LA";
1974 case SUBLANG_DEFAULT: return "la_VA";
1980 case SUBLANG_LATVIAN_LATVIA: return "lv_LV";
1983 case LANG_LITHUANIAN:
1986 case SUBLANG_LITHUANIAN_LITHUANIA: return "lt_LT";
1989 case LANG_LUXEMBOURGISH:
1992 case SUBLANG_LUXEMBOURGISH_LUXEMBOURG: return "lb_LU";
1995 case LANG_MACEDONIAN:
1998 case SUBLANG_MACEDONIAN_MACEDONIA: return "mk_MK";
2004 case SUBLANG_MALAY_MALAYSIA: return "ms_MY";
2005 case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN";
2008 case LANG_MALAYALAM:
2011 case SUBLANG_MALAYALAM_INDIA: return "ml_IN";
2017 case SUBLANG_MALTESE_MALTA: return "mt_MT";
2021 /* FIXME: Adjust this when such locales appear on Unix. */
2024 case SUBLANG_DEFAULT: return "mni_IN";
2030 case SUBLANG_MAORI_NEW_ZEALAND: return "mi_NZ";
2033 case LANG_MAPUDUNGUN:
2036 case SUBLANG_MAPUDUNGUN_CHILE: return "arn_CL";
2042 case SUBLANG_MARATHI_INDIA: return "mr_IN";
2048 case SUBLANG_MOHAWK_CANADA: return "moh_CA";
2051 case LANG_MONGOLIAN:
2054 case SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA: case 0x1e: return "mn_MN";
2055 case SUBLANG_MONGOLIAN_PRC: case 0x1f: return "mn_CN";
2057 return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN". */
2061 case SUBLANG_NEPALI_NEPAL: return "ne_NP";
2062 case SUBLANG_NEPALI_INDIA: return "ne_IN";
2065 case LANG_NORWEGIAN:
2068 case 0x1f: return "nb";
2069 case SUBLANG_NORWEGIAN_BOKMAL: return "nb_NO";
2070 case 0x1e: return "nn";
2071 case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO";
2077 case SUBLANG_OCCITAN_FRANCE: return "oc_FR";
2083 case SUBLANG_ORIYA_INDIA: return "or_IN";
2089 case SUBLANG_DEFAULT: return "om_ET";
2092 case LANG_PAPIAMENTU:
2095 case SUBLANG_DEFAULT: return "pap_AN";
2101 case SUBLANG_PASHTO_AFGHANISTAN: return "ps_AF";
2103 return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF". */
2107 case SUBLANG_POLISH_POLAND: return "pl_PL";
2110 case LANG_PORTUGUESE:
2113 /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT.
2114 Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */
2115 case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR";
2116 case SUBLANG_PORTUGUESE: return "pt_PT";
2122 case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */
2123 case SUBLANG_PUNJABI_PAKISTAN: return "pa_PK"; /* Arabic script */
2127 /* Note: Microsoft uses the non-ISO language code "quz". */
2130 case SUBLANG_QUECHUA_BOLIVIA: return "qu_BO";
2131 case SUBLANG_QUECHUA_ECUADOR: return "qu_EC";
2132 case SUBLANG_QUECHUA_PERU: return "qu_PE";
2138 case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO";
2139 case SUBLANG_ROMANIAN_MOLDOVA: return "ro_MD";
2145 case SUBLANG_ROMANSH_SWITZERLAND: return "rm_CH";
2151 case SUBLANG_RUSSIAN_RUSSIA: return "ru_RU";
2152 case SUBLANG_RUSSIAN_MOLDAVIA: return "ru_MD";
2154 return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */
2159 case 0x00: return "se";
2160 case SUBLANG_SAMI_NORTHERN_NORWAY: return "se_NO";
2161 case SUBLANG_SAMI_NORTHERN_SWEDEN: return "se_SE";
2162 case SUBLANG_SAMI_NORTHERN_FINLAND: return "se_FI";
2164 case 0x1f: return "smj";
2165 case SUBLANG_SAMI_LULE_NORWAY: return "smj_NO";
2166 case SUBLANG_SAMI_LULE_SWEDEN: return "smj_SE";
2168 case 0x1e: return "sma";
2169 case SUBLANG_SAMI_SOUTHERN_NORWAY: return "sma_NO";
2170 case SUBLANG_SAMI_SOUTHERN_SWEDEN: return "sma_SE";
2172 case 0x1d: return "sms";
2173 case SUBLANG_SAMI_SKOLT_FINLAND: return "sms_FI";
2175 case 0x1c: return "smn";
2176 case SUBLANG_SAMI_INARI_FINLAND: return "smn_FI";
2178 return "se"; /* or "smi"? */
2182 case SUBLANG_SANSKRIT_INDIA: return "sa_IN";
2185 case LANG_SCOTTISH_GAELIC:
2188 case SUBLANG_DEFAULT: return "gd_GB";
2194 case SUBLANG_SINDHI_INDIA: return "sd_IN";
2195 case SUBLANG_SINDHI_PAKISTAN: return "sd_PK";
2196 /*case SUBLANG_SINDHI_AFGHANISTAN: return "sd_AF";*/
2199 case LANG_SINHALESE:
2202 case SUBLANG_SINHALESE_SRI_LANKA: return "si_LK";
2208 case SUBLANG_SLOVAK_SLOVAKIA: return "sk_SK";
2211 case LANG_SLOVENIAN:
2214 case SUBLANG_SLOVENIAN_SLOVENIA: return "sl_SI";
2220 case SUBLANG_DEFAULT: return "so_SO";
2224 /* FIXME: Adjust this when such locales appear on Unix. */
2228 case 0x00: return "hsb";
2229 case SUBLANG_UPPER_SORBIAN_GERMANY: return "hsb_DE";
2231 case 0x1f: return "dsb";
2232 case SUBLANG_LOWER_SORBIAN_GERMANY: return "dsb_DE";
2236 /* <http://www.microsoft.com/globaldev/reference/lcid-all.mspx> calls
2237 it "Sepedi"; according to
2238 <http://www.ethnologue.com/show_language.asp?code=nso>
2239 <http://www.ethnologue.com/show_language.asp?code=sot>
2240 it's the same as Northern Sotho. */
2243 case SUBLANG_SOTHO_SOUTH_AFRICA: return "nso_ZA";
2249 case SUBLANG_SPANISH: return "es_ES";
2250 case SUBLANG_SPANISH_MEXICAN: return "es_MX";
2251 case SUBLANG_SPANISH_MODERN:
2252 return "es_ES@modern"; /* not seen on Unix */
2253 case SUBLANG_SPANISH_GUATEMALA: return "es_GT";
2254 case SUBLANG_SPANISH_COSTA_RICA: return "es_CR";
2255 case SUBLANG_SPANISH_PANAMA: return "es_PA";
2256 case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO";
2257 case SUBLANG_SPANISH_VENEZUELA: return "es_VE";
2258 case SUBLANG_SPANISH_COLOMBIA: return "es_CO";
2259 case SUBLANG_SPANISH_PERU: return "es_PE";
2260 case SUBLANG_SPANISH_ARGENTINA: return "es_AR";
2261 case SUBLANG_SPANISH_ECUADOR: return "es_EC";
2262 case SUBLANG_SPANISH_CHILE: return "es_CL";
2263 case SUBLANG_SPANISH_URUGUAY: return "es_UY";
2264 case SUBLANG_SPANISH_PARAGUAY: return "es_PY";
2265 case SUBLANG_SPANISH_BOLIVIA: return "es_BO";
2266 case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV";
2267 case SUBLANG_SPANISH_HONDURAS: return "es_HN";
2268 case SUBLANG_SPANISH_NICARAGUA: return "es_NI";
2269 case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR";
2270 case SUBLANG_SPANISH_US: return "es_US";
2276 case SUBLANG_DEFAULT: return "bnt_TZ"; /* or "st_LS" or "nso_ZA"? */
2282 case SUBLANG_SWAHILI_KENYA: return "sw_KE";
2288 case SUBLANG_SWEDISH_SWEDEN: return "sv_SE";
2289 case SUBLANG_SWEDISH_FINLAND: return "sv_FI";
2295 case SUBLANG_SYRIAC_SYRIA: return "syr_SY"; /* An extinct language. */
2301 case SUBLANG_TAGALOG_PHILIPPINES: return "tl_PH"; /* or "fil_PH"? */
2303 return "tl"; /* or "fil"? */
2307 case 0x1f: return "tg";
2308 case SUBLANG_TAJIK_TAJIKISTAN: return "tg_TJ";
2311 case LANG_TAMAZIGHT:
2312 /* Note: Microsoft uses the non-ISO language code "tmz". */
2315 /* FIXME: Adjust this when Tamazight locales appear on Unix. */
2316 case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic";
2317 case 0x1f: return "ber@latin";
2318 case SUBLANG_TAMAZIGHT_ALGERIA_LATIN: return "ber_DZ@latin";
2324 case SUBLANG_TAMIL_INDIA: return "ta_IN";
2326 return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */
2330 case SUBLANG_TATAR_RUSSIA: return "tt_RU";
2336 case SUBLANG_TELUGU_INDIA: return "te_IN";
2342 case SUBLANG_THAI_THAILAND: return "th_TH";
2348 case SUBLANG_TIBETAN_PRC:
2349 /* Most Tibetans would not like "bo_CN". But Tibet does not yet
2350 have a country code of its own. */
2352 case SUBLANG_TIBETAN_BHUTAN: return "bo_BT";
2358 case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET";
2359 case SUBLANG_TIGRINYA_ERITREA: return "ti_ER";
2365 case SUBLANG_DEFAULT: return "ts_ZA";
2369 /* Spoken in South Africa, Botswana. */
2372 case SUBLANG_TSWANA_SOUTH_AFRICA: return "tn_ZA";
2378 case SUBLANG_TURKISH_TURKEY: return "tr_TR";
2384 case SUBLANG_TURKMEN_TURKMENISTAN: return "tk_TM";
2390 case SUBLANG_UIGHUR_PRC: return "ug_CN";
2393 case LANG_UKRAINIAN:
2396 case SUBLANG_UKRAINIAN_UKRAINE: return "uk_UA";
2402 case SUBLANG_URDU_PAKISTAN: return "ur_PK";
2403 case SUBLANG_URDU_INDIA: return "ur_IN";
2409 case 0x1f: return "uz";
2410 case SUBLANG_UZBEK_LATIN: return "uz_UZ";
2411 case 0x1e: return "uz@cyrillic";
2412 case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic";
2418 case SUBLANG_DEFAULT: return "ve_ZA";
2421 case LANG_VIETNAMESE:
2424 case SUBLANG_VIETNAMESE_VIETNAM: return "vi_VN";
2430 case SUBLANG_WELSH_UNITED_KINGDOM: return "cy_GB";
2436 case SUBLANG_WOLOF_SENEGAL: return "wo_SN";
2442 case SUBLANG_XHOSA_SOUTH_AFRICA: return "xh_ZA";
2448 case SUBLANG_YAKUT_RUSSIA: return "sah_RU";
2454 case SUBLANG_YI_PRC: return "ii_CN";
2460 case SUBLANG_DEFAULT: return "yi_IL";
2466 case SUBLANG_YORUBA_NIGERIA: return "yo_NG";
2472 case SUBLANG_ZULU_SOUTH_AFRICA: return "zu_ZA";
2475 default: return "C";
2480 # if !defined IN_LIBINTL
2484 gl_locale_name_from_win32_LCID (LCID lcid)
2488 /* Strip off the sorting rules, keep only the language part. */
2489 langid = LANGIDFROMLCID (lcid);
2491 return gl_locale_name_from_win32_LANGID (langid);
2497 /* XPG3 defines the result of 'setlocale (category, NULL)' as:
2498 "Directs 'setlocale()' to query 'category' and return the current
2499 setting of 'local'."
2500 However it does not specify the exact format. Neither do SUSV2 and
2501 ISO C 99. So we can use this feature only on selected systems (e.g.
2502 those using GNU C Library). */
2503 #if defined _LIBC || (defined __GLIBC__ && __GLIBC__ >= 2)
2504 # define HAVE_LOCALE_NULL
2507 /* Determine the current locale's name, and canonicalize it into XPG syntax
2508 language[_territory][.codeset][@modifier]
2509 The codeset part in the result is not reliable; the locale_charset()
2510 should be used for codeset information instead.
2511 The result must not be freed; it is statically allocated. */
2514 gl_locale_name_posix (int category, const char *categoryname)
2516 /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
2517 On some systems this can be done by the 'setlocale' function itself. */
2518 #if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
2519 return setlocale (category, NULL);
2521 /* On other systems we ignore what setlocale reports and instead look at the
2522 environment variables directly. This is necessary
2523 1. on systems which have a facility for customizing the default locale
2524 (MacOS X, native Windows, Cygwin) and where the system's setlocale()
2525 function ignores this default locale (MacOS X, Cygwin), in two cases:
2526 a. when the user missed to use the setlocale() override from libintl
2527 (for example by not including <libintl.h>),
2528 b. when setlocale supports only the "C" locale, such as on Cygwin
2529 1.5.x. In this case even the override from libintl cannot help.
2530 2. on all systems where setlocale supports only the "C" locale. */
2531 /* Strictly speaking, it is a POSIX violation to look at the environment
2532 variables regardless whether setlocale has been called or not. POSIX
2534 "For C-language programs, the POSIX locale shall be the
2535 default locale when the setlocale() function is not called."
2536 But we assume that all programs that use internationalized APIs call
2537 setlocale (LC_ALL, ""). */
2538 return gl_locale_name_environ (category, categoryname);
2543 gl_locale_name_environ (int category, const char *categoryname)
2547 /* Setting of LC_ALL overrides all other. */
2548 retval = getenv ("LC_ALL");
2549 if (retval != NULL && retval[0] != '\0')
2551 /* Next comes the name of the desired category. */
2552 retval = getenv (categoryname);
2553 if (retval != NULL && retval[0] != '\0')
2555 /* Last possibility is the LANG environment variable. */
2556 retval = getenv ("LANG");
2557 if (retval != NULL && retval[0] != '\0')
2559 #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
2560 /* MacOS X 10.2 or newer.
2561 Ignore invalid LANG value set by the Terminal application. */
2562 if (strcmp (retval, "UTF-8") != 0)
2564 #if defined __CYGWIN__
2566 Ignore dummy LANG value set by ~/.profile. */
2567 if (strcmp (retval, "C.UTF-8") != 0)
2576 gl_locale_name_default (void)
2579 "All implementations shall define a locale as the default locale, to be
2580 invoked when no environment variables are set, or set to the empty
2581 string. This default locale can be the POSIX locale or any other
2582 implementation-defined locale. Some implementations may provide
2583 facilities for local installation administrators to set the default
2584 locale, customizing it for each location. POSIX:2001 does not require
2587 The systems with such a facility are MacOS X and Windows: They provide a
2588 GUI that allows the user to choose a locale.
2589 - On MacOS X, by default, none of LC_* or LANG are set. Starting with
2590 MacOS X 10.4 or 10.5, LANG is set for processes launched by the
2591 'Terminal' application (but sometimes to an incorrect value "UTF-8").
2592 When no environment variable is set, setlocale (LC_ALL, "") uses the
2594 - On native Windows, by default, none of LC_* or LANG are set.
2595 When no environment variable is set, setlocale (LC_ALL, "") uses the
2596 locale chosen by the user.
2597 - On Cygwin 1.5.x, by default, none of LC_* or LANG are set.
2598 When no environment variable is set, setlocale (LC_ALL, "") uses the
2600 - On Cygwin 1.7, by default, LANG is set to "C.UTF-8" when the default
2601 ~/.profile is executed.
2602 When no environment variable is set, setlocale (LC_ALL, "") uses the
2603 "C.UTF-8" locale, which operates in the same way as the "C" locale.
2606 #if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined WIN32_NATIVE || defined __CYGWIN__)
2608 /* The system does not have a way of setting the locale, other than the
2609 POSIX specified environment variables. We use C as default locale. */
2614 /* Return an XPG style locale name language[_territory][@modifier].
2615 Don't even bother determining the codeset; it's not useful in this
2616 context, because message catalogs are not specific to a single
2619 # if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
2620 /* MacOS X 10.2 or newer */
2622 /* Cache the locale name, since CoreFoundation calls are expensive. */
2623 static const char *cached_localename;
2625 if (cached_localename == NULL)
2628 # if HAVE_CFLOCALECOPYCURRENT /* MacOS X 10.3 or newer */
2629 CFLocaleRef locale = CFLocaleCopyCurrent ();
2630 CFStringRef name = CFLocaleGetIdentifier (locale);
2632 if (CFStringGetCString (name, namebuf, sizeof(namebuf),
2633 kCFStringEncodingASCII))
2635 gl_locale_name_canonicalize (namebuf);
2636 cached_localename = strdup (namebuf);
2639 # elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */
2641 CFPreferencesCopyAppValue (CFSTR ("AppleLocale"),
2642 kCFPreferencesCurrentApplication);
2644 && CFGetTypeID (value) == CFStringGetTypeID ()
2645 && CFStringGetCString ((CFStringRef)value, namebuf, sizeof(namebuf),
2646 kCFStringEncodingASCII))
2648 gl_locale_name_canonicalize (namebuf);
2649 cached_localename = strdup (namebuf);
2652 if (cached_localename == NULL)
2653 cached_localename = "C";
2655 return cached_localename;
2660 # if defined WIN32_NATIVE || defined __CYGWIN__ /* WIN32 or Cygwin */
2664 /* Use native Win32 API locale ID. */
2665 lcid = GetThreadLocale ();
2667 return gl_locale_name_from_win32_LCID (lcid);
2674 gl_locale_name (int category, const char *categoryname)
2678 retval = gl_locale_name_posix (category, categoryname);
2682 return gl_locale_name_default ();