/*
- * "$Id: language.c 6407 2007-03-27 17:45:12Z mike $"
+ * "$Id: language.c 6916 2007-09-05 21:14:08Z mike $"
*
* I18N/language support for the Common UNIX Printing System (CUPS).
*
+ * Copyright 2007 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
- * property of Easy Software Products and are protected by Federal
- * copyright law. Distribution and use rights are outlined in the file
- * "LICENSE.txt" which should have been included with this file. If this
- * file is missing or damaged please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636 USA
- *
- * Voice: (301) 373-9600
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*
* preference so we have to look it up this way...
*/
- if (!language)
+ if (!language && (language = getenv("LANG")) == NULL)
language = appleLangDefault();
#else
*/
# ifdef HAVE_CF_LOCALE_ID
+
+typedef struct
+{
+ const char * const name; /* Language name */
+ const char * const locale; /* Locale name */
+} _apple_name_locale_t;
+
+static const _apple_name_locale_t apple_name_locale[] =
+{
+ { "en" , "en_US" },
+ { "nb" , "no" },
+ { "zh-Hans" , "zh_CN" },
+ { "zh-Hant" , "zh_TW" }
+};
+
+
/*
* 'appleLangDefault()' - Get the default locale string.
*/
static const char * /* O - Locale string */
appleLangDefault(void)
{
+ int i; /* Looping var */
+ CFBundleRef bundle; /* Main bundle (if any) */
+ CFArrayRef bundleList; /* List of localizations in bundle */
CFPropertyListRef localizationList;
/* List of localization data */
CFStringRef languageName; /* Current name */
if (!cg->language[0])
{
if ((lang = getenv("LANG")))
+ {
strlcpy(cg->language, lang, sizeof(cg->language));
- else
+ return (cg->language);
+ }
+ else if ((bundle = CFBundleGetMainBundle()) != NULL &&
+ (bundleList = CFBundleCopyBundleLocalizations(bundle)) != NULL)
{
localizationList =
- CFPreferencesCopyAppValue(CFSTR("AppleLanguages"),
- kCFPreferencesCurrentApplication);
+ CFBundleCopyPreferredLocalizationsFromArray(bundleList);
- if (localizationList != NULL)
+ CFRelease(bundleList);
+ }
+ else
+ localizationList =
+ CFPreferencesCopyAppValue(CFSTR("AppleLanguages"),
+ kCFPreferencesCurrentApplication);
+
+ if (localizationList)
+ {
+ if (CFGetTypeID(localizationList) == CFArrayGetTypeID() &&
+ CFArrayGetCount(localizationList) > 0)
{
- if (CFGetTypeID(localizationList) == CFArrayGetTypeID() &&
- CFArrayGetCount(localizationList) > 0)
+ languageName = CFArrayGetValueAtIndex(localizationList, 0);
+
+ if (languageName &&
+ CFGetTypeID(languageName) == CFStringGetTypeID())
{
- languageName = CFArrayGetValueAtIndex(localizationList, 0);
+ localeName = CFLocaleCreateCanonicalLocaleIdentifierFromString(
+ kCFAllocatorDefault, languageName);
+
+ if (localeName)
+ {
+ CFStringGetCString(localeName, cg->language, sizeof(cg->language),
+ kCFStringEncodingASCII);
+ CFRelease(localeName);
- if (languageName != NULL &&
- CFGetTypeID(languageName) == CFStringGetTypeID())
- {
- localeName = CFLocaleCreateCanonicalLocaleIdentifierFromString(
- kCFAllocatorDefault, languageName);
+ DEBUG_printf(("appleLangDefault: cg->language=\"%s\"\n",
+ cg->language));
- if (localeName != NULL)
+ /*
+ * Map new language identifiers to locales...
+ */
+
+ for (i = 0;
+ i < sizeof(apple_name_locale) / sizeof(apple_name_locale[0]);
+ i++)
{
- CFStringGetCString(localeName, cg->language, sizeof(cg->language),
- kCFStringEncodingASCII);
- CFRelease(localeName);
-
- if (!strcmp(cg->language, "en"))
- strlcpy(cg->language, "en_US.UTF-8", sizeof(cg->language));
- else if (strchr(cg->language, '.') == NULL)
- strlcat(cg->language, ".UTF-8", sizeof(cg->language));
+ if (!strcmp(cg->language, apple_name_locale[i].name))
+ {
+ DEBUG_printf(("appleLangDefault: mapping \"%s\" to \"%s\"...\n",
+ cg->language, apple_name_locale[i].locale));
+ strlcpy(cg->language, apple_name_locale[i].locale,
+ sizeof(cg->language));
+ break;
+ }
}
- }
- }
- CFRelease(localizationList);
+ /*
+ * Convert language subtag into region subtag...
+ */
+
+ if (cg->language[2] == '-')
+ cg->language[2] = '_';
+
+ if (!strchr(cg->language, '.'))
+ strlcat(cg->language, ".UTF-8", sizeof(cg->language));
+ }
+ }
}
+
+ CFRelease(localizationList);
}
/*
/*
- * End of "$Id: language.c 6407 2007-03-27 17:45:12Z mike $".
+ * End of "$Id: language.c 6916 2007-09-05 21:14:08Z mike $".
*/