]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/localize.c
Update svn:keyword properties.
[thirdparty/cups.git] / cups / localize.c
index 17453961c219df5d605ee8b0720d11b79773a9a6..13f44c018eea554a488c8f8e4aef6cd51e8a96bd 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id: localize.c 7363 2008-03-03 22:19:24Z mike $"
+ * "$Id$"
  *
- *   PPD localization routines for the Common UNIX Printing System (CUPS).
+ *   PPD localization routines for CUPS.
  *
- *   Copyright 2007-2008 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -26,6 +26,7 @@
  * Contents:
  *
  *   ppdLocalize()           - Localize the PPD file to the current locale.
+ *   ppdLocalizeAttr()       - Localize an attribute.
  *   ppdLocalizeIPPReason()  - Get the localized version of a cupsIPPReason
  *                             attribute.
  *   ppdLocalizeMarkerName() - Get the localized version of a marker-names
  * Include necessary headers.
  */
 
-#include "globals.h"
+#include "cups-private.h"
 #include "ppd-private.h"
-#include "debug.h"
 
 
 /*
  * Local functions...
  */
 
-static void            ppd_ll_CC(char *ll_CC, int ll_CC_size);
+static cups_lang_t     *ppd_ll_CC(char *ll_CC, int ll_CC_size);
 
 
 /*
@@ -61,7 +61,7 @@ static void           ppd_ll_CC(char *ll_CC, int ll_CC_size);
  * descriptions, printer presets, and custom option parameters.  Each
  * localized string uses the UTF-8 character encoding.
  *
- * @since CUPS 1.2@
+ * @since CUPS 1.2/OS X 10.5@
  */
 
 int                                    /* O - 0 on success, -1 on error */
@@ -83,7 +83,7 @@ ppdLocalize(ppd_file_t *ppd)          /* I - PPD file */
   * Range check input...
   */
 
-  DEBUG_printf(("ppdLocalize(ppd=%p)\n", ppd));
+  DEBUG_printf(("ppdLocalize(ppd=%p)", ppd));
 
   if (!ppd)
     return (-1);
@@ -114,7 +114,8 @@ ppdLocalize(ppd_file_t *ppd)                /* I - PPD file */
            k > 0;
           k --, choice ++)
       {
-        if (strcmp(choice->choice, "Custom"))
+        if (strcmp(choice->choice, "Custom") ||
+           !ppdFindCustomOption(ppd, option->keyword))
          locattr = _ppdLocalizedAttr(ppd, option->keyword, choice->choice,
                                      ll_CC);
        else
@@ -195,6 +196,45 @@ ppdLocalize(ppd_file_t *ppd)               /* I - PPD file */
 }
 
 
+/*
+ * 'ppdLocalizeAttr()' - Localize an attribute.
+ *
+ * This function uses the current locale to find the localized attribute for
+ * the given main and option keywords.  If no localized version of the
+ * attribute exists for the current locale, the unlocalized version is returned.
+ */
+
+ppd_attr_t *                           /* O - Localized attribute or @code NULL@ if none exists */
+ppdLocalizeAttr(ppd_file_t *ppd,       /* I - PPD file */
+               const char *keyword,    /* I - Main keyword */
+               const char *spec)       /* I - Option keyword or @code NULL@ for none */
+{
+  ppd_attr_t   *locattr;               /* Localized attribute */
+  char         ll_CC[6];               /* Language + country locale */
+
+
+ /*
+  * Get the default language...
+  */
+
+  ppd_ll_CC(ll_CC, sizeof(ll_CC));
+
+ /*
+  * Find the localized attribute...
+  */
+
+  if (spec)
+    locattr = _ppdLocalizedAttr(ppd, keyword, spec, ll_CC);
+  else
+    locattr = _ppdLocalizedAttr(ppd, "Translation", keyword, ll_CC);
+
+  if (!locattr)
+    locattr = ppdFindAttr(ppd, keyword, spec);
+
+  return (locattr);
+}
+
+
 /*
  * 'ppdLocalizeIPPReason()' - Get the localized version of a cupsIPPReason
  *                            attribute.
@@ -206,7 +246,7 @@ ppdLocalize(ppd_file_t *ppd)                /* I - PPD file */
  *
  * If no value of the requested scheme can be found, NULL is returned.
  *
- * @since CUPS 1.3@
+ * @since CUPS 1.3/OS X 10.5@
  */
 
 const char *                           /* O - Value or NULL if not found */
@@ -217,6 +257,7 @@ ppdLocalizeIPPReason(
     char       *buffer,                        /* I - Value buffer */
     size_t     bufsize)                        /* I - Size of value buffer */
 {
+  cups_lang_t  *lang;                  /* Current language */
   ppd_attr_t   *locattr;               /* Localized attribute */
   char         ll_CC[6],               /* Language + country locale */
                *bufptr,                /* Pointer into buffer */
@@ -241,7 +282,7 @@ ppdLocalizeIPPReason(
   * Get the default language...
   */
 
-  ppd_ll_CC(ll_CC, sizeof(ll_CC));
+  lang = ppd_ll_CC(ll_CC, sizeof(ll_CC));
 
  /*
   * Find the localized attribute...
@@ -252,7 +293,74 @@ ppdLocalizeIPPReason(
     locattr = ppdFindAttr(ppd, "cupsIPPReason", reason);
 
   if (!locattr)
+  {
+    if (lang && (!scheme || !strcmp(scheme, "text")))
+    {
+     /*
+      * Try to localize a standard printer-state-reason keyword...
+      */
+
+      const char *message = NULL;      /* Localized message */
+
+      if (!strncmp(reason, "media-needed", 12))
+       message = _("The paper tray needs to be filled.");
+      else if (!strncmp(reason, "media-jam", 9))
+       message = _("There is a paper jam.");
+      else if (!strncmp(reason, "offline", 7) ||
+                      !strncmp(reason, "shutdown", 8))
+       message = _("The printer is not connected.");
+      else if (!strncmp(reason, "toner-low", 9))
+       message = _("The printer is running low on toner.");
+      else if (!strncmp(reason, "toner-empty", 11))
+       message = _("The printer may be out of toner.");
+      else if (!strncmp(reason, "cover-open", 10))
+       message = _("The printer's cover is open.");
+      else if (!strncmp(reason, "interlock-open", 14))
+       message = _("The printer's interlock is open.");
+      else if (!strncmp(reason, "door-open", 9))
+       message = _("The printer's door is open.");
+      else if (!strncmp(reason, "input-tray-missing", 18))
+       message = _("The paper tray is missing.");
+      else if (!strncmp(reason, "media-low", 9))
+       message = _("The paper tray is almost empty.");
+      else if (!strncmp(reason, "media-empty", 11))
+       message = _("The paper tray is empty.");
+      else if (!strncmp(reason, "output-tray-missing", 19))
+       message = _("The output bin is missing.");
+      else if (!strncmp(reason, "output-area-almost-full", 23))
+       message = _("The output bin is almost full.");
+      else if (!strncmp(reason, "output-area-full", 16))
+       message = _("The output bin is full.");
+      else if (!strncmp(reason, "marker-supply-low", 17))
+       message = _("The printer is running low on ink.");
+      else if (!strncmp(reason, "marker-supply-empty", 19))
+       message = _("The printer may be out of ink.");
+      else if (!strncmp(reason, "marker-waste-almost-full", 24))
+       message = _("The printer's waste bin is almost full.");
+      else if (!strncmp(reason, "marker-waste-full", 17))
+       message = _("The printer's waste bin is full.");
+      else if (!strncmp(reason, "fuser-over-temp", 15))
+       message = _("The fuser's temperature is high.");
+      else if (!strncmp(reason, "fuser-under-temp", 16))
+       message = _("The fuser's temperature is low.");
+      else if (!strncmp(reason, "opc-near-eol", 12))
+       message = _("The optical photoconductor will need to be replaced soon.");
+      else if (!strncmp(reason, "opc-life-over", 13))
+       message = _("The optical photoconductor needs to be replaced.");
+      else if (!strncmp(reason, "developer-low", 13))
+       message = _("The developer unit will need to be replaced soon.");
+      else if (!strncmp(reason, "developer-empty", 15))
+       message = _("The developer unit needs to be replaced.");
+
+      if (message)
+      {
+        strlcpy(buffer, _cupsLangString(lang, message), bufsize);
+       return (buffer);
+      }
+    }
+
     return (NULL);
+  }
 
  /*
   * Now find the value we need...
@@ -277,12 +385,9 @@ ppdLocalizeIPPReason(
         * Decode text: URI and add to the buffer...
        */
 
-        if (bufptr > buffer)
-         *bufptr++ = ' ';              /* Add leading whitespace */
-
        valptr += 5;
 
-        while (*valptr && !isspace(*valptr & 255) && bufptr < bufend)
+        while (*valptr && !_cups_isspace(*valptr) && bufptr < bufend)
        {
          if (*valptr == '%' && isxdigit(valptr[1] & 255) &&
              isxdigit(valptr[2] & 255))
@@ -320,7 +425,7 @@ ppdLocalizeIPPReason(
         * Skip this URI...
        */
 
-        while (*valptr && !isspace(*valptr & 255))
+        while (*valptr && !_cups_isspace(*valptr))
           valptr++;
       }
 
@@ -328,7 +433,7 @@ ppdLocalizeIPPReason(
       * Skip whitespace...
       */
 
-      while (isspace(*valptr & 255))
+      while (_cups_isspace(*valptr))
        valptr ++;
     }
 
@@ -356,7 +461,7 @@ ppdLocalizeIPPReason(
         * Copy URI...
        */
 
-        while (*valptr && !isspace(*valptr & 255) && bufptr < bufend)
+        while (*valptr && !_cups_isspace(*valptr) && bufptr < bufend)
          *bufptr++ = *valptr++;
 
        *bufptr = '\0';
@@ -369,7 +474,7 @@ ppdLocalizeIPPReason(
         * Skip this URI...
        */
 
-       while (*valptr && !isspace(*valptr & 255))
+       while (*valptr && !_cups_isspace(*valptr))
          valptr++;
       }
 
@@ -377,7 +482,7 @@ ppdLocalizeIPPReason(
       * Skip whitespace...
       */
 
-      while (isspace(*valptr & 255))
+      while (_cups_isspace(*valptr))
        valptr ++;
     }
 
@@ -394,7 +499,7 @@ ppdLocalizeIPPReason(
  * text from the attribute value. If no localized text for the requested
  * name can be found, @code NULL@ is returned.
  *
- * @since CUPS 1.4@
+ * @since CUPS 1.4/OS X 10.6@
  */
 
 const char *                           /* O - Value or @code NULL@ if not found */
@@ -491,7 +596,7 @@ _ppdGetLanguages(ppd_file_t *ppd)   /* I - PPD file */
     * Skip leading whitespace...
     */
 
-    while (isspace(*ptr & 255))
+    while (_cups_isspace(*ptr))
       ptr ++;
 
     if (!*ptr)
@@ -501,7 +606,7 @@ _ppdGetLanguages(ppd_file_t *ppd)   /* I - PPD file */
     * Find the end of this language name...
     */
 
-    for (start = ptr; *ptr && !isspace(*ptr & 255); ptr ++);
+    for (start = ptr; *ptr && !_cups_isspace(*ptr); ptr ++);
 
     if (*ptr)
       *ptr++ = '\0';
@@ -532,7 +637,7 @@ _ppdGetLanguages(ppd_file_t *ppd)   /* I - PPD file */
 /*
  * '_ppdHashName()' - Generate a hash value for a device or profile name.
  *
- * This function is primarily used on Mac OS X, but is generally accessible
+ * This function is primarily used on OS X, but is generally accessible
  * since cupstestppd needs to check for profile name collisions in PPD files...
  */
 
@@ -564,8 +669,8 @@ _ppdLocalizedAttr(ppd_file_t *ppd,  /* I - PPD file */
   ppd_attr_t   *attr;                  /* Current attribute */
 
 
-  DEBUG_printf(("_ppdLocalizedAttr(ppd=%p, keyword=\"%s\", spec=\"%s\", "
-                "ll_CC=\"%s\")\n", ppd, keyword, spec, ll_CC));
+  DEBUG_printf(("4_ppdLocalizedAttr(ppd=%p, keyword=\"%s\", spec=\"%s\", "
+                "ll_CC=\"%s\")", ppd, keyword, spec, ll_CC));
 
  /*
   * Look for Keyword.ll_CC, then Keyword.ll...
@@ -574,7 +679,7 @@ _ppdLocalizedAttr(ppd_file_t *ppd,  /* I - PPD file */
   snprintf(lkeyword, sizeof(lkeyword), "%s.%s", ll_CC, keyword);
   if ((attr = ppdFindAttr(ppd, lkeyword, spec)) == NULL)
   {
-    snprintf(lkeyword, sizeof(lkeyword), "%2s.%s", ll_CC, keyword);
+    snprintf(lkeyword, sizeof(lkeyword), "%2.2s.%s", ll_CC, keyword);
     attr = ppdFindAttr(ppd, lkeyword, spec);
 
     if (!attr)
@@ -607,10 +712,10 @@ _ppdLocalizedAttr(ppd_file_t *ppd,        /* I - PPD file */
 
 #ifdef DEBUG
   if (attr)
-    DEBUG_printf(("_ppdLocalizedAttr: *%s %s/%s: \"%s\"\n", attr->name,
+    DEBUG_printf(("5_ppdLocalizedAttr: *%s %s/%s: \"%s\"\n", attr->name,
                   attr->spec, attr->text, attr->value ? attr->value : ""));
   else
-    DEBUG_puts("_ppdLocalizedAttr: NOT FOUND");
+    DEBUG_puts("5_ppdLocalizedAttr: NOT FOUND");
 #endif /* DEBUG */
 
   return (attr);
@@ -621,7 +726,7 @@ _ppdLocalizedAttr(ppd_file_t *ppd,  /* I - PPD file */
  * 'ppd_ll_CC()' - Get the current locale names.
  */
 
-static void
+static cups_lang_t *                   /* O - Current language */
 ppd_ll_CC(char *ll_CC,                 /* O - Country-specific locale name */
           int  ll_CC_size)             /* I - Size of country-specific name */
 {
@@ -635,7 +740,7 @@ ppd_ll_CC(char *ll_CC,                      /* O - Country-specific locale name */
   if ((lang = cupsLangDefault()) == NULL)
   {
     strlcpy(ll_CC, "en_US", ll_CC_size);
-    return;
+    return (NULL);
   }
 
  /*
@@ -661,20 +766,14 @@ ppd_ll_CC(char *ll_CC,                    /* O - Country-specific locale name */
       strlcpy(ll_CC, "sv_SE", ll_CC_size);
     else if (!strcmp(ll_CC, "zh"))     /* Simplified Chinese */
       strlcpy(ll_CC, "zh_CN", ll_CC_size);
-    else if (ll_CC_size >= 6)
-    {
-      ll_CC[2] = '_';
-      ll_CC[3] = toupper(ll_CC[0] & 255);
-      ll_CC[4] = toupper(ll_CC[1] & 255);
-      ll_CC[5] = '\0';
-    }
   }
 
-  DEBUG_printf(("ppd_ll_CC: lang->language=\"%s\", ll_CC=\"%s\"...\n",
+  DEBUG_printf(("8ppd_ll_CC: lang->language=\"%s\", ll_CC=\"%s\"...",
                 lang->language, ll_CC));
+  return (lang);
 }
 
 
 /*
- * End of "$Id: localize.c 7363 2008-03-03 22:19:24Z mike $".
+ * End of "$Id$".
  */