+
+
+# ifdef CUPS_BUNDLEDIR
+/*
+ * 'appleMessageLoad()' - Load a message catalog from a localizable bundle.
+ */
+
+static cups_array_t * /* O - Message catalog */
+appleMessageLoad(const char *locale) /* I - Locale ID */
+{
+ char filename[1024], /* Path to cups.strings file */
+ applelang[256]; /* Apple language ID */
+ CFURLRef url; /* URL to cups.strings file */
+ CFReadStreamRef stream = NULL; /* File stream */
+ CFPropertyListRef plist = NULL; /* Localization file */
+#ifdef DEBUG
+ CFErrorRef error = NULL; /* Error when opening file */
+#endif /* DEBUG */
+
+
+ DEBUG_printf(("appleMessageLoad(locale=\"%s\")", locale));
+
+ /*
+ * Load the cups.strings file...
+ */
+
+ snprintf(filename, sizeof(filename),
+ CUPS_BUNDLEDIR "/Resources/%s.lproj/cups.strings",
+ _cupsAppleLanguage(locale, applelang, sizeof(applelang)));
+ DEBUG_printf(("1appleMessageLoad: filename=\"%s\"", filename));
+
+ if (access(filename, 0))
+ {
+ /*
+ * Try alternate lproj directory names...
+ */
+
+ if (!strncmp(locale, "en", 2))
+ locale = "English";
+ else if (!strncmp(locale, "nb", 2) || !strncmp(locale, "nl", 2))
+ locale = "Dutch";
+ else if (!strncmp(locale, "fr", 2))
+ locale = "French";
+ else if (!strncmp(locale, "de", 2))
+ locale = "German";
+ else if (!strncmp(locale, "it", 2))
+ locale = "Italian";
+ else if (!strncmp(locale, "ja", 2))
+ locale = "Japanese";
+ else if (!strncmp(locale, "es", 2))
+ locale = "Spanish";
+
+ snprintf(filename, sizeof(filename),
+ CUPS_BUNDLEDIR "/Resources/%s.lproj/cups.strings", locale);
+ DEBUG_printf(("1appleMessageLoad: alternate filename=\"%s\"", filename));
+ }
+
+ url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
+ (UInt8 *)filename,
+ (CFIndex)strlen(filename), false);
+ if (url)
+ {
+ stream = CFReadStreamCreateWithFile(kCFAllocatorDefault, url);
+ if (stream)
+ {
+ /*
+ * Read the property list containing the localization data.
+ *
+ * NOTE: This code currently generates a clang "potential leak"
+ * warning, but the object is released in _cupsMessageFree().
+ */
+
+ CFReadStreamOpen(stream);
+
+#ifdef DEBUG
+ plist = CFPropertyListCreateWithStream(kCFAllocatorDefault, stream, 0,
+ kCFPropertyListImmutable, NULL,
+ &error);
+ if (error)
+ {
+ CFStringRef msg = CFErrorCopyDescription(error);
+ /* Error message */
+
+ CFStringGetCString(msg, filename, sizeof(filename),
+ kCFStringEncodingUTF8);
+ DEBUG_printf(("1appleMessageLoad: %s", filename));
+
+ CFRelease(msg);
+ CFRelease(error);
+ }
+
+#else
+ plist = CFPropertyListCreateWithStream(kCFAllocatorDefault, stream, 0,
+ kCFPropertyListImmutable, NULL,
+ NULL);
+#endif /* DEBUG */
+
+ if (plist && CFGetTypeID(plist) != CFDictionaryGetTypeID())
+ {
+ CFRelease(plist);
+ plist = NULL;
+ }
+
+ CFRelease(stream);
+ }
+
+ CFRelease(url);
+ }
+
+ DEBUG_printf(("1appleMessageLoad: url=%p, stream=%p, plist=%p", url, stream,
+ plist));
+
+ /*
+ * Create and return an empty array to act as a cache for messages, passing the
+ * plist as the user data.
+ */
+
+ return (_cupsMessageNew((void *)plist));
+}
+# endif /* CUPS_BUNDLEDIR */