701
# if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
702
/* MacOS X 10.2 or newer */
704
/* Canonicalize a MacOS X locale name to a Unix locale name.
705
NAME is a sufficiently large buffer.
706
On input, it contains the MacOS X locale name.
707
On output, it contains the Unix locale name. */
708
# if !defined IN_LIBINTL
712
gl_locale_name_canonicalize (char *name)
714
/* This conversion is based on a posting by
715
Deborah GoldSmith <goldsmit@apple.com> on 2005-03-08,
716
http://lists.apple.com/archives/carbon-dev/2005/Mar/msg00293.html */
718
/* Convert legacy (NeXTstep inherited) English names to Unix (ISO 639 and
719
ISO 3166) names. Prior to MacOS X 10.3, there is no API for doing this.
720
Therefore we do it ourselves, using a table based on the results of the
721
MacOS X 10.3.8 function
722
CFLocaleCreateCanonicalLocaleIdentifierFromString(). */
723
typedef struct { const char legacy[21+1]; const char unixy[5+1]; }
725
static const legacy_entry legacy_table[] = {
726
{ "Afrikaans", "af" },
727
{ "Albanian", "sq" },
730
{ "Armenian", "hy" },
731
{ "Assamese", "as" },
733
{ "Azerbaijani", "az" },
735
{ "Belarusian", "be" },
736
{ "Belorussian", "be" },
738
{ "Brazilian Portugese", "pt_BR" },
739
{ "Brazilian Portuguese", "pt_BR" },
741
{ "Bulgarian", "bg" },
743
{ "Byelorussian", "be" },
746
{ "Chichewa", "ny" },
748
{ "Chinese, Simplified", "zh_CN" },
749
{ "Chinese, Traditional", "zh_TW" },
750
{ "Chinese, Tradtional", "zh_TW" },
751
{ "Croatian", "hr" },
755
{ "Dzongkha", "dz" },
757
{ "Esperanto", "eo" },
758
{ "Estonian", "et" },
762
{ "Flemish", "nl_BE" },
764
{ "Galician", "gl" },
765
{ "Gallegan", "gl" },
766
{ "Georgian", "ka" },
769
{ "Greenlandic", "kl" },
771
{ "Gujarati", "gu" },
772
{ "Hawaiian", "haw" }, /* Yes, "haw", not "cpe". */
775
{ "Hungarian", "hu" },
776
{ "Icelandic", "is" },
777
{ "Indonesian", "id" },
778
{ "Inuktitut", "iu" },
781
{ "Japanese", "ja" },
782
{ "Javanese", "jv" },
783
{ "Kalaallisut", "kl" },
785
{ "Kashmiri", "ks" },
788
{ "Kinyarwanda", "rw" },
794
{ "Lithuanian", "lt" },
795
{ "Macedonian", "mk" },
796
{ "Malagasy", "mg" },
798
{ "Malayalam", "ml" },
802
{ "Moldavian", "mo" },
803
{ "Mongolian", "mn" },
805
{ "Norwegian", "nb" }, /* Yes, "nb", not the obsolete "no". */
814
{ "Portuguese", "pt" },
815
{ "Portuguese, Brazilian", "pt_BR" },
819
{ "Romanian", "ro" },
823
{ "Sami", "se_NO" }, /* Not just "se". */
824
{ "Sanskrit", "sa" },
825
{ "Scottish", "gd" },
827
{ "Simplified Chinese", "zh_CN" },
829
{ "Sinhalese", "si" },
831
{ "Slovenian", "sl" },
834
{ "Sundanese", "su" },
845
{ "Tigrinya", "ti" },
847
{ "Traditional Chinese", "zh_TW" },
851
{ "Ukrainian", "uk" },
854
{ "Vietnamese", "vi" },
859
/* Convert new-style locale names with language tags (ISO 639 and ISO 15924)
860
to Unix (ISO 639 and ISO 3166) names. */
861
typedef struct { const char langtag[7+1]; const char unixy[12+1]; }
863
static const langtag_entry langtag_table[] = {
864
/* MacOS X has "az-Arab", "az-Cyrl", "az-Latn".
865
The default script for az on Unix is Latin. */
867
/* MacOS X has "ga-dots". Does not yet exist on Unix. */
869
/* MacOS X has "kk-Cyrl". Does not yet exist on Unix. */
870
/* MacOS X has "mn-Cyrl", "mn-Mong".
871
The default script for mn on Unix is Cyrillic. */
873
/* MacOS X has "ms-Arab", "ms-Latn".
874
The default script for ms on Unix is Latin. */
876
/* MacOS X has "tg-Cyrl".
877
The default script for tg on Unix is Cyrillic. */
879
/* MacOS X has "tk-Cyrl". Does not yet exist on Unix. */
880
/* MacOS X has "tt-Cyrl".
881
The default script for tt on Unix is Cyrillic. */
883
/* MacOS X has "zh-Hans", "zh-Hant".
884
Country codes are used to distinguish these on Unix. */
885
{ "zh-Hans", "zh_CN" },
886
{ "zh-Hant", "zh_TW" }
889
/* Convert script names (ISO 15924) to Unix conventions.
890
See http://www.unicode.org/iso15924/iso15924-codes.html */
891
typedef struct { const char script[4+1]; const char unixy[9+1]; }
893
static const script_entry script_table[] = {
894
{ "Arab", "arabic" },
895
{ "Cyrl", "cyrillic" },
896
{ "Mong", "mongolian" }
899
/* Step 1: Convert using legacy_table. */
900
if (name[0] >= 'A' && name[0] <= 'Z')
904
i2 = sizeof (legacy_table) / sizeof (legacy_entry);
907
/* At this point we know that if name occurs in legacy_table,
908
its index must be >= i1 and < i2. */
909
unsigned int i = (i1 + i2) >> 1;
910
const legacy_entry *p = &legacy_table[i];
911
if (strcmp (name, p->legacy) < 0)
916
if (strcmp (name, legacy_table[i1].legacy) == 0)
918
strcpy (name, legacy_table[i1].unixy);
923
/* Step 2: Convert using langtag_table and script_table. */
924
if (strlen (name) == 7 && name[2] == '-')
928
i2 = sizeof (langtag_table) / sizeof (langtag_entry);
931
/* At this point we know that if name occurs in langtag_table,
932
its index must be >= i1 and < i2. */
933
unsigned int i = (i1 + i2) >> 1;
934
const langtag_entry *p = &langtag_table[i];
935
if (strcmp (name, p->langtag) < 0)
940
if (strcmp (name, langtag_table[i1].langtag) == 0)
942
strcpy (name, langtag_table[i1].unixy);
947
i2 = sizeof (script_table) / sizeof (script_entry);
950
/* At this point we know that if (name + 3) occurs in script_table,
951
its index must be >= i1 and < i2. */
952
unsigned int i = (i1 + i2) >> 1;
953
const script_entry *p = &script_table[i];
954
if (strcmp (name + 3, p->script) < 0)
959
if (strcmp (name + 3, script_table[i1].script) == 0)
962
strcpy (name + 3, script_table[i1].unixy);
967
/* Step 3: Convert new-style dash to Unix underscore. */
970
for (p = name; *p != '\0'; p++)
697
978
/* XPG3 defines the result of 'setlocale (category, NULL)' as:
698
979
"Directs 'setlocale()' to query 'category' and return the current
699
980
setting of 'local'."
700
981
However it does not specify the exact format. Neither do SUSV2 and
701
982
ISO C 99. So we can use this feature only on selected systems (e.g.
702
983
those using GNU C Library). */
703
#if defined _LIBC || (defined __GNU_LIBRARY__ && __GNU_LIBRARY__ >= 2)
984
#if defined _LIBC || (defined __GLIBC__ && __GLIBC__ >= 2)
704
985
# define HAVE_LOCALE_NULL
707
988
/* Determine the current locale's name, and canonicalize it into XPG syntax
708
language[_territory[.codeset]][@modifier]
989
language[_territory][.codeset][@modifier]
709
990
The codeset part in the result is not reliable; the locale_charset()
710
991
should be used for codeset information instead.
711
992
The result must not be freed; it is statically allocated. */
714
_nl_locale_name_posix (int category, const char *categoryname)
995
gl_locale_name_posix (int category, const char *categoryname)
716
997
/* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
717
998
On some systems this can be done by the 'setlocale' function itself. */