1 /* Determine name of the currently selected locale.
2 Copyright (C) 1995-1999, 2000-2008 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"
35 #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__
50 # define WIN32_LEAN_AND_MEAN
52 /* List of language codes, sorted by value:
75 0x17 LANG_RHAETO_ROMANCE
78 0x1a LANG_CROATIAN == LANG_SERBIAN
170 /* Mingw headers don't have latest language and sublanguage codes. */
171 # ifndef LANG_AFRIKAANS
172 # define LANG_AFRIKAANS 0x36
174 # ifndef LANG_ALBANIAN
175 # define LANG_ALBANIAN 0x1c
177 # ifndef LANG_AMHARIC
178 # define LANG_AMHARIC 0x5e
181 # define LANG_ARABIC 0x01
183 # ifndef LANG_ARMENIAN
184 # define LANG_ARMENIAN 0x2b
186 # ifndef LANG_ASSAMESE
187 # define LANG_ASSAMESE 0x4d
190 # define LANG_AZERI 0x2c
193 # define LANG_BASQUE 0x2d
195 # ifndef LANG_BELARUSIAN
196 # define LANG_BELARUSIAN 0x23
198 # ifndef LANG_BENGALI
199 # define LANG_BENGALI 0x45
201 # ifndef LANG_BURMESE
202 # define LANG_BURMESE 0x55
204 # ifndef LANG_CAMBODIAN
205 # define LANG_CAMBODIAN 0x53
207 # ifndef LANG_CATALAN
208 # define LANG_CATALAN 0x03
210 # ifndef LANG_CHEROKEE
211 # define LANG_CHEROKEE 0x5c
214 # define LANG_DIVEHI 0x65
217 # define LANG_EDO 0x66
219 # ifndef LANG_ESTONIAN
220 # define LANG_ESTONIAN 0x25
222 # ifndef LANG_FAEROESE
223 # define LANG_FAEROESE 0x38
226 # define LANG_FARSI 0x29
228 # ifndef LANG_FRISIAN
229 # define LANG_FRISIAN 0x62
231 # ifndef LANG_FULFULDE
232 # define LANG_FULFULDE 0x67
235 # define LANG_GAELIC 0x3c
237 # ifndef LANG_GALICIAN
238 # define LANG_GALICIAN 0x56
240 # ifndef LANG_GEORGIAN
241 # define LANG_GEORGIAN 0x37
243 # ifndef LANG_GUARANI
244 # define LANG_GUARANI 0x74
246 # ifndef LANG_GUJARATI
247 # define LANG_GUJARATI 0x47
250 # define LANG_HAUSA 0x68
252 # ifndef LANG_HAWAIIAN
253 # define LANG_HAWAIIAN 0x75
256 # define LANG_HEBREW 0x0d
259 # define LANG_HINDI 0x39
262 # define LANG_IBIBIO 0x69
265 # define LANG_IGBO 0x70
267 # ifndef LANG_INDONESIAN
268 # define LANG_INDONESIAN 0x21
270 # ifndef LANG_INUKTITUT
271 # define LANG_INUKTITUT 0x5d
273 # ifndef LANG_KANNADA
274 # define LANG_KANNADA 0x4b
277 # define LANG_KANURI 0x71
279 # ifndef LANG_KASHMIRI
280 # define LANG_KASHMIRI 0x60
283 # define LANG_KAZAK 0x3f
285 # ifndef LANG_KONKANI
286 # define LANG_KONKANI 0x57
289 # define LANG_KYRGYZ 0x40
292 # define LANG_LAO 0x54
295 # define LANG_LATIN 0x76
297 # ifndef LANG_LATVIAN
298 # define LANG_LATVIAN 0x26
300 # ifndef LANG_LITHUANIAN
301 # define LANG_LITHUANIAN 0x27
303 # ifndef LANG_MACEDONIAN
304 # define LANG_MACEDONIAN 0x2f
307 # define LANG_MALAY 0x3e
309 # ifndef LANG_MALAYALAM
310 # define LANG_MALAYALAM 0x4c
312 # ifndef LANG_MALTESE
313 # define LANG_MALTESE 0x3a
315 # ifndef LANG_MANIPURI
316 # define LANG_MANIPURI 0x58
319 # define LANG_MAORI 0x81
321 # ifndef LANG_MARATHI
322 # define LANG_MARATHI 0x4e
324 # ifndef LANG_MONGOLIAN
325 # define LANG_MONGOLIAN 0x50
328 # define LANG_NEPALI 0x61
331 # define LANG_ORIYA 0x48
334 # define LANG_OROMO 0x72
336 # ifndef LANG_PAPIAMENTU
337 # define LANG_PAPIAMENTU 0x79
340 # define LANG_PASHTO 0x63
342 # ifndef LANG_PUNJABI
343 # define LANG_PUNJABI 0x46
345 # ifndef LANG_QUECHUA
346 # define LANG_QUECHUA 0x6b
348 # ifndef LANG_RHAETO_ROMANCE
349 # define LANG_RHAETO_ROMANCE 0x17
352 # define LANG_SAAMI 0x3b
354 # ifndef LANG_SANSKRIT
355 # define LANG_SANSKRIT 0x4f
357 # ifndef LANG_SERBIAN
358 # define LANG_SERBIAN 0x1a
361 # define LANG_SINDHI 0x59
363 # ifndef LANG_SINHALESE
364 # define LANG_SINHALESE 0x5b
367 # define LANG_SLOVAK 0x1b
370 # define LANG_SOMALI 0x77
372 # ifndef LANG_SORBIAN
373 # define LANG_SORBIAN 0x2e
376 # define LANG_SOTHO 0x6c
379 # define LANG_SUTU 0x30
381 # ifndef LANG_SWAHILI
382 # define LANG_SWAHILI 0x41
385 # define LANG_SYRIAC 0x5a
387 # ifndef LANG_TAGALOG
388 # define LANG_TAGALOG 0x64
391 # define LANG_TAJIK 0x28
393 # ifndef LANG_TAMAZIGHT
394 # define LANG_TAMAZIGHT 0x5f
397 # define LANG_TAMIL 0x49
400 # define LANG_TATAR 0x44
403 # define LANG_TELUGU 0x4a
406 # define LANG_THAI 0x1e
408 # ifndef LANG_TIBETAN
409 # define LANG_TIBETAN 0x51
411 # ifndef LANG_TIGRINYA
412 # define LANG_TIGRINYA 0x73
415 # define LANG_TSONGA 0x31
418 # define LANG_TSWANA 0x32
420 # ifndef LANG_TURKMEN
421 # define LANG_TURKMEN 0x42
424 # define LANG_UIGHUR 0x80
426 # ifndef LANG_UKRAINIAN
427 # define LANG_UKRAINIAN 0x22
430 # define LANG_URDU 0x20
433 # define LANG_UZBEK 0x43
436 # define LANG_VENDA 0x33
438 # ifndef LANG_VIETNAMESE
439 # define LANG_VIETNAMESE 0x2a
442 # define LANG_WELSH 0x52
445 # define LANG_XHOSA 0x34
448 # define LANG_YI 0x78
450 # ifndef LANG_YIDDISH
451 # define LANG_YIDDISH 0x3d
454 # define LANG_YORUBA 0x6a
457 # define LANG_ZULU 0x35
459 # ifndef SUBLANG_ARABIC_SAUDI_ARABIA
460 # define SUBLANG_ARABIC_SAUDI_ARABIA 0x01
462 # ifndef SUBLANG_ARABIC_IRAQ
463 # define SUBLANG_ARABIC_IRAQ 0x02
465 # ifndef SUBLANG_ARABIC_EGYPT
466 # define SUBLANG_ARABIC_EGYPT 0x03
468 # ifndef SUBLANG_ARABIC_LIBYA
469 # define SUBLANG_ARABIC_LIBYA 0x04
471 # ifndef SUBLANG_ARABIC_ALGERIA
472 # define SUBLANG_ARABIC_ALGERIA 0x05
474 # ifndef SUBLANG_ARABIC_MOROCCO
475 # define SUBLANG_ARABIC_MOROCCO 0x06
477 # ifndef SUBLANG_ARABIC_TUNISIA
478 # define SUBLANG_ARABIC_TUNISIA 0x07
480 # ifndef SUBLANG_ARABIC_OMAN
481 # define SUBLANG_ARABIC_OMAN 0x08
483 # ifndef SUBLANG_ARABIC_YEMEN
484 # define SUBLANG_ARABIC_YEMEN 0x09
486 # ifndef SUBLANG_ARABIC_SYRIA
487 # define SUBLANG_ARABIC_SYRIA 0x0a
489 # ifndef SUBLANG_ARABIC_JORDAN
490 # define SUBLANG_ARABIC_JORDAN 0x0b
492 # ifndef SUBLANG_ARABIC_LEBANON
493 # define SUBLANG_ARABIC_LEBANON 0x0c
495 # ifndef SUBLANG_ARABIC_KUWAIT
496 # define SUBLANG_ARABIC_KUWAIT 0x0d
498 # ifndef SUBLANG_ARABIC_UAE
499 # define SUBLANG_ARABIC_UAE 0x0e
501 # ifndef SUBLANG_ARABIC_BAHRAIN
502 # define SUBLANG_ARABIC_BAHRAIN 0x0f
504 # ifndef SUBLANG_ARABIC_QATAR
505 # define SUBLANG_ARABIC_QATAR 0x10
507 # ifndef SUBLANG_AZERI_LATIN
508 # define SUBLANG_AZERI_LATIN 0x01
510 # ifndef SUBLANG_AZERI_CYRILLIC
511 # define SUBLANG_AZERI_CYRILLIC 0x02
513 # ifndef SUBLANG_BENGALI_INDIA
514 # define SUBLANG_BENGALI_INDIA 0x01
516 # ifndef SUBLANG_BENGALI_BANGLADESH
517 # define SUBLANG_BENGALI_BANGLADESH 0x02
519 # ifndef SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN
520 # define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN 0x05
522 # ifndef SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC
523 # define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC 0x08
525 # ifndef SUBLANG_CROATIAN_CROATIA
526 # define SUBLANG_CROATIAN_CROATIA 0x01
528 # ifndef SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN
529 # define SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN 0x04
531 # ifndef SUBLANG_CHINESE_MACAU
532 # define SUBLANG_CHINESE_MACAU 0x05
534 # ifndef SUBLANG_ENGLISH_SOUTH_AFRICA
535 # define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07
537 # ifndef SUBLANG_ENGLISH_JAMAICA
538 # define SUBLANG_ENGLISH_JAMAICA 0x08
540 # ifndef SUBLANG_ENGLISH_CARIBBEAN
541 # define SUBLANG_ENGLISH_CARIBBEAN 0x09
543 # ifndef SUBLANG_ENGLISH_BELIZE
544 # define SUBLANG_ENGLISH_BELIZE 0x0a
546 # ifndef SUBLANG_ENGLISH_TRINIDAD
547 # define SUBLANG_ENGLISH_TRINIDAD 0x0b
549 # ifndef SUBLANG_ENGLISH_ZIMBABWE
550 # define SUBLANG_ENGLISH_ZIMBABWE 0x0c
552 # ifndef SUBLANG_ENGLISH_PHILIPPINES
553 # define SUBLANG_ENGLISH_PHILIPPINES 0x0d
555 # ifndef SUBLANG_ENGLISH_INDONESIA
556 # define SUBLANG_ENGLISH_INDONESIA 0x0e
558 # ifndef SUBLANG_ENGLISH_HONGKONG
559 # define SUBLANG_ENGLISH_HONGKONG 0x0f
561 # ifndef SUBLANG_ENGLISH_INDIA
562 # define SUBLANG_ENGLISH_INDIA 0x10
564 # ifndef SUBLANG_ENGLISH_MALAYSIA
565 # define SUBLANG_ENGLISH_MALAYSIA 0x11
567 # ifndef SUBLANG_ENGLISH_SINGAPORE
568 # define SUBLANG_ENGLISH_SINGAPORE 0x12
570 # ifndef SUBLANG_FRENCH_LUXEMBOURG
571 # define SUBLANG_FRENCH_LUXEMBOURG 0x05
573 # ifndef SUBLANG_FRENCH_MONACO
574 # define SUBLANG_FRENCH_MONACO 0x06
576 # ifndef SUBLANG_FRENCH_WESTINDIES
577 # define SUBLANG_FRENCH_WESTINDIES 0x07
579 # ifndef SUBLANG_FRENCH_REUNION
580 # define SUBLANG_FRENCH_REUNION 0x08
582 # ifndef SUBLANG_FRENCH_CONGO
583 # define SUBLANG_FRENCH_CONGO 0x09
585 # ifndef SUBLANG_FRENCH_SENEGAL
586 # define SUBLANG_FRENCH_SENEGAL 0x0a
588 # ifndef SUBLANG_FRENCH_CAMEROON
589 # define SUBLANG_FRENCH_CAMEROON 0x0b
591 # ifndef SUBLANG_FRENCH_COTEDIVOIRE
592 # define SUBLANG_FRENCH_COTEDIVOIRE 0x0c
594 # ifndef SUBLANG_FRENCH_MALI
595 # define SUBLANG_FRENCH_MALI 0x0d
597 # ifndef SUBLANG_FRENCH_MOROCCO
598 # define SUBLANG_FRENCH_MOROCCO 0x0e
600 # ifndef SUBLANG_FRENCH_HAITI
601 # define SUBLANG_FRENCH_HAITI 0x0f
603 # ifndef SUBLANG_GERMAN_LUXEMBOURG
604 # define SUBLANG_GERMAN_LUXEMBOURG 0x04
606 # ifndef SUBLANG_GERMAN_LIECHTENSTEIN
607 # define SUBLANG_GERMAN_LIECHTENSTEIN 0x05
609 # ifndef SUBLANG_KASHMIRI_INDIA
610 # define SUBLANG_KASHMIRI_INDIA 0x02
612 # ifndef SUBLANG_MALAY_MALAYSIA
613 # define SUBLANG_MALAY_MALAYSIA 0x01
615 # ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM
616 # define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02
618 # ifndef SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA
619 # define SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA 0x01
621 # ifndef SUBLANG_MONGOLIAN_PRC
622 # define SUBLANG_MONGOLIAN_PRC 0x02
624 # ifndef SUBLANG_NEPALI_INDIA
625 # define SUBLANG_NEPALI_INDIA 0x02
627 # ifndef SUBLANG_PUNJABI_INDIA
628 # define SUBLANG_PUNJABI_INDIA 0x01
630 # ifndef SUBLANG_PUNJABI_PAKISTAN
631 # define SUBLANG_PUNJABI_PAKISTAN 0x02
633 # ifndef SUBLANG_QUECHUA_BOLIVIA
634 # define SUBLANG_QUECHUA_BOLIVIA 0x01
636 # ifndef SUBLANG_QUECHUA_ECUADOR
637 # define SUBLANG_QUECHUA_ECUADOR 0x02
639 # ifndef SUBLANG_QUECHUA_PERU
640 # define SUBLANG_QUECHUA_PERU 0x03
642 # ifndef SUBLANG_ROMANIAN_ROMANIA
643 # define SUBLANG_ROMANIAN_ROMANIA 0x01
645 # ifndef SUBLANG_ROMANIAN_MOLDOVA
646 # define SUBLANG_ROMANIAN_MOLDOVA 0x02
648 # ifndef SUBLANG_RUSSIAN_RUSSIA
649 # define SUBLANG_RUSSIAN_RUSSIA 0x01
651 # ifndef SUBLANG_RUSSIAN_MOLDAVIA
652 # define SUBLANG_RUSSIAN_MOLDAVIA 0x02
654 # ifndef SUBLANG_SERBIAN_LATIN
655 # define SUBLANG_SERBIAN_LATIN 0x02
657 # ifndef SUBLANG_SERBIAN_CYRILLIC
658 # define SUBLANG_SERBIAN_CYRILLIC 0x03
660 # ifndef SUBLANG_SINDHI_INDIA
661 # define SUBLANG_SINDHI_INDIA 0x01
663 # undef SUBLANG_SINDHI_PAKISTAN
664 # define SUBLANG_SINDHI_PAKISTAN 0x02
665 # ifndef SUBLANG_SINDHI_AFGHANISTAN
666 # define SUBLANG_SINDHI_AFGHANISTAN 0x02
668 # ifndef SUBLANG_SPANISH_GUATEMALA
669 # define SUBLANG_SPANISH_GUATEMALA 0x04
671 # ifndef SUBLANG_SPANISH_COSTA_RICA
672 # define SUBLANG_SPANISH_COSTA_RICA 0x05
674 # ifndef SUBLANG_SPANISH_PANAMA
675 # define SUBLANG_SPANISH_PANAMA 0x06
677 # ifndef SUBLANG_SPANISH_DOMINICAN_REPUBLIC
678 # define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07
680 # ifndef SUBLANG_SPANISH_VENEZUELA
681 # define SUBLANG_SPANISH_VENEZUELA 0x08
683 # ifndef SUBLANG_SPANISH_COLOMBIA
684 # define SUBLANG_SPANISH_COLOMBIA 0x09
686 # ifndef SUBLANG_SPANISH_PERU
687 # define SUBLANG_SPANISH_PERU 0x0a
689 # ifndef SUBLANG_SPANISH_ARGENTINA
690 # define SUBLANG_SPANISH_ARGENTINA 0x0b
692 # ifndef SUBLANG_SPANISH_ECUADOR
693 # define SUBLANG_SPANISH_ECUADOR 0x0c
695 # ifndef SUBLANG_SPANISH_CHILE
696 # define SUBLANG_SPANISH_CHILE 0x0d
698 # ifndef SUBLANG_SPANISH_URUGUAY
699 # define SUBLANG_SPANISH_URUGUAY 0x0e
701 # ifndef SUBLANG_SPANISH_PARAGUAY
702 # define SUBLANG_SPANISH_PARAGUAY 0x0f
704 # ifndef SUBLANG_SPANISH_BOLIVIA
705 # define SUBLANG_SPANISH_BOLIVIA 0x10
707 # ifndef SUBLANG_SPANISH_EL_SALVADOR
708 # define SUBLANG_SPANISH_EL_SALVADOR 0x11
710 # ifndef SUBLANG_SPANISH_HONDURAS
711 # define SUBLANG_SPANISH_HONDURAS 0x12
713 # ifndef SUBLANG_SPANISH_NICARAGUA
714 # define SUBLANG_SPANISH_NICARAGUA 0x13
716 # ifndef SUBLANG_SPANISH_PUERTO_RICO
717 # define SUBLANG_SPANISH_PUERTO_RICO 0x14
719 # ifndef SUBLANG_SPANISH_US
720 # define SUBLANG_SPANISH_US 0x15
722 # ifndef SUBLANG_SWEDISH_FINLAND
723 # define SUBLANG_SWEDISH_FINLAND 0x02
725 # ifndef SUBLANG_TAMAZIGHT_ARABIC
726 # define SUBLANG_TAMAZIGHT_ARABIC 0x01
728 # ifndef SUBLANG_TAMAZIGHT_ALGERIA_LATIN
729 # define SUBLANG_TAMAZIGHT_ALGERIA_LATIN 0x02
731 # ifndef SUBLANG_TIBETAN_PRC
732 # define SUBLANG_TIBETAN_PRC 0x01
734 # ifndef SUBLANG_TIBETAN_BHUTAN
735 # define SUBLANG_TIBETAN_BHUTAN 0x02
737 # ifndef SUBLANG_TIGRINYA_ETHIOPIA
738 # define SUBLANG_TIGRINYA_ETHIOPIA 0x01
740 # ifndef SUBLANG_TIGRINYA_ERITREA
741 # define SUBLANG_TIGRINYA_ERITREA 0x02
743 # ifndef SUBLANG_UIGHUR_PRC
744 # define SUBLANG_UIGHUR_PRC 0x01
746 # ifndef SUBLANG_URDU_PAKISTAN
747 # define SUBLANG_URDU_PAKISTAN 0x01
749 # ifndef SUBLANG_URDU_INDIA
750 # define SUBLANG_URDU_INDIA 0x02
752 # ifndef SUBLANG_UZBEK_LATIN
753 # define SUBLANG_UZBEK_LATIN 0x01
755 # ifndef SUBLANG_UZBEK_CYRILLIC
756 # define SUBLANG_UZBEK_CYRILLIC 0x02
758 /* GetLocaleInfoA operations. */
759 # ifndef LOCALE_SNAME
760 # define LOCALE_SNAME 0x5c
765 #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
766 /* MacOS X 10.2 or newer */
768 /* Canonicalize a MacOS X locale name to a Unix locale name.
769 NAME is a sufficiently large buffer.
770 On input, it contains the MacOS X locale name.
771 On output, it contains the Unix locale name. */
772 # if !defined IN_LIBINTL
776 gl_locale_name_canonicalize (char *name)
778 /* This conversion is based on a posting by
779 Deborah GoldSmith <goldsmit@apple.com> on 2005-03-08,
780 http://lists.apple.com/archives/carbon-dev/2005/Mar/msg00293.html */
782 /* Convert legacy (NeXTstep inherited) English names to Unix (ISO 639 and
783 ISO 3166) names. Prior to MacOS X 10.3, there is no API for doing this.
784 Therefore we do it ourselves, using a table based on the results of the
785 MacOS X 10.3.8 function
786 CFLocaleCreateCanonicalLocaleIdentifierFromString(). */
787 typedef struct { const char legacy[21+1]; const char unixy[5+1]; }
789 static const legacy_entry legacy_table[] = {
790 { "Afrikaans", "af" },
791 { "Albanian", "sq" },
794 { "Armenian", "hy" },
795 { "Assamese", "as" },
797 { "Azerbaijani", "az" },
799 { "Belarusian", "be" },
800 { "Belorussian", "be" },
802 { "Brazilian Portugese", "pt_BR" },
803 { "Brazilian Portuguese", "pt_BR" },
805 { "Bulgarian", "bg" },
807 { "Byelorussian", "be" },
810 { "Chichewa", "ny" },
812 { "Chinese, Simplified", "zh_CN" },
813 { "Chinese, Traditional", "zh_TW" },
814 { "Chinese, Tradtional", "zh_TW" },
815 { "Croatian", "hr" },
819 { "Dzongkha", "dz" },
821 { "Esperanto", "eo" },
822 { "Estonian", "et" },
826 { "Flemish", "nl_BE" },
828 { "Galician", "gl" },
829 { "Gallegan", "gl" },
830 { "Georgian", "ka" },
833 { "Greenlandic", "kl" },
835 { "Gujarati", "gu" },
836 { "Hawaiian", "haw" }, /* Yes, "haw", not "cpe". */
839 { "Hungarian", "hu" },
840 { "Icelandic", "is" },
841 { "Indonesian", "id" },
842 { "Inuktitut", "iu" },
845 { "Japanese", "ja" },
846 { "Javanese", "jv" },
847 { "Kalaallisut", "kl" },
849 { "Kashmiri", "ks" },
852 { "Kinyarwanda", "rw" },
858 { "Lithuanian", "lt" },
859 { "Macedonian", "mk" },
860 { "Malagasy", "mg" },
862 { "Malayalam", "ml" },
866 { "Moldavian", "mo" },
867 { "Mongolian", "mn" },
869 { "Norwegian", "nb" }, /* Yes, "nb", not the obsolete "no". */
878 { "Portuguese", "pt" },
879 { "Portuguese, Brazilian", "pt_BR" },
883 { "Romanian", "ro" },
887 { "Sami", "se_NO" }, /* Not just "se". */
888 { "Sanskrit", "sa" },
889 { "Scottish", "gd" },
891 { "Simplified Chinese", "zh_CN" },
893 { "Sinhalese", "si" },
895 { "Slovenian", "sl" },
898 { "Sundanese", "su" },
909 { "Tigrinya", "ti" },
911 { "Traditional Chinese", "zh_TW" },
915 { "Ukrainian", "uk" },
918 { "Vietnamese", "vi" },
923 /* Convert new-style locale names with language tags (ISO 639 and ISO 15924)
924 to Unix (ISO 639 and ISO 3166) names. */
925 typedef struct { const char langtag[7+1]; const char unixy[12+1]; }
927 static const langtag_entry langtag_table[] = {
928 /* MacOS X has "az-Arab", "az-Cyrl", "az-Latn".
929 The default script for az on Unix is Latin. */
931 /* MacOS X has "ga-dots". Does not yet exist on Unix. */
933 /* MacOS X has "kk-Cyrl". Does not yet exist on Unix. */
934 /* MacOS X has "mn-Cyrl", "mn-Mong".
935 The default script for mn on Unix is Cyrillic. */
937 /* MacOS X has "ms-Arab", "ms-Latn".
938 The default script for ms on Unix is Latin. */
940 /* MacOS X has "tg-Cyrl".
941 The default script for tg on Unix is Cyrillic. */
943 /* MacOS X has "tk-Cyrl". Does not yet exist on Unix. */
944 /* MacOS X has "tt-Cyrl".
945 The default script for tt on Unix is Cyrillic. */
947 /* MacOS X has "zh-Hans", "zh-Hant".
948 Country codes are used to distinguish these on Unix. */
949 { "zh-Hans", "zh_CN" },
950 { "zh-Hant", "zh_TW" }
953 /* Convert script names (ISO 15924) to Unix conventions.
954 See http://www.unicode.org/iso15924/iso15924-codes.html */
955 typedef struct { const char script[4+1]; const char unixy[9+1]; }
957 static const script_entry script_table[] = {
958 { "Arab", "arabic" },
959 { "Cyrl", "cyrillic" },
960 { "Mong", "mongolian" }
963 /* Step 1: Convert using legacy_table. */
964 if (name[0] >= 'A' && name[0] <= 'Z')
968 i2 = sizeof (legacy_table) / sizeof (legacy_entry);
971 /* At this point we know that if name occurs in legacy_table,
972 its index must be >= i1 and < i2. */
973 unsigned int i = (i1 + i2) >> 1;
974 const legacy_entry *p = &legacy_table[i];
975 if (strcmp (name, p->legacy) < 0)
980 if (strcmp (name, legacy_table[i1].legacy) == 0)
982 strcpy (name, legacy_table[i1].unixy);
987 /* Step 2: Convert using langtag_table and script_table. */
988 if (strlen (name) == 7 && name[2] == '-')
992 i2 = sizeof (langtag_table) / sizeof (langtag_entry);
995 /* At this point we know that if name occurs in langtag_table,
996 its index must be >= i1 and < i2. */
997 unsigned int i = (i1 + i2) >> 1;
998 const langtag_entry *p = &langtag_table[i];
999 if (strcmp (name, p->langtag) < 0)
1004 if (strcmp (name, langtag_table[i1].langtag) == 0)
1006 strcpy (name, langtag_table[i1].unixy);
1011 i2 = sizeof (script_table) / sizeof (script_entry);
1014 /* At this point we know that if (name + 3) occurs in script_table,
1015 its index must be >= i1 and < i2. */
1016 unsigned int i = (i1 + i2) >> 1;
1017 const script_entry *p = &script_table[i];
1018 if (strcmp (name + 3, p->script) < 0)
1023 if (strcmp (name + 3, script_table[i1].script) == 0)
1026 strcpy (name + 3, script_table[i1].unixy);
1031 /* Step 3: Convert new-style dash to Unix underscore. */
1034 for (p = name; *p != '\0'; p++)
1045 /* Canonicalize a Win32 native locale name to a Unix locale name.
1046 NAME is a sufficiently large buffer.
1047 On input, it contains the Win32 locale name.
1048 On output, it contains the Unix locale name. */
1049 # if !defined IN_LIBINTL
1053 gl_locale_name_canonicalize (char *name)
1055 /* FIXME: This is probably incomplete: it does not handle "zh-Hans" and
1059 for (p = name; *p != '\0'; p++)
1064 for (; *p != '\0'; p++)
1066 if (*p >= 'a' && *p <= 'z')
1078 # if !defined IN_LIBINTL
1082 gl_locale_name_from_win32_LANGID (LANGID langid)
1084 /* Activate the new code only when the GETTEXT_MUI environment variable is
1085 set, for the time being, since the new code is not well tested. */
1086 if (getenv ("GETTEXT_MUI") != NULL)
1088 static char namebuf[256];
1090 /* Query the system's notion of locale name.
1091 On Windows95/98/ME, GetLocaleInfoA returns some incorrect results.
1092 But we don't need to support systems that are so old. */
1093 if (GetLocaleInfoA (MAKELCID (langid, SORT_DEFAULT), LOCALE_SNAME,
1094 namebuf, sizeof (namebuf) - 1))
1096 /* Convert it to a Unix locale name. */
1097 gl_locale_name_canonicalize (namebuf);
1101 /* Internet Explorer has an LCID to RFC3066 name mapping stored in
1102 HKEY_CLASSES_ROOT\Mime\Database\Rfc1766. But we better don't use that
1103 since IE's i18n subsystem is known to be inconsistent with the Win32 base
1104 (e.g. they have different character conversion facilities that produce
1105 different results). */
1106 /* Use our own table. */
1110 /* Split into language and territory part. */
1111 primary = PRIMARYLANGID (langid);
1112 sub = SUBLANGID (langid);
1114 /* Dispatch on language.
1115 See also http://www.unicode.org/unicode/onlinedat/languages.html .
1116 For details about languages, see http://www.ethnologue.com/ . */
1119 case LANG_AFRIKAANS: return "af_ZA";
1120 case LANG_ALBANIAN: return "sq_AL";
1121 case LANG_AMHARIC: return "am_ET";
1125 case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA";
1126 case SUBLANG_ARABIC_IRAQ: return "ar_IQ";
1127 case SUBLANG_ARABIC_EGYPT: return "ar_EG";
1128 case SUBLANG_ARABIC_LIBYA: return "ar_LY";
1129 case SUBLANG_ARABIC_ALGERIA: return "ar_DZ";
1130 case SUBLANG_ARABIC_MOROCCO: return "ar_MA";
1131 case SUBLANG_ARABIC_TUNISIA: return "ar_TN";
1132 case SUBLANG_ARABIC_OMAN: return "ar_OM";
1133 case SUBLANG_ARABIC_YEMEN: return "ar_YE";
1134 case SUBLANG_ARABIC_SYRIA: return "ar_SY";
1135 case SUBLANG_ARABIC_JORDAN: return "ar_JO";
1136 case SUBLANG_ARABIC_LEBANON: return "ar_LB";
1137 case SUBLANG_ARABIC_KUWAIT: return "ar_KW";
1138 case SUBLANG_ARABIC_UAE: return "ar_AE";
1139 case SUBLANG_ARABIC_BAHRAIN: return "ar_BH";
1140 case SUBLANG_ARABIC_QATAR: return "ar_QA";
1143 case LANG_ARMENIAN: return "hy_AM";
1144 case LANG_ASSAMESE: return "as_IN";
1148 /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */
1149 case SUBLANG_AZERI_LATIN: return "az_AZ@latin";
1150 case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic";
1156 case SUBLANG_DEFAULT: return "eu_ES";
1158 return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */
1159 case LANG_BELARUSIAN: return "be_BY";
1163 case SUBLANG_BENGALI_INDIA: return "bn_IN";
1164 case SUBLANG_BENGALI_BANGLADESH: return "bn_BD";
1167 case LANG_BULGARIAN: return "bg_BG";
1168 case LANG_BURMESE: return "my_MM";
1169 case LANG_CAMBODIAN: return "km_KH";
1170 case LANG_CATALAN: return "ca_ES";
1171 case LANG_CHEROKEE: return "chr_US";
1175 case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW";
1176 case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN";
1177 case SUBLANG_CHINESE_HONGKONG: return "zh_HK";
1178 case SUBLANG_CHINESE_SINGAPORE: return "zh_SG";
1179 case SUBLANG_CHINESE_MACAU: return "zh_MO";
1182 case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN
1183 * What used to be called Serbo-Croatian
1184 * should really now be two separate
1185 * languages because of political reasons.
1186 * (Says tml, who knows nothing about Serbian
1188 * (I can feel those flames coming already.)
1192 case SUBLANG_CROATIAN_CROATIA: return "hr_HR";
1193 case SUBLANG_SERBIAN_LATIN: return "sr_CS";
1194 case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic";
1195 case SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN: return "hr_BA";
1196 case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN: return "bs_BA";
1197 case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC: return "bs_BA@cyrillic";
1200 case LANG_CZECH: return "cs_CZ";
1201 case LANG_DANISH: return "da_DK";
1202 case LANG_DIVEHI: return "dv_MV";
1206 case SUBLANG_DUTCH: return "nl_NL";
1207 case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE";
1210 case LANG_EDO: return "bin_NG";
1214 /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought
1215 * English was the language spoken in England.
1218 case SUBLANG_ENGLISH_US: return "en_US";
1219 case SUBLANG_ENGLISH_UK: return "en_GB";
1220 case SUBLANG_ENGLISH_AUS: return "en_AU";
1221 case SUBLANG_ENGLISH_CAN: return "en_CA";
1222 case SUBLANG_ENGLISH_NZ: return "en_NZ";
1223 case SUBLANG_ENGLISH_EIRE: return "en_IE";
1224 case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA";
1225 case SUBLANG_ENGLISH_JAMAICA: return "en_JM";
1226 case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */
1227 case SUBLANG_ENGLISH_BELIZE: return "en_BZ";
1228 case SUBLANG_ENGLISH_TRINIDAD: return "en_TT";
1229 case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW";
1230 case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH";
1231 case SUBLANG_ENGLISH_INDONESIA: return "en_ID";
1232 case SUBLANG_ENGLISH_HONGKONG: return "en_HK";
1233 case SUBLANG_ENGLISH_INDIA: return "en_IN";
1234 case SUBLANG_ENGLISH_MALAYSIA: return "en_MY";
1235 case SUBLANG_ENGLISH_SINGAPORE: return "en_SG";
1238 case LANG_ESTONIAN: return "et_EE";
1239 case LANG_FAEROESE: return "fo_FO";
1240 case LANG_FARSI: return "fa_IR";
1241 case LANG_FINNISH: return "fi_FI";
1245 case SUBLANG_FRENCH: return "fr_FR";
1246 case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE";
1247 case SUBLANG_FRENCH_CANADIAN: return "fr_CA";
1248 case SUBLANG_FRENCH_SWISS: return "fr_CH";
1249 case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU";
1250 case SUBLANG_FRENCH_MONACO: return "fr_MC";
1251 case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */
1252 case SUBLANG_FRENCH_REUNION: return "fr_RE";
1253 case SUBLANG_FRENCH_CONGO: return "fr_CG";
1254 case SUBLANG_FRENCH_SENEGAL: return "fr_SN";
1255 case SUBLANG_FRENCH_CAMEROON: return "fr_CM";
1256 case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI";
1257 case SUBLANG_FRENCH_MALI: return "fr_ML";
1258 case SUBLANG_FRENCH_MOROCCO: return "fr_MA";
1259 case SUBLANG_FRENCH_HAITI: return "fr_HT";
1262 case LANG_FRISIAN: return "fy_NL";
1264 /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin. */
1269 case 0x01: /* SCOTTISH */ return "gd_GB";
1270 case 0x02: /* IRISH */ return "ga_IE";
1273 case LANG_GALICIAN: return "gl_ES";
1274 case LANG_GEORGIAN: return "ka_GE";
1278 case SUBLANG_GERMAN: return "de_DE";
1279 case SUBLANG_GERMAN_SWISS: return "de_CH";
1280 case SUBLANG_GERMAN_AUSTRIAN: return "de_AT";
1281 case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU";
1282 case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI";
1285 case LANG_GREEK: return "el_GR";
1286 case LANG_GUARANI: return "gn_PY";
1287 case LANG_GUJARATI: return "gu_IN";
1288 case LANG_HAUSA: return "ha_NG";
1290 /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers)
1291 or Hawaii Creole English ("cpe_US", 600000 speakers)? */
1293 case LANG_HEBREW: return "he_IL";
1294 case LANG_HINDI: return "hi_IN";
1295 case LANG_HUNGARIAN: return "hu_HU";
1296 case LANG_IBIBIO: return "nic_NG";
1297 case LANG_ICELANDIC: return "is_IS";
1298 case LANG_IGBO: return "ig_NG";
1299 case LANG_INDONESIAN: return "id_ID";
1300 case LANG_INUKTITUT: return "iu_CA";
1304 case SUBLANG_ITALIAN: return "it_IT";
1305 case SUBLANG_ITALIAN_SWISS: return "it_CH";
1308 case LANG_JAPANESE: return "ja_JP";
1309 case LANG_KANNADA: return "kn_IN";
1310 case LANG_KANURI: return "kr_NG";
1314 case SUBLANG_DEFAULT: return "ks_PK";
1315 case SUBLANG_KASHMIRI_INDIA: return "ks_IN";
1318 case LANG_KAZAK: return "kk_KZ";
1320 /* FIXME: Adjust this when such locales appear on Unix. */
1322 case LANG_KOREAN: return "ko_KR";
1323 case LANG_KYRGYZ: return "ky_KG";
1324 case LANG_LAO: return "lo_LA";
1325 case LANG_LATIN: return "la_VA";
1326 case LANG_LATVIAN: return "lv_LV";
1327 case LANG_LITHUANIAN: return "lt_LT";
1328 case LANG_MACEDONIAN: return "mk_MK";
1332 case SUBLANG_MALAY_MALAYSIA: return "ms_MY";
1333 case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN";
1336 case LANG_MALAYALAM: return "ml_IN";
1337 case LANG_MALTESE: return "mt_MT";
1339 /* FIXME: Adjust this when such locales appear on Unix. */
1341 case LANG_MAORI: return "mi_NZ";
1342 case LANG_MARATHI: return "mr_IN";
1343 case LANG_MONGOLIAN:
1346 case SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA: return "mn_MN";
1347 case SUBLANG_MONGOLIAN_PRC: return "mn_CN";
1349 return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN". */
1353 case SUBLANG_DEFAULT: return "ne_NP";
1354 case SUBLANG_NEPALI_INDIA: return "ne_IN";
1357 case LANG_NORWEGIAN:
1360 case SUBLANG_NORWEGIAN_BOKMAL: return "nb_NO";
1361 case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO";
1364 case LANG_ORIYA: return "or_IN";
1365 case LANG_OROMO: return "om_ET";
1366 case LANG_PAPIAMENTU: return "pap_AN";
1368 return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF". */
1369 case LANG_POLISH: return "pl_PL";
1370 case LANG_PORTUGUESE:
1373 case SUBLANG_PORTUGUESE: return "pt_PT";
1374 /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT.
1375 Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */
1376 case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR";
1382 case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */
1383 case SUBLANG_PUNJABI_PAKISTAN: return "pa_PK"; /* Arabic script */
1389 case SUBLANG_QUECHUA_BOLIVIA: return "qu_BO";
1390 case SUBLANG_QUECHUA_ECUADOR: return "qu_EC";
1391 case SUBLANG_QUECHUA_PERU: return "qu_PE";
1394 case LANG_RHAETO_ROMANCE: return "rm_CH";
1398 case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO";
1399 case SUBLANG_ROMANIAN_MOLDOVA: return "ro_MD";
1405 case SUBLANG_RUSSIAN_RUSSIA: return "ru_RU";
1406 case SUBLANG_RUSSIAN_MOLDAVIA: return "ru_MD";
1408 return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */
1409 case LANG_SAAMI: /* actually Northern Sami */ return "se_NO";
1410 case LANG_SANSKRIT: return "sa_IN";
1414 case SUBLANG_SINDHI_INDIA: return "sd_IN";
1415 case SUBLANG_SINDHI_PAKISTAN: return "sd_PK";
1416 /*case SUBLANG_SINDHI_AFGHANISTAN: return "sd_AF";*/
1419 case LANG_SINHALESE: return "si_LK";
1420 case LANG_SLOVAK: return "sk_SK";
1421 case LANG_SLOVENIAN: return "sl_SI";
1422 case LANG_SOMALI: return "so_SO";
1424 /* FIXME: Adjust this when such locales appear on Unix. */
1427 /* <http://www.microsoft.com/globaldev/reference/lcid-all.mspx> calls
1428 it "Sepedi"; according to
1429 <http://www.ethnologue.com/show_language.asp?code=nso>
1430 <http://www.ethnologue.com/show_language.asp?code=sot>
1431 it's the same as Northern Sotho. */
1436 case SUBLANG_SPANISH: return "es_ES";
1437 case SUBLANG_SPANISH_MEXICAN: return "es_MX";
1438 case SUBLANG_SPANISH_MODERN:
1439 return "es_ES@modern"; /* not seen on Unix */
1440 case SUBLANG_SPANISH_GUATEMALA: return "es_GT";
1441 case SUBLANG_SPANISH_COSTA_RICA: return "es_CR";
1442 case SUBLANG_SPANISH_PANAMA: return "es_PA";
1443 case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO";
1444 case SUBLANG_SPANISH_VENEZUELA: return "es_VE";
1445 case SUBLANG_SPANISH_COLOMBIA: return "es_CO";
1446 case SUBLANG_SPANISH_PERU: return "es_PE";
1447 case SUBLANG_SPANISH_ARGENTINA: return "es_AR";
1448 case SUBLANG_SPANISH_ECUADOR: return "es_EC";
1449 case SUBLANG_SPANISH_CHILE: return "es_CL";
1450 case SUBLANG_SPANISH_URUGUAY: return "es_UY";
1451 case SUBLANG_SPANISH_PARAGUAY: return "es_PY";
1452 case SUBLANG_SPANISH_BOLIVIA: return "es_BO";
1453 case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV";
1454 case SUBLANG_SPANISH_HONDURAS: return "es_HN";
1455 case SUBLANG_SPANISH_NICARAGUA: return "es_NI";
1456 case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR";
1457 case SUBLANG_SPANISH_US: return "es_US";
1460 case LANG_SUTU: return "bnt_TZ"; /* or "st_LS" or "nso_ZA"? */
1461 case LANG_SWAHILI: return "sw_KE";
1465 case SUBLANG_DEFAULT: return "sv_SE";
1466 case SUBLANG_SWEDISH_FINLAND: return "sv_FI";
1469 case LANG_SYRIAC: return "syr_TR"; /* An extinct language. */
1470 case LANG_TAGALOG: return "tl_PH";
1471 case LANG_TAJIK: return "tg_TJ";
1472 case LANG_TAMAZIGHT:
1475 /* FIXME: Adjust this when Tamazight locales appear on Unix. */
1476 case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic";
1477 case SUBLANG_TAMAZIGHT_ALGERIA_LATIN: return "ber_DZ@latin";
1483 case SUBLANG_DEFAULT: return "ta_IN";
1485 return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */
1486 case LANG_TATAR: return "tt_RU";
1487 case LANG_TELUGU: return "te_IN";
1488 case LANG_THAI: return "th_TH";
1492 case SUBLANG_TIBETAN_PRC:
1493 /* Most Tibetans would not like "bo_CN". But Tibet does not yet
1494 have a country code of its own. */
1496 case SUBLANG_TIBETAN_BHUTAN: return "bo_BT";
1502 case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET";
1503 case SUBLANG_TIGRINYA_ERITREA: return "ti_ER";
1506 case LANG_TSONGA: return "ts_ZA";
1507 case LANG_TSWANA: return "tn_BW";
1508 case LANG_TURKISH: return "tr_TR";
1509 case LANG_TURKMEN: return "tk_TM";
1513 case SUBLANG_UIGHUR_PRC: return "ug_CN";
1516 case LANG_UKRAINIAN: return "uk_UA";
1520 case SUBLANG_URDU_PAKISTAN: return "ur_PK";
1521 case SUBLANG_URDU_INDIA: return "ur_IN";
1527 case SUBLANG_UZBEK_LATIN: return "uz_UZ";
1528 case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic";
1531 case LANG_VENDA: return "ve_ZA";
1532 case LANG_VIETNAMESE: return "vi_VN";
1533 case LANG_WELSH: return "cy_GB";
1534 case LANG_XHOSA: return "xh_ZA";
1535 case LANG_YI: return "sit_CN";
1536 case LANG_YIDDISH: return "yi_IL";
1537 case LANG_YORUBA: return "yo_NG";
1538 case LANG_ZULU: return "zu_ZA";
1539 default: return "C";
1544 # if !defined IN_LIBINTL
1548 gl_locale_name_from_win32_LCID (LCID lcid)
1552 /* Strip off the sorting rules, keep only the language part. */
1553 langid = LANGIDFROMLCID (lcid);
1555 return gl_locale_name_from_win32_LANGID (langid);
1561 /* XPG3 defines the result of 'setlocale (category, NULL)' as:
1562 "Directs 'setlocale()' to query 'category' and return the current
1563 setting of 'local'."
1564 However it does not specify the exact format. Neither do SUSV2 and
1565 ISO C 99. So we can use this feature only on selected systems (e.g.
1566 those using GNU C Library). */
1567 #if defined _LIBC || (defined __GLIBC__ && __GLIBC__ >= 2)
1568 # define HAVE_LOCALE_NULL
1571 /* Determine the current locale's name, and canonicalize it into XPG syntax
1572 language[_territory][.codeset][@modifier]
1573 The codeset part in the result is not reliable; the locale_charset()
1574 should be used for codeset information instead.
1575 The result must not be freed; it is statically allocated. */
1578 gl_locale_name_posix (int category, const char *categoryname)
1580 /* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
1581 On some systems this can be done by the 'setlocale' function itself. */
1582 #if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
1583 return setlocale (category, NULL);
1587 /* Setting of LC_ALL overrides all other. */
1588 retval = getenv ("LC_ALL");
1589 if (retval != NULL && retval[0] != '\0')
1591 /* Next comes the name of the desired category. */
1592 retval = getenv (categoryname);
1593 if (retval != NULL && retval[0] != '\0')
1595 /* Last possibility is the LANG environment variable. */
1596 retval = getenv ("LANG");
1597 if (retval != NULL && retval[0] != '\0')
1605 gl_locale_name_default (void)
1608 "All implementations shall define a locale as the default locale, to be
1609 invoked when no environment variables are set, or set to the empty
1610 string. This default locale can be the POSIX locale or any other
1611 implementation-defined locale. Some implementations may provide
1612 facilities for local installation administrators to set the default
1613 locale, customizing it for each location. POSIX:2001 does not require
1616 #if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined(WIN32_NATIVE))
1618 /* The system does not have a way of setting the locale, other than the
1619 POSIX specified environment variables. We use C as default locale. */
1624 /* Return an XPG style locale name language[_territory][@modifier].
1625 Don't even bother determining the codeset; it's not useful in this
1626 context, because message catalogs are not specific to a single
1629 # if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
1630 /* MacOS X 10.2 or newer */
1632 /* Cache the locale name, since CoreFoundation calls are expensive. */
1633 static const char *cached_localename;
1635 if (cached_localename == NULL)
1638 # if HAVE_CFLOCALECOPYCURRENT /* MacOS X 10.3 or newer */
1639 CFLocaleRef locale = CFLocaleCopyCurrent ();
1640 CFStringRef name = CFLocaleGetIdentifier (locale);
1642 if (CFStringGetCString (name, namebuf, sizeof(namebuf),
1643 kCFStringEncodingASCII))
1645 gl_locale_name_canonicalize (namebuf);
1646 cached_localename = strdup (namebuf);
1649 # elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */
1651 CFPreferencesCopyAppValue (CFSTR ("AppleLocale"),
1652 kCFPreferencesCurrentApplication);
1654 && CFGetTypeID (value) == CFStringGetTypeID ()
1655 && CFStringGetCString ((CFStringRef)value, namebuf, sizeof(namebuf),
1656 kCFStringEncodingASCII))
1658 gl_locale_name_canonicalize (namebuf);
1659 cached_localename = strdup (namebuf);
1662 if (cached_localename == NULL)
1663 cached_localename = "C";
1665 return cached_localename;
1670 # if defined(WIN32_NATIVE) /* WIN32, not Cygwin */
1674 /* Use native Win32 API locale ID. */
1675 lcid = GetThreadLocale ();
1677 return gl_locale_name_from_win32_LCID (lcid);
1684 gl_locale_name (int category, const char *categoryname)
1688 retval = gl_locale_name_posix (category, categoryname);
1692 return gl_locale_name_default ();