]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/ppd-cache.c
Generate strings files for localizing PPD options (Issue #5194)
[thirdparty/cups.git] / cups / ppd-cache.c
index 23e34be4b81cdab55ef0160e33bc7c7dc6748a89..177db7b082a78b0173b0f2bbc01aa48d7180e420 100644 (file)
@@ -28,6 +28,7 @@
 
 static int     cups_get_url(http_t **http, const char *url, char *name, size_t namesize);
 static void    pwg_add_finishing(cups_array_t *finishings, ipp_finishings_t template, const char *name, const char *value);
+static void    pwg_add_message(cups_array_t *a, const char *msg, const char *str);
 static int     pwg_compare_finishings(_pwg_finishings_t *a, _pwg_finishings_t *b);
 static int     pwg_compare_sizes(cups_size_t *a, cups_size_t *b);
 static cups_size_t *pwg_copy_size(cups_size_t *size);
@@ -914,8 +915,6 @@ _ppdCacheCreateWithFile(
       else
         pc->mandatory = _cupsArrayNewStrings(value, ' ');
     }
-    else if (!_cups_strcasecmp(line, "StringsURI"))
-      pc->strings_uri = _cupsStrAlloc(value);
     else if (!_cups_strcasecmp(line, "SupportFile"))
     {
       if (!pc->support_files)
@@ -1028,6 +1027,7 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)   /* I - PPD file */
   pwg_size_t           *new_size;      /* New size to add, if any */
   const char           *filter;        /* Current filter */
   _pwg_finishings_t    *finishings;    /* Current finishings value */
+  char                 msg_id[256];    /* Message identifier */
 
 
   DEBUG_printf(("_ppdCacheCreateWithPPD(ppd=%p)", ppd));
@@ -1049,6 +1049,8 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)   /* I - PPD file */
     goto create_error;
   }
 
+  pc->strings = _cupsMessageNew(NULL);
+
  /*
   * Copy and convert size data...
   */
@@ -1285,6 +1287,13 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)  /* I - PPD file */
 
       map->pwg = _cupsStrAlloc(pwg_name);
       map->ppd = _cupsStrAlloc(choice->choice);
+
+     /*
+      * Add localized text for PWG keyword to message catalog...
+      */
+
+      snprintf(msg_id, sizeof(msg_id), "media-source.%s", pwg_name);
+      pwg_add_message(pc->strings, msg_id, choice->text);
     }
   }
 
@@ -1349,6 +1358,13 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)  /* I - PPD file */
 
       map->pwg = _cupsStrAlloc(pwg_name);
       map->ppd = _cupsStrAlloc(choice->choice);
+
+     /*
+      * Add localized text for PWG keyword to message catalog...
+      */
+
+      snprintf(msg_id, sizeof(msg_id), "media-type.%s", pwg_name);
+      pwg_add_message(pc->strings, msg_id, choice->text);
     }
   }
 
@@ -1376,6 +1392,13 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)  /* I - PPD file */
 
       map->pwg = _cupsStrAlloc(pwg_keyword);
       map->ppd = _cupsStrAlloc(choice->choice);
+
+     /*
+      * Add localized text for PWG keyword to message catalog...
+      */
+
+      snprintf(msg_id, sizeof(msg_id), "output-bin.%s", pwg_name);
+      pwg_add_message(pc->strings, msg_id, choice->text);
     }
   }
 
@@ -1393,6 +1416,17 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)  /* I - PPD file */
 
     do
     {
+     /*
+      * Add localized text for PWG keyword to message catalog...
+      */
+
+      snprintf(msg_id, sizeof(msg_id), "preset-name.%s", ppd_attr->spec);
+      pwg_add_message(pc->strings, msg_id, ppd_attr->text);
+
+     /*
+      * Get the options for this preset...
+      */
+
       num_options = _ppdParseOptions(ppd_attr->value, 0, &options,
                                      _PPD_PARSE_ALL);
 
@@ -1836,7 +1870,16 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)  /* I - PPD file */
     pc->templates = cupsArrayNew3((cups_array_func_t)strcmp, NULL, NULL, 0, (cups_acopy_func_t)_cupsStrAlloc, (cups_afree_func_t)_cupsStrFree);
 
     for (choice = ppd_option->choices, i = ppd_option->num_choices; i > 0; choice ++, i --)
+    {
       cupsArrayAdd(pc->templates, (void *)choice->choice);
+
+     /*
+      * Add localized text for PWG keyword to message catalog...
+      */
+
+      snprintf(msg_id, sizeof(msg_id), "finishing-template.%s", choice->choice);
+      pwg_add_message(pc->strings, msg_id, choice->text);
+    }
   }
 
  /*
@@ -1870,13 +1913,6 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)  /* I - PPD file */
   if ((ppd_attr = ppdFindAttr(ppd, "cupsMandatory", NULL)) != NULL)
     pc->mandatory = _cupsArrayNewStrings(ppd_attr->value, ' ');
 
- /*
-  * Strings (remote) file...
-  */
-
-  if ((ppd_attr = ppdFindAttr(ppd, "cupsStringsURI", NULL)) != NULL)
-    pc->strings_uri = _cupsStrAlloc(ppd_attr->value);
-
  /*
   * Support files...
   */
@@ -2000,6 +2036,8 @@ _ppdCacheDestroy(_ppd_cache_t *pc)        /* I - PPD cache and mapping data */
 
   cupsArrayDelete(pc->support_files);
 
+  cupsArrayDelete(pc->strings);
+
   free(pc);
 }
 
@@ -2947,13 +2985,6 @@ _ppdCacheWriteFile(
        value = (char *)cupsArrayNext(pc->mandatory))
     cupsFilePutConf(fp, "Mandatory", value);
 
- /*
-  * (Remote) strings file...
-  */
-
-  if (pc->strings_uri)
-    cupsFilePutConf(fp, "StringsURI", pc->strings_uri);
-
  /*
   * Support files...
   */
@@ -4613,6 +4644,27 @@ pwg_add_finishing(
 }
 
 
+/*
+ * 'pwg_add_message()' - Add a message to the PPD cached strings.
+ */
+
+static void
+pwg_add_message(cups_array_t *a,       /* I - Message catalog */
+                const char   *msg,     /* I - Message identifier */
+                const char   *str)     /* I - Localized string */
+{
+  _cups_message_t      *m;             /* New message */
+
+
+  if ((m = calloc(1, sizeof(_cups_message_t))) != NULL)
+  {
+    m->msg = strdup(msg);
+    m->str = strdup(str);
+    cupsArrayAdd(a, m);
+  }
+}
+
+
 /*
  * 'pwg_compare_finishings()' - Compare two finishings values.
  */