19
* _cupsAppleLanguage() - Get the Apple language identifier associated
21
* _cupsEncodingName() - Return the character encoding name string
22
* for the given encoding enumeration.
19
* _cupsAppleLanguage() - Get the Apple language identifier associated with
21
* _cupsEncodingName() - Return the character encoding name string for the
22
* given encoding enumeration.
23
23
* cupsLangDefault() - Return the default language.
24
* cupsLangEncoding() - Return the character encoding (us-ascii, etc.)
25
* for the given language.
24
* cupsLangEncoding() - Return the character encoding (us-ascii, etc.) for
26
26
* cupsLangFlush() - Flush all language data out of the cache.
27
27
* cupsLangFree() - Free language data.
28
28
* cupsLangGet() - Get a language.
76
73
"iso-8859-8", "iso-8859-9",
77
74
"iso-8859-10", "utf-8",
78
75
"iso-8859-13", "iso-8859-14",
79
"iso-8859-15", "windows-874",
80
"windows-1250", "windows-1251",
81
"windows-1252", "windows-1253",
82
"windows-1254", "windows-1255",
83
"windows-1256", "windows-1257",
84
"windows-1258", "koi8-r",
76
"iso-8859-15", "cp874",
85
82
"koi8-u", "iso-8859-11",
86
83
"iso-8859-16", "mac-roman",
87
84
"unknown", "unknown",
159
156
* Local functions...
163
161
static const char *appleLangDefault(void);
162
# ifdef CUPS_BUNDLEDIR
163
# ifndef CF_RETURNS_RETAINED
164
# if __has_feature(attribute_cf_returns_retained)
165
# define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
167
# define CF_RETURNS_RETAINED
168
# endif /* __has_feature(attribute_cf_returns_retained) */
169
# endif /* !CF_RETURNED_RETAINED */
170
static cups_array_t *appleMessageLoad(const char *locale)
172
# endif /* CUPS_BUNDLEDIR */
164
173
#endif /* __APPLE__ */
165
174
static cups_lang_t *cups_cache_lookup(const char *name,
166
175
cups_encoding_t encoding);
167
176
static int cups_message_compare(_cups_message_t *m1,
168
177
_cups_message_t *m2);
178
static void cups_message_free(_cups_message_t *m);
169
179
static void cups_unquote(char *d, const char *s);
174
* _cupsAppleLanguage() - Get the Apple language identifier associated
184
* '_cupsAppleLanguage()' - Get the Apple language identifier associated with a
178
188
const char * /* O - Language ID */
388
390
charset[16], /* Character set */
389
391
*csptr, /* Pointer to CODESET string */
390
392
*ptr, /* Pointer into language/charset */
391
real[48], /* Real language name */
392
filename[1024]; /* Filename for language locale file */
393
real[48]; /* Real language name */
393
394
cups_encoding_t encoding; /* Encoding to use */
394
395
cups_lang_t *lang; /* Current language... */
396
#if !defined(__APPLE__) || !defined(CUPS_BUNDLEDIR)
397
char filename[1024]; /* Filename for language locale file */
395
398
_cups_globals_t *cg = _cupsGlobals();
396
399
/* Pointer to library globals */
400
#endif /* !__APPLE__ || !CUPS_BUNDLEDIR */
397
401
static const char * const locale_encodings[] =
398
402
{ /* Locale charset names */
399
403
"ASCII", "ISO88591", "ISO88592", "ISO88593",
676
680
* Map alternate names for various character sets...
679
if (!strcasecmp(charset, "iso-2022-jp") ||
680
!strcasecmp(charset, "sjis"))
683
if (!_cups_strcasecmp(charset, "iso-2022-jp") ||
684
!_cups_strcasecmp(charset, "sjis"))
681
685
encoding = CUPS_WINDOWS_932;
682
else if (!strcasecmp(charset, "iso-2022-cn"))
686
else if (!_cups_strcasecmp(charset, "iso-2022-cn"))
683
687
encoding = CUPS_WINDOWS_936;
684
else if (!strcasecmp(charset, "iso-2022-kr"))
688
else if (!_cups_strcasecmp(charset, "iso-2022-kr"))
685
689
encoding = CUPS_WINDOWS_949;
686
else if (!strcasecmp(charset, "big5"))
690
else if (!_cups_strcasecmp(charset, "big5"))
687
691
encoding = CUPS_WINDOWS_950;
701
705
snprintf(real, sizeof(real), "%s_%s", langname, country);
707
#if !defined(__APPLE__) || !defined(CUPS_BUNDLEDIR)
703
708
snprintf(filename, sizeof(filename), "%s/%s/cups_%s.po", cg->localedir,
710
#endif /* !__APPLE__ || !CUPS_BUNDLEDIR */
708
714
strcpy(real, langname);
715
#if !defined(__APPLE__) || !defined(CUPS_BUNDLEDIR)
709
716
filename[0] = '\0'; /* anti-compiler-warning-code */
717
#endif /* !__APPLE__ || !CUPS_BUNDLEDIR */
712
#ifdef HAVE_PTHREAD_H
713
pthread_mutex_lock(&lang_mutex);
714
#endif /* HAVE_PTHREAD_H */
720
_cupsMutexLock(&lang_mutex);
716
722
if ((lang = cups_cache_lookup(real, encoding)) != NULL)
718
#ifdef HAVE_PTHREAD_H
719
pthread_mutex_unlock(&lang_mutex);
720
#endif /* HAVE_PTHREAD_H */
724
_cupsMutexUnlock(&lang_mutex);
722
726
DEBUG_printf(("3cupsLangGet: Using cached copy of \"%s\"...", real));
731
#if !defined(__APPLE__) || !defined(CUPS_BUNDLEDIR)
727
732
if (!country[0] || access(filename, 0))
1102
1092
key.id = (char *)m;
1103
1093
match = (_cups_message_t *)cupsArrayFind(a, &key);
1095
#if defined(__APPLE__) && defined(CUPS_BUNDLEDIR)
1096
if (!match && cupsArrayUserData(a))
1099
* Try looking the string up in the cups.strings dictionary...
1102
CFDictionaryRef dict; /* cups.strings dictionary */
1103
CFStringRef cfm, /* Message as a CF string */
1104
cfstr; /* Localized text as a CF string */
1106
dict = (CFDictionaryRef)cupsArrayUserData(a);
1107
cfm = CFStringCreateWithCString(kCFAllocatorDefault, m,
1108
kCFStringEncodingUTF8);
1109
match = calloc(1, sizeof(_cups_message_t));
1110
match->id = strdup(m);
1111
cfstr = cfm ? CFDictionaryGetValue(dict, cfm) : NULL;
1115
char buffer[1024]; /* Message buffer */
1117
CFStringGetCString(cfstr, buffer, sizeof(buffer), kCFStringEncodingUTF8);
1118
match->str = strdup(buffer);
1120
DEBUG_printf(("1_cupsMessageLookup: Found \"%s\" as \"%s\"...",
1125
match->str = strdup(m);
1127
DEBUG_printf(("1_cupsMessageLookup: Did not find \"%s\"...", m));
1130
cupsArrayAdd(a, match);
1135
#endif /* __APPLE__ && CUPS_BUNDLEDIR */
1105
1137
if (match && match->str)
1106
1138
return (match->str);
1227
1259
return (cg->language);
1263
# ifdef CUPS_BUNDLEDIR
1265
* 'appleMessageLoad()' - Load a message catalog from a localizable bundle.
1268
static cups_array_t * /* O - Message catalog */
1269
appleMessageLoad(const char *locale) /* I - Locale ID */
1271
char filename[1024], /* Path to cups.strings file */
1272
applelang[256]; /* Apple language ID */
1273
CFURLRef url; /* URL to cups.strings file */
1274
CFReadStreamRef stream = NULL; /* File stream */
1275
CFPropertyListRef plist = NULL; /* Localization file */
1277
CFErrorRef error = NULL; /* Error when opening file */
1281
DEBUG_printf(("appleMessageLoad(locale=\"%s\")", locale));
1284
* Load the cups.strings file...
1287
snprintf(filename, sizeof(filename),
1288
CUPS_BUNDLEDIR "/Resources/%s.lproj/cups.strings",
1289
_cupsAppleLanguage(locale, applelang, sizeof(applelang)));
1290
DEBUG_printf(("1appleMessageLoad: filename=\"%s\"", filename));
1292
if (access(filename, 0))
1295
* Try alternate lproj directory names...
1298
if (!strncmp(locale, "en", 2))
1300
else if (!strncmp(locale, "nb", 2) || !strncmp(locale, "nl", 2))
1302
else if (!strncmp(locale, "fr", 2))
1304
else if (!strncmp(locale, "de", 2))
1306
else if (!strncmp(locale, "it", 2))
1308
else if (!strncmp(locale, "ja", 2))
1309
locale = "Japanese";
1310
else if (!strncmp(locale, "es", 2))
1313
snprintf(filename, sizeof(filename),
1314
CUPS_BUNDLEDIR "/Resources/%s.lproj/cups.strings", locale);
1315
DEBUG_printf(("1appleMessageLoad: alternate filename=\"%s\"", filename));
1318
url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
1320
strlen(filename), false);
1323
stream = CFReadStreamCreateWithFile(kCFAllocatorDefault, url);
1327
* Read the property list containing the localization data.
1329
* NOTE: This code currently generates a clang "potential leak"
1330
* warning, but the object is released in _cupsMessageFree().
1333
CFReadStreamOpen(stream);
1336
plist = CFPropertyListCreateWithStream(kCFAllocatorDefault, stream, 0,
1337
kCFPropertyListImmutable, NULL,
1341
CFStringRef msg = CFErrorCopyDescription(error);
1344
CFStringGetCString(msg, filename, sizeof(filename),
1345
kCFStringEncodingUTF8);
1346
DEBUG_printf(("1appleMessageLoad: %s", filename));
1353
plist = CFPropertyListCreateWithStream(kCFAllocatorDefault, stream, 0,
1354
kCFPropertyListImmutable, NULL,
1358
if (plist && CFGetTypeID(plist) != CFDictionaryGetTypeID())
1370
DEBUG_printf(("1appleMessageLoad: url=%p, stream=%p, plist=%p", url, stream,
1374
* Create and return an empty array to act as a cache for messages, passing the
1375
* plist as the user data.
1378
return (cupsArrayNew3((cups_array_func_t)cups_message_compare, (void *)plist,
1379
(cups_ahash_func_t)NULL, 0,
1380
(cups_acopy_func_t)NULL,
1381
(cups_afree_func_t)cups_message_free));
1383
# endif /* CUPS_BUNDLEDIR */
1229
1384
#endif /* __APPLE__ */