2 * "$Id: language.c 5769 2006-07-20 17:17:14Z mike $"
4 * I18N/language support for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * _cupsEncodingName() - Return the character encoding name string
29 * for the given encoding enumeration.
30 * cupsLangDefault() - Return the default language.
31 * cupsLangEncoding() - Return the character encoding (us-ascii, etc.)
32 * for the given language.
33 * cupsLangFlush() - Flush all language data out of the cache.
34 * cupsLangFree() - Free language data.
35 * cupsLangGet() - Get a language.
36 * _cupsLangString() - Get a message string.
37 * _cupsMessageFree() - Free a messages array.
38 * _cupsMessageLoad() - Load a .po file into a messages array.
39 * _cupsMessageLookup() - Lookup a message string.
40 * appleLangDefault() - Get the default locale string.
41 * cups_cache_lookup() - Lookup a language in the cache...
42 * cups_message_compare() - Compare two messages.
43 * cups_unquote() - Unquote characters in strings...
47 * Include necessary headers...
54 #ifdef HAVE_LANGINFO_H
55 # include <langinfo.h>
56 #endif /* HAVE_LANGINFO_H */
62 #ifdef HAVE_COREFOUNDATION_H
63 # include <CoreFoundation/CoreFoundation.h>
64 #endif /* HAVE_COREFOUNDATION_H */
72 static pthread_mutex_t lang_mutex
= PTHREAD_MUTEX_INITIALIZER
;
73 /* Mutex to control access to cache */
74 #endif /* HAVE_PTHREAD_H */
75 static cups_lang_t
*lang_cache
= NULL
;
76 /* Language string cache */
84 static const char *appleLangDefault(void);
85 #endif /* __APPLE__ */
86 static cups_lang_t
*cups_cache_lookup(const char *name
,
87 cups_encoding_t encoding
);
88 static int cups_message_compare(_cups_message_t
*m1
,
90 static void cups_unquote(char *d
, const char *s
);
97 static const char * const lang_encodings
[] =
98 { /* Encoding strings */
99 "us-ascii", "iso-8859-1",
100 "iso-8859-2", "iso-8859-3",
101 "iso-8859-4", "iso-8859-5",
102 "iso-8859-6", "iso-8859-7",
103 "iso-8859-8", "iso-8859-9",
104 "iso-8859-10", "utf-8",
105 "iso-8859-13", "iso-8859-14",
106 "iso-8859-15", "windows-874",
107 "windows-1250", "windows-1251",
108 "windows-1252", "windows-1253",
109 "windows-1254", "windows-1255",
110 "windows-1256", "windows-1257",
111 "windows-1258", "koi8-r",
112 "koi8-u", "iso-8859-11",
113 "iso-8859-16", "mac-roman",
114 "unknown", "unknown",
115 "unknown", "unknown",
116 "unknown", "unknown",
117 "unknown", "unknown",
118 "unknown", "unknown",
119 "unknown", "unknown",
120 "unknown", "unknown",
121 "unknown", "unknown",
122 "unknown", "unknown",
123 "unknown", "unknown",
124 "unknown", "unknown",
125 "unknown", "unknown",
126 "unknown", "unknown",
127 "unknown", "unknown",
128 "unknown", "unknown",
129 "unknown", "unknown",
130 "unknown", "unknown",
131 "windows-932", "windows-936",
132 "windows-949", "windows-950",
133 "windows-1361", "unknown",
134 "unknown", "unknown",
135 "unknown", "unknown",
136 "unknown", "unknown",
137 "unknown", "unknown",
138 "unknown", "unknown",
139 "unknown", "unknown",
140 "unknown", "unknown",
141 "unknown", "unknown",
142 "unknown", "unknown",
143 "unknown", "unknown",
144 "unknown", "unknown",
145 "unknown", "unknown",
146 "unknown", "unknown",
147 "unknown", "unknown",
148 "unknown", "unknown",
149 "unknown", "unknown",
150 "unknown", "unknown",
151 "unknown", "unknown",
152 "unknown", "unknown",
153 "unknown", "unknown",
154 "unknown", "unknown",
155 "unknown", "unknown",
156 "unknown", "unknown",
157 "unknown", "unknown",
158 "unknown", "unknown",
159 "unknown", "unknown",
160 "unknown", "unknown",
161 "unknown", "unknown",
162 "unknown", "unknown",
169 * '_cupsEncodingName()' - Return the character encoding name string
170 * for the given encoding enumeration.
173 const char * /* O - Character encoding */
175 cups_encoding_t encoding
) /* I - Encoding value */
178 encoding
>= (sizeof(lang_encodings
) / sizeof(const char *)))
179 return (lang_encodings
[0]);
181 return (lang_encodings
[encoding
]);
186 * 'cupsLangDefault()' - Return the default language.
189 cups_lang_t
* /* O - Language data */
190 cupsLangDefault(void)
192 return (cupsLangGet(NULL
));
197 * 'cupsLangEncoding()' - Return the character encoding (us-ascii, etc.)
198 * for the given language.
201 const char * /* O - Character encoding */
202 cupsLangEncoding(cups_lang_t
*lang
) /* I - Language data */
205 return ((char*)lang_encodings
[0]);
207 return ((char*)lang_encodings
[lang
->encoding
]);
212 * 'cupsLangFlush()' - Flush all language data out of the cache.
218 cups_lang_t
*lang
, /* Current language */
219 *next
; /* Next language */
223 * Free all languages in the cache...
226 #ifdef HAVE_PTHREAD_H
227 pthread_mutex_lock(&lang_mutex
);
228 #endif /* HAVE_PTHREAD_H */
230 for (lang
= lang_cache
; lang
!= NULL
; lang
= next
)
233 * Free all messages...
236 _cupsMessageFree(lang
->strings
);
239 * Then free the language structure itself...
248 #ifdef HAVE_PTHREAD_H
249 pthread_mutex_unlock(&lang_mutex
);
250 #endif /* HAVE_PTHREAD_H */
255 * 'cupsLangFree()' - Free language data.
257 * This does not actually free anything; use cupsLangFlush() for that.
261 cupsLangFree(cups_lang_t
*lang
) /* I - Language to free */
263 #ifdef HAVE_PTHREAD_H
264 pthread_mutex_lock(&lang_mutex
);
265 #endif /* HAVE_PTHREAD_H */
267 if (lang
!= NULL
&& lang
->used
> 0)
270 #ifdef HAVE_PTHREAD_H
271 pthread_mutex_unlock(&lang_mutex
);
272 #endif /* HAVE_PTHREAD_H */
277 * 'cupsLangGet()' - Get a language.
280 cups_lang_t
* /* O - Language data */
281 cupsLangGet(const char *language
) /* I - Language or locale */
283 int i
; /* Looping var */
285 char locale
[255]; /* Copy of locale name */
286 #endif /* !__APPLE__ */
287 char langname
[16], /* Requested language name */
288 country
[16], /* Country code */
289 charset
[16], /* Character set */
290 *csptr
, /* Pointer to CODESET string */
291 *ptr
, /* Pointer into language/charset */
292 real
[48], /* Real language name */
293 filename
[1024]; /* Filename for language locale file */
294 cups_encoding_t encoding
; /* Encoding to use */
295 cups_lang_t
*lang
; /* Current language... */
296 _cups_globals_t
*cg
= _cupsGlobals();
297 /* Pointer to library globals */
298 static const char * const locale_encodings
[] =
299 { /* Locale charset names */
300 "ASCII", "ISO88591", "ISO88592", "ISO88593",
301 "ISO88594", "ISO88595", "ISO88596", "ISO88597",
302 "ISO88598", "ISO88599", "ISO885910", "UTF8",
303 "ISO885913", "ISO885914", "ISO885915", "CP874",
304 "CP1250", "CP1251", "CP1252", "CP1253",
305 "CP1254", "CP1255", "CP1256", "CP1257",
306 "CP1258", "KOI8R", "KOI8U", "ISO885911",
307 "ISO885916", "MACROMAN", "", "",
318 "CP932", "CP936", "CP949", "CP950",
319 "CP1361", "", "", "",
336 "EUCCN", "EUCJP", "EUCKR", "EUCTW"
340 DEBUG_printf(("cupsLangGet(language=\"%s\")\n", language
? language
: "(null)"));
344 * Set the character set to UTF-8...
347 strcpy(charset
, "UTF8");
350 * Apple's setlocale doesn't give us the user's localization
351 * preference so we have to look it up this way...
355 language
= appleLangDefault();
359 * Set the charset to "unknown"...
365 * Use setlocale() to determine the currently set locale, and then
366 * fallback to environment variables to avoid setting the locale,
367 * since setlocale() is not thread-safe!
373 * First see if the locale has been set; if it is still "C" or
374 * "POSIX", use the environment to get the default...
378 ptr
= setlocale(LC_MESSAGES
, NULL
);
380 ptr
= setlocale(LC_ALL
, NULL
);
381 # endif /* LC_MESSAGES */
383 DEBUG_printf(("cupsLangGet: current locale is \"%s\"\n",
384 ptr
? ptr
: "(null)"));
386 if (!ptr
|| !strcmp(ptr
, "C") || !strcmp(ptr
, "POSIX"))
389 * Get the character set from the LC_CTYPE locale setting...
392 if ((ptr
= getenv("LC_CTYPE")) == NULL
)
393 if ((ptr
= getenv("LC_ALL")) == NULL
)
394 if ((ptr
= getenv("LANG")) == NULL
)
397 if ((csptr
= strchr(ptr
, '.')) != NULL
)
400 * Extract the character set from the environment...
403 for (ptr
= charset
, csptr
++; *csptr
; csptr
++)
404 if (ptr
< (charset
+ sizeof(charset
) - 1) && isalnum(*csptr
& 255))
412 * Default to UTF-8...
415 strcpy(charset
, "UTF8");
419 * Get the locale for messages from the LC_MESSAGES locale setting...
422 if ((ptr
= getenv("LC_MESSAGES")) == NULL
)
423 if ((ptr
= getenv("LC_ALL")) == NULL
)
424 if ((ptr
= getenv("LANG")) == NULL
)
430 strlcpy(locale
, ptr
, sizeof(locale
));
433 DEBUG_printf(("cupsLangGet: new language value is \"%s\"\n",
434 language
? language
: "(null)"));
437 #endif /* __APPLE__ */
440 * If "language" is NULL at this point, then chances are we are using
441 * a language that is not installed for the base OS.
447 * Switch to the POSIX ("C") locale...
455 * On systems that support the nl_langinfo(CODESET) call, use
456 * this value as the character set...
459 if (!charset
[0] && (csptr
= nl_langinfo(CODESET
)) != NULL
)
462 * Copy all of the letters and numbers in the CODESET string...
465 for (ptr
= charset
; *csptr
; csptr
++)
466 if (isalnum(*csptr
& 255) && ptr
< (charset
+ sizeof(charset
) - 1))
471 DEBUG_printf(("cupsLangGet: charset set to \"%s\" via nl_langinfo(CODESET)...\n",
477 * Parse the language string passed in to a locale string. "C" is the
478 * standard POSIX locale and is copied unchanged. Otherwise the
479 * language string is converted from ll-cc[.charset] (language-country)
480 * to ll_CC[.CHARSET] to match the file naming convention used by all
481 * POSIX-compliant operating systems. Invalid language names are mapped
482 * to the POSIX locale.
487 if (language
== NULL
|| !language
[0] ||
488 !strcmp(language
, "POSIX"))
489 strcpy(langname
, "C");
493 * Copy the parts of the locale string over safely...
496 for (ptr
= langname
; *language
; language
++)
497 if (*language
== '_' || *language
== '-' || *language
== '.')
499 else if (ptr
< (langname
+ sizeof(langname
) - 1))
500 *ptr
++ = tolower(*language
& 255);
504 if (*language
== '_' || *language
== '-')
507 * Copy the country code...
510 for (language
++, ptr
= country
; *language
; language
++)
511 if (*language
== '.')
513 else if (ptr
< (country
+ sizeof(country
) - 1))
514 *ptr
++ = toupper(*language
& 255);
519 if (*language
== '.' && !charset
[0])
522 * Copy the encoding...
525 for (language
++, ptr
= charset
; *language
; language
++)
526 if (isalnum(*language
& 255) && ptr
< (charset
+ sizeof(charset
) - 1))
527 *ptr
++ = toupper(*language
& 255);
533 * Force a POSIX locale for an invalid language name...
536 if (strlen(langname
) != 2)
538 strcpy(langname
, "C");
544 DEBUG_printf(("cupsLangGet: langname=\"%s\", country=\"%s\", charset=\"%s\"\n",
545 langname
, country
, charset
));
548 * Figure out the desired encoding...
551 encoding
= CUPS_AUTO_ENCODING
;
556 i
< (int)(sizeof(locale_encodings
) / sizeof(locale_encodings
[0]));
558 if (!strcasecmp(charset
, locale_encodings
[i
]))
560 encoding
= (cups_encoding_t
)i
;
564 if (encoding
== CUPS_AUTO_ENCODING
)
567 * Map alternate names for various character sets...
570 if (!strcasecmp(charset
, "iso-2022-jp") ||
571 !strcasecmp(charset
, "sjis"))
572 encoding
= CUPS_WINDOWS_932
;
573 else if (!strcasecmp(charset
, "iso-2022-cn"))
574 encoding
= CUPS_WINDOWS_936
;
575 else if (!strcasecmp(charset
, "iso-2022-kr"))
576 encoding
= CUPS_WINDOWS_949
;
577 else if (!strcasecmp(charset
, "big5"))
578 encoding
= CUPS_WINDOWS_950
;
582 DEBUG_printf(("cupsLangGet: encoding=%d(%s)\n", encoding
,
583 encoding
== CUPS_AUTO_ENCODING
? "auto" :
584 lang_encodings
[encoding
]));
587 * See if we already have this language/country loaded...
592 snprintf(real
, sizeof(real
), "%s_%s", langname
, country
);
594 snprintf(filename
, sizeof(filename
), "%s/%s/cups_%s.po", cg
->localedir
,
599 strcpy(real
, langname
);
600 filename
[0] = '\0'; /* anti-compiler-warning-code */
603 #ifdef HAVE_PTHREAD_H
604 pthread_mutex_lock(&lang_mutex
);
605 #endif /* HAVE_PTHREAD_H */
607 if ((lang
= cups_cache_lookup(langname
, encoding
)) != NULL
)
609 #ifdef HAVE_PTHREAD_H
610 pthread_mutex_unlock(&lang_mutex
);
611 #endif /* HAVE_PTHREAD_H */
616 if (!country
[0] || access(filename
, 0))
619 * Country localization not available, look for generic localization...
622 snprintf(filename
, sizeof(filename
), "%s/%s/cups_%s.po", cg
->localedir
,
625 if (access(filename
, 0))
628 * No generic localization, so use POSIX...
631 DEBUG_printf(("access(\"%s\", 0): %s\n", filename
, strerror(errno
)));
633 snprintf(filename
, sizeof(filename
), "%s/C/cups_C.po", cg
->localedir
);
638 * See if there is a free language available; if so, use that
642 for (lang
= lang_cache
; lang
!= NULL
; lang
= lang
->next
)
649 * Allocate memory for the language and add it to the cache.
652 if ((lang
= calloc(sizeof(cups_lang_t
), 1)) == NULL
)
654 #ifdef HAVE_PTHREAD_H
655 pthread_mutex_unlock(&lang_mutex
);
656 #endif /* HAVE_PTHREAD_H */
661 lang
->next
= lang_cache
;
667 * Free all old strings as needed...
670 _cupsMessageFree(lang
->strings
);
674 * Then assign the language and encoding fields...
678 strlcpy(lang
->language
, real
, sizeof(lang
->language
));
680 if (encoding
!= CUPS_AUTO_ENCODING
)
681 lang
->encoding
= encoding
;
683 lang
->encoding
= CUPS_UTF8
;
686 * Read the strings from the file...
689 lang
->strings
= _cupsMessageLoad(filename
);
695 #ifdef HAVE_PTHREAD_H
696 pthread_mutex_unlock(&lang_mutex
);
697 #endif /* HAVE_PTHREAD_H */
704 * '_cupsLangString()' - Get a message string.
706 * The returned string is UTF-8 encoded; use cupsUTF8ToCharset() to
707 * convert the string to the language encoding.
710 const char * /* O - Localized message */
711 _cupsLangString(cups_lang_t
*lang
, /* I - Language */
712 const char *message
) /* I - Message */
715 * Range check input...
718 if (!lang
|| !message
)
721 #ifdef HAVE_PTHREAD_H
723 const char *s
; /* Localized message */
725 pthread_mutex_lock(&lang_mutex
);
727 s
= _cupsMessageLookup(lang
->strings
, message
);
729 pthread_mutex_unlock(&lang_mutex
);
734 return (_cupsMessageLookup(lang
->strings
, message
));
735 #endif /* HAVE_PTHREAD_H */
740 * '_cupsMessageFree()' - Free a messages array.
744 _cupsMessageFree(cups_array_t
*a
) /* I - Message array */
746 _cups_message_t
*m
; /* Current message */
749 for (m
= (_cups_message_t
*)cupsArrayFirst(a
);
751 m
= (_cups_message_t
*)cupsArrayNext(a
))
754 * Remove the message from the array, then free the message and strings.
757 cupsArrayRemove(a
, m
);
777 * '_cupsMessageLoad()' - Load a .po file into a messages array.
780 cups_array_t
* /* O - New message array */
781 _cupsMessageLoad(const char *filename
) /* I - Message catalog to load */
783 cups_file_t
*fp
; /* Message file */
784 cups_array_t
*a
; /* Message array */
785 _cups_message_t
*m
; /* Current message */
786 char s
[4096], /* String buffer */
787 *ptr
, /* Pointer into buffer */
788 *temp
; /* New string */
789 int length
; /* Length of combined strings */
792 DEBUG_printf(("_cupsMessageLoad(filename=\"%s\")\n", filename
));
795 * Create an array to hold the messages...
798 if ((a
= cupsArrayNew((cups_array_func_t
)cups_message_compare
, NULL
)) == NULL
)
802 * Open the message catalog file...
805 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
809 * Read messages from the catalog file until EOF...
811 * The format is the GNU gettext .po format, which is fairly simple:
814 * msgstr "localized text"
816 * The ID and localized text can span multiple lines using the form:
821 * "localized text spanning "
827 while (cupsFileGets(fp
, s
, sizeof(s
)) != NULL
)
830 * Skip blank and comment lines...
833 if (s
[0] == '#' || !s
[0])
837 * Strip the trailing quote...
840 if ((ptr
= strrchr(s
, '\"')) == NULL
)
846 * Find start of value...
849 if ((ptr
= strchr(s
, '\"')) == NULL
)
855 * Unquote the text...
858 cups_unquote(ptr
, ptr
);
861 * Create or add to a message...
864 if (!strncmp(s
, "msgid", 5))
867 * Add previous message as needed...
874 * Create a new message with the given msgid string...
877 if ((m
= (_cups_message_t
*)calloc(1, sizeof(_cups_message_t
))) == NULL
)
885 else if (s
[0] == '\"' && m
)
888 * Append to current string...
891 length
= strlen(m
->str
? m
->str
: m
->id
);
893 if ((temp
= realloc(m
->str
? m
->str
: m
->id
,
894 length
+ strlen(ptr
) + 1)) == NULL
)
903 * Copy the new portion to the end of the msgstr string - safe
904 * to use strcpy because the buffer is allocated to the correct
910 strcpy(m
->str
+ length
, ptr
);
915 * Copy the new portion to the end of the msgid string - safe
916 * to use strcpy because the buffer is allocated to the correct
922 strcpy(m
->id
+ length
, ptr
);
925 else if (!strncmp(s
, "msgstr", 6) && m
)
931 m
->str
= strdup(ptr
);
936 * Add the last message string to the array as needed...
943 * Close the message catalog file and return the new array...
953 * '_cupsMessageLookup()' - Lookup a message string.
956 const char * /* O - Localized message */
957 _cupsMessageLookup(cups_array_t
*a
, /* I - Message array */
958 const char *m
) /* I - Message */
960 _cups_message_t key
, /* Search key */
961 *match
; /* Matching message */
965 * Lookup the message string; if it doesn't exist in the catalog,
966 * then return the message that was passed to us...
970 match
= (_cups_message_t
*)cupsArrayFind(a
, &key
);
972 if (match
&& match
->str
)
981 * Code & data to translate OSX's language names to their ISO 639-1 locale.
983 * The first version uses the new CoreFoundation API added in 10.3 (Panther),
984 * the second is for 10.2 (Jaguar).
987 # ifdef HAVE_CF_LOCALE_ID
989 * 'appleLangDefault()' - Get the default locale string.
992 static const char * /* O - Locale string */
993 appleLangDefault(void)
995 CFPropertyListRef localizationList
;
996 /* List of localization data */
997 CFStringRef languageName
; /* Current name */
998 CFStringRef localeName
; /* Canonical from of name */
999 _cups_globals_t
*cg
= _cupsGlobals();
1000 /* Pointer to library globals */
1004 * Only do the lookup and translation the first time.
1007 if (!cg
->language
[0])
1010 CFPreferencesCopyAppValue(CFSTR("AppleLanguages"),
1011 kCFPreferencesCurrentApplication
);
1013 if (localizationList
!= NULL
)
1015 if (CFGetTypeID(localizationList
) == CFArrayGetTypeID() &&
1016 CFArrayGetCount(localizationList
) > 0)
1018 languageName
= CFArrayGetValueAtIndex(localizationList
, 0);
1020 if (languageName
!= NULL
&&
1021 CFGetTypeID(languageName
) == CFStringGetTypeID())
1023 localeName
= CFLocaleCreateCanonicalLocaleIdentifierFromString(
1024 kCFAllocatorDefault
, languageName
);
1026 if (localeName
!= NULL
)
1028 CFStringGetCString(localeName
, cg
->language
, sizeof(cg
->language
),
1029 kCFStringEncodingASCII
);
1030 CFRelease(localeName
);
1032 if (!strcmp(cg
->language
, "en"))
1033 strlcpy(cg
->language
, "en_US.UTF-8", sizeof(cg
->language
));
1034 else if (strchr(cg
->language
, '.') == NULL
)
1035 strlcat(cg
->language
, ".UTF-8", sizeof(cg
->language
));
1040 CFRelease(localizationList
);
1044 * If we didn't find the language, default to en_US...
1047 if (!cg
->language
[0])
1048 strlcpy(cg
->language
, "en_US.UTF-8", sizeof(cg
->language
));
1052 * Return the cached locale...
1055 return (cg
->language
);
1059 * Code & data to translate OSX 10.2's language names to their ISO 639-1
1065 const char * const name
; /* Language name */
1066 const char * const locale
; /* Locale name */
1067 } _apple_name_locale_t
;
1069 static const _apple_name_locale_t apple_name_locale
[] =
1071 { "English" , "en_US.UTF-8" }, { "French" , "fr.UTF-8" },
1072 { "German" , "de.UTF-8" }, { "Italian" , "it.UTF-8" },
1073 { "Dutch" , "nl.UTF-8" }, { "Swedish" , "sv.UTF-8" },
1074 { "Spanish" , "es.UTF-8" }, { "Danish" , "da.UTF-8" },
1075 { "Portuguese" , "pt.UTF-8" }, { "Norwegian" , "no.UTF-8" },
1076 { "Hebrew" , "he.UTF-8" }, { "Japanese" , "ja.UTF-8" },
1077 { "Arabic" , "ar.UTF-8" }, { "Finnish" , "fi.UTF-8" },
1078 { "Greek" , "el.UTF-8" }, { "Icelandic" , "is.UTF-8" },
1079 { "Maltese" , "mt.UTF-8" }, { "Turkish" , "tr.UTF-8" },
1080 { "Croatian" , "hr.UTF-8" }, { "Chinese" , "zh.UTF-8" },
1081 { "Urdu" , "ur.UTF-8" }, { "Hindi" , "hi.UTF-8" },
1082 { "Thai" , "th.UTF-8" }, { "Korean" , "ko.UTF-8" },
1083 { "Lithuanian" , "lt.UTF-8" }, { "Polish" , "pl.UTF-8" },
1084 { "Hungarian" , "hu.UTF-8" }, { "Estonian" , "et.UTF-8" },
1085 { "Latvian" , "lv.UTF-8" }, { "Sami" , "se.UTF-8" },
1086 { "Faroese" , "fo.UTF-8" }, { "Farsi" , "fa.UTF-8" },
1087 { "Russian" , "ru.UTF-8" }, { "Chinese" , "zh.UTF-8" },
1088 { "Dutch" , "nl.UTF-8" }, { "Irish" , "ga.UTF-8" },
1089 { "Albanian" , "sq.UTF-8" }, { "Romanian" , "ro.UTF-8" },
1090 { "Czech" , "cs.UTF-8" }, { "Slovak" , "sk.UTF-8" },
1091 { "Slovenian" , "sl.UTF-8" }, { "Yiddish" , "yi.UTF-8" },
1092 { "Serbian" , "sr.UTF-8" }, { "Macedonian" , "mk.UTF-8" },
1093 { "Bulgarian" , "bg.UTF-8" }, { "Ukrainian" , "uk.UTF-8" },
1094 { "Byelorussian", "be.UTF-8" }, { "Uzbek" , "uz.UTF-8" },
1095 { "Kazakh" , "kk.UTF-8" }, { "Azerbaijani", "az.UTF-8" },
1096 { "Azerbaijani" , "az.UTF-8" }, { "Armenian" , "hy.UTF-8" },
1097 { "Georgian" , "ka.UTF-8" }, { "Moldavian" , "mo.UTF-8" },
1098 { "Kirghiz" , "ky.UTF-8" }, { "Tajiki" , "tg.UTF-8" },
1099 { "Turkmen" , "tk.UTF-8" }, { "Mongolian" , "mn.UTF-8" },
1100 { "Mongolian" , "mn.UTF-8" }, { "Pashto" , "ps.UTF-8" },
1101 { "Kurdish" , "ku.UTF-8" }, { "Kashmiri" , "ks.UTF-8" },
1102 { "Sindhi" , "sd.UTF-8" }, { "Tibetan" , "bo.UTF-8" },
1103 { "Nepali" , "ne.UTF-8" }, { "Sanskrit" , "sa.UTF-8" },
1104 { "Marathi" , "mr.UTF-8" }, { "Bengali" , "bn.UTF-8" },
1105 { "Assamese" , "as.UTF-8" }, { "Gujarati" , "gu.UTF-8" },
1106 { "Punjabi" , "pa.UTF-8" }, { "Oriya" , "or.UTF-8" },
1107 { "Malayalam" , "ml.UTF-8" }, { "Kannada" , "kn.UTF-8" },
1108 { "Tamil" , "ta.UTF-8" }, { "Telugu" , "te.UTF-8" },
1109 { "Sinhalese" , "si.UTF-8" }, { "Burmese" , "my.UTF-8" },
1110 { "Khmer" , "km.UTF-8" }, { "Lao" , "lo.UTF-8" },
1111 { "Vietnamese" , "vi.UTF-8" }, { "Indonesian" , "id.UTF-8" },
1112 { "Tagalog" , "tl.UTF-8" }, { "Malay" , "ms.UTF-8" },
1113 { "Malay" , "ms.UTF-8" }, { "Amharic" , "am.UTF-8" },
1114 { "Tigrinya" , "ti.UTF-8" }, { "Oromo" , "om.UTF-8" },
1115 { "Somali" , "so.UTF-8" }, { "Swahili" , "sw.UTF-8" },
1116 { "Kinyarwanda" , "rw.UTF-8" }, { "Rundi" , "rn.UTF-8" },
1117 { "Nyanja" , "" }, { "Malagasy" , "mg.UTF-8" },
1118 { "Esperanto" , "eo.UTF-8" }, { "Welsh" , "cy.UTF-8" },
1119 { "Basque" , "eu.UTF-8" }, { "Catalan" , "ca.UTF-8" },
1120 { "Latin" , "la.UTF-8" }, { "Quechua" , "qu.UTF-8" },
1121 { "Guarani" , "gn.UTF-8" }, { "Aymara" , "ay.UTF-8" },
1122 { "Tatar" , "tt.UTF-8" }, { "Uighur" , "ug.UTF-8" },
1123 { "Dzongkha" , "dz.UTF-8" }, { "Javanese" , "jv.UTF-8" },
1124 { "Sundanese" , "su.UTF-8" }, { "Galician" , "gl.UTF-8" },
1125 { "Afrikaans" , "af.UTF-8" }, { "Breton" , "br.UTF-8" },
1126 { "Inuktitut" , "iu.UTF-8" }, { "Scottish" , "gd.UTF-8" },
1127 { "Manx" , "gv.UTF-8" }, { "Irish" , "ga.UTF-8" },
1128 { "Tongan" , "to.UTF-8" }, { "Greek" , "el.UTF-8" },
1129 { "Greenlandic" , "kl.UTF-8" }, { "Azerbaijani", "az.UTF-8" }
1134 * 'appleLangDefault()' - Get the default locale string.
1137 static const char * /* O - Locale string */
1138 appleLangDefault(void)
1140 int i
; /* Looping var */
1141 CFPropertyListRef localizationList
;
1142 /* List of localization data */
1143 CFStringRef localizationName
;
1145 char buff
[256]; /* Temporary buffer */
1146 _cups_globals_t
*cg
= _cupsGlobals();
1147 /* Pointer to library globals */
1151 * Only do the lookup and translation the first time.
1154 if (cg
->language
== NULL
)
1157 CFPreferencesCopyAppValue(CFSTR("AppleLanguages"),
1158 kCFPreferencesCurrentApplication
);
1160 if (localizationList
!= NULL
)
1162 if (CFGetTypeID(localizationList
) == CFArrayGetTypeID() &&
1163 CFArrayGetCount(localizationList
) > 0)
1165 localizationName
= CFArrayGetValueAtIndex(localizationList
, 0);
1167 if (localizationName
!= NULL
&&
1168 CFGetTypeID(localizationName
) == CFStringGetTypeID())
1170 CFIndex length
= CFStringGetLength(localizationName
);
1172 if (length
<= sizeof(buff
) &&
1173 CFStringGetCString(localizationName
, buff
, sizeof(buff
),
1174 kCFStringEncodingASCII
))
1176 buff
[sizeof(buff
) - 1] = '\0';
1179 i
< sizeof(apple_name_locale
) / sizeof(apple_name_locale
[0]);
1182 if (!strcasecmp(buff
, apple_name_locale
[i
].name
))
1184 cg
->language
= apple_name_locale
[i
].locale
;
1192 CFRelease(localizationList
);
1196 * If we didn't find the language, default to en_US...
1199 if (cg
->language
== NULL
)
1200 cg
->language
= apple_name_locale
[0].locale
;
1204 * Return the cached locale...
1207 return (cg
->language
);
1209 # endif /* HAVE_CF_LOCALE_ID */
1210 #endif /* __APPLE__ */
1214 * 'cups_cache_lookup()' - Lookup a language in the cache...
1217 static cups_lang_t
* /* O - Language data or NULL */
1218 cups_cache_lookup(const char *name
,/* I - Name of locale */
1219 cups_encoding_t encoding
)
1220 /* I - Encoding of locale */
1222 cups_lang_t
*lang
; /* Current language */
1225 DEBUG_printf(("cups_cache_lookup(name=\"%s\", encoding=%d(%s))\n", name
,
1226 encoding
, encoding
== CUPS_AUTO_ENCODING
? "auto" :
1227 lang_encodings
[encoding
]));
1230 * Loop through the cache and return a match if found...
1233 for (lang
= lang_cache
; lang
!= NULL
; lang
= lang
->next
)
1235 DEBUG_printf(("cups_cache_lookup: lang=%p, language=\"%s\", encoding=%d(%s)\n",
1236 lang
, lang
->language
, lang
->encoding
,
1237 lang_encodings
[lang
->encoding
]));
1239 if (!strcmp(lang
->language
, name
) &&
1240 (encoding
== CUPS_AUTO_ENCODING
|| encoding
== lang
->encoding
))
1244 DEBUG_puts("cups_cache_lookup: returning match!");
1250 DEBUG_puts("cups_cache_lookup: returning NULL!");
1257 * 'cups_message_compare()' - Compare two messages.
1260 static int /* O - Result of comparison */
1261 cups_message_compare(
1262 _cups_message_t
*m1
, /* I - First message */
1263 _cups_message_t
*m2
) /* I - Second message */
1265 return (strcmp(m1
->id
, m2
->id
));
1270 * 'cups_unquote()' - Unquote characters in strings...
1274 cups_unquote(char *d
, /* O - Unquoted string */
1275 const char *s
) /* I - Original string */
1288 *d
= *d
* 8 + *s
- '0';
1317 * End of "$Id: language.c 5769 2006-07-20 17:17:14Z mike $".