]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/dest-localization.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / cups / dest-localization.c
index 5439465d3697690df7a2a1d49a0693ac6b213a24..a35540b7286b047665fa16c75ce8d638cd59397f 100644 (file)
@@ -1,17 +1,9 @@
 /*
- * "$Id$"
- *
  * Destination localization support for CUPS.
  *
  * Copyright 2012-2014 by Apple Inc.
  *
- * These coded instructions, statements, and computer programs are the
- * 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.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
@@ -38,7 +30,7 @@ static char   *cups_scan_strings(char *buffer);
  * The returned string is stored in the destination information and will become
  * invalid if the destination information is deleted.
  *
- * @since CUPS 2.0/OS X 10.10@
+ * @since CUPS 2.0/macOS 10.10@
  */
 
 const char *                           /* O - Localized string */
@@ -62,12 +54,15 @@ cupsLocalizeDestMedia(
                        *ltype;         /* Localized media type */
 
 
+  DEBUG_printf(("cupsLocalizeDestMedia(http=%p, dest=%p, dinfo=%p, flags=%x, size=%p(\"%s\"))", (void *)http, (void *)dest, (void *)dinfo, flags, (void *)size, size ? size->media : "(null)"));
+
  /*
   * Range check input...
   */
 
   if (!http || !dest || !dinfo || !size)
   {
+    DEBUG_puts("1cupsLocalizeDestMedia: Returning NULL.");
     _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
     return (NULL);
   }
@@ -81,13 +76,24 @@ cupsLocalizeDestMedia(
 
   key.id = size->media;
   if ((match = (_cups_message_t *)cupsArrayFind(dinfo->localizations, &key)) != NULL)
+  {
+    DEBUG_printf(("1cupsLocalizeDestMedia: Returning \"%s\".", match->str));
     return (match->str);
+  }
 
  /*
   * If not, get the localized size, source, and type strings...
   */
 
   lang = cupsLangDefault();
+
+  snprintf(temp, sizeof(temp), "media.%s", size->media);
+  if ((lsize = _cupsLangString(lang, temp)) != NULL && strcmp(lsize, temp))
+  {
+    DEBUG_printf(("1cupsLocalizeDestMedia: Returning standard localization \"%s\".", lsize));
+    return (lsize);
+  }
+
   pwg  = pwgMediaForSize(size->width, size->length);
 
   if (pwg->ppd)
@@ -103,7 +109,7 @@ cupsLocalizeDestMedia(
       * Use inches since the size is a multiple of 1/4 inch.
       */
 
-      snprintf(temp, sizeof(temp), _cupsLangString(lang, _("%g x %g")), size->width / 2540.0, size->length / 2540.0);
+      snprintf(temp, sizeof(temp), _cupsLangString(lang, _("%g x %g \"")), size->width / 2540.0, size->length / 2540.0);
     }
     else
     {
@@ -191,6 +197,8 @@ cupsLocalizeDestMedia(
 
   cupsArrayAdd(dinfo->localizations, match);
 
+  DEBUG_printf(("1cupsLocalizeDestMedia: Returning \"%s\".", match->str));
+
   return (match->str);
 }
 
@@ -202,7 +210,7 @@ cupsLocalizeDestMedia(
  * The returned string is stored in the destination information and will become
  * invalid if the destination information is deleted.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 const char *                           /* O - Localized string */
@@ -214,7 +222,10 @@ cupsLocalizeDestOption(
 {
   _cups_message_t      key,            /* Search key */
                        *match;         /* Matching entry */
+  const char            *localized;     /* Localized string */
+
 
+  DEBUG_printf(("cupsLocalizeDestOption(http=%p, dest=%p, dinfo=%p, option=\"%s\")", (void *)http, (void *)dest, (void *)dinfo, option));
 
   if (!http || !dest || !dinfo)
     return (option);
@@ -222,13 +233,12 @@ cupsLocalizeDestOption(
   if (!dinfo->localizations)
     cups_create_localizations(http, dinfo);
 
-  if (cupsArrayCount(dinfo->localizations) == 0)
-    return (option);
-
   key.id = (char *)option;
   if ((match = (_cups_message_t *)cupsArrayFind(dinfo->localizations,
                                                 &key)) != NULL)
     return (match->str);
+  else if ((localized = _cupsLangString(cupsLangDefault(), option)) != NULL)
+    return (localized);
   else
     return (option);
 }
@@ -241,7 +251,7 @@ cupsLocalizeDestOption(
  * The returned string is stored in the destination information and will become
  * invalid if the destination information is deleted.
  *
- * @since CUPS 1.6/OS X 10.8@
+ * @since CUPS 1.6/macOS 10.8@
  */
 
 const char *                           /* O - Localized string */
@@ -255,22 +265,40 @@ cupsLocalizeDestValue(
   _cups_message_t      key,            /* Search key */
                        *match;         /* Matching entry */
   char                 pair[256];      /* option.value pair */
+  const char            *localized;     /* Localized string */
+
 
+  DEBUG_printf(("cupsLocalizeDestValue(http=%p, dest=%p, dinfo=%p, option=\"%s\", value=\"%s\")", (void *)http, (void *)dest, (void *)dinfo, option, value));
 
   if (!http || !dest || !dinfo)
     return (value);
 
+  if (!strcmp(option, "media"))
+  {
+    pwg_media_t *media = pwgMediaForPWG(value);
+    cups_size_t size;
+
+    strlcpy(size.media, value, sizeof(size.media));
+    size.width  = media ? media->width : 0;
+    size.length = media ? media->length : 0;
+    size.left   = 0;
+    size.right  = 0;
+    size.bottom = 0;
+    size.top    = 0;
+
+    return (cupsLocalizeDestMedia(http, dest, dinfo, CUPS_MEDIA_FLAGS_DEFAULT, &size));
+  }
+
   if (!dinfo->localizations)
     cups_create_localizations(http, dinfo);
 
-  if (cupsArrayCount(dinfo->localizations) == 0)
-    return (value);
-
   snprintf(pair, sizeof(pair), "%s.%s", option, value);
   key.id = pair;
   if ((match = (_cups_message_t *)cupsArrayFind(dinfo->localizations,
                                                 &key)) != NULL)
     return (match->str);
+  else if ((localized = _cupsLangString(cupsLangDefault(), pair)) != NULL && strcmp(localized, pair))
+    return (localized);
   else
     return (value);
 }
@@ -531,9 +559,3 @@ cups_scan_strings(char *buffer)             /* I - Start of string */
 
   return (bufptr);
 }
-
-
-
-/*
- * End of "$Id$".
- */