]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Update _ppdCacheCreateWithPPD to accept languages to localize.
authorMichael R Sweet <msweet@msweet.org>
Mon, 15 Apr 2024 20:00:42 +0000 (16:00 -0400)
committerMichael R Sweet <msweet@msweet.org>
Mon, 15 Apr 2024 20:00:42 +0000 (16:00 -0400)
backend/ipp.c
cups/ppd-cache.c
cups/ppd-mark.c
cups/ppd-private.h
scheduler/conf.h
scheduler/cupsfilter.c
scheduler/printers.c
tools/ippeveps.c

index 749ad085d812725acee476e0be049fc92f9fc50e..17966f7f31d02f996001537fef915dc4148f1293 100644 (file)
@@ -9,10 +9,6 @@
  * information.
  */
 
-/*
- * Include necessary headers.
- */
-
 #include "backend-private.h"
 #include <cups/ppd-private.h>
 #include <sys/types.h>
@@ -1323,7 +1319,7 @@ main(int  argc,                           /* I - Number of command-line args */
       ppd_attr_t *mandatory;           /* cupsMandatory value */
 
       ppd = ppdOpenFile(getenv("PPD"));
-      pc  = _ppdCacheCreateWithPPD(ppd);
+      pc  = _ppdCacheCreateWithPPD(NULL, ppd);
 
       ppdMarkDefaults(ppd);
       cupsMarkOptions(ppd, num_options, options);
index 679f3695ece348b0a02d9797dcc65967bc7cfbb6..0cd49851ff1748b626e81ab1b70f1f7f25dfd1a4 100644 (file)
@@ -8,14 +8,11 @@
  * information.
  */
 
-/*
- * Include necessary headers...
- */
-
 #include "cups-private.h"
 #include "ppd-private.h"
 #include "debug-internal.h"
 #include <math.h>
+#include <ctype.h>
 
 
 /*
@@ -37,7 +34,6 @@ static const char *ppd_get_string(cups_lang_t *base, cups_lang_t *printer, const
 static const char *ppd_inputslot_for_keyword(_ppd_cache_t *pc, const char *keyword);
 static void    ppd_put_strings(cups_file_t *fp, cups_lang_t *langs, const char *ppd_option, const char *ppd_choice, const char *pwg_msgid);
 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, void *data);
 static int     pwg_compare_sizes(cups_size_t *a, cups_size_t *b, void *data);
 static cups_size_t *pwg_copy_size(cups_size_t *size, void *data);
@@ -1023,7 +1019,9 @@ _ppdCacheCreateWithFile(
  */
 
 _ppd_cache_t *                         /* O - PPD cache and mapping data */
-_ppdCacheCreateWithPPD(ppd_file_t *ppd)        /* I - PPD file */
+_ppdCacheCreateWithPPD(
+    cups_lang_t *langs,                        /* I - Languages to load */
+    ppd_file_t  *ppd)                  /* I - PPD file */
 {
   int                  i, j, k;        /* Looping vars */
   _ppd_cache_t         *pc;            /* PWG mapping data */
@@ -1068,6 +1066,8 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)   /* I - PPD file */
   const char           *filter;        /* Current filter */
   _pwg_finishings_t    *finishings;    /* Current finishings value */
   char                 msg_id[256];    /* Message identifier */
+  cups_lang_t          *lang;          /* Current language */
+  _cups_message_t      msg;            /* Message */
 
 
   DEBUG_printf("_ppdCacheCreateWithPPD(ppd=%p)", (void *)ppd);
@@ -1089,8 +1089,6 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)   /* I - PPD file */
     goto create_error;
   }
 
-  pc->strings = _cupsMessageNew(NULL);
-
  /*
   * Copy and convert size data...
   */
@@ -1353,7 +1351,32 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)  /* I - PPD file */
       */
 
       snprintf(msg_id, sizeof(msg_id), "media-source.%s", pwg_name);
-      pwg_add_message(pc->strings, msg_id, choice->text);
+      msg.msg = msg_id;
+
+      for (lang = langs; lang; lang = lang->next)
+      {
+        // See if the string is already localized...
+        if (cupsArrayFind(lang->strings, &msg))
+          continue;                    // Yes
+
+        // Otherwise add the text...
+        if (!strcmp(lang->language, "en"))
+        {
+          // English
+          msg.str = choice->text;
+       }
+       else
+       {
+         // Other languauge...
+          snprintf(ppd_name, sizeof(ppd_name), "%s.InputSlot", lang->language);
+          if ((ppd_attr = ppdFindAttr(ppd, ppd_name, choice->choice)) != NULL)
+            msg.str = ppd_attr->text;
+         else
+           continue;
+       }
+
+       cupsArrayAdd(lang->strings, &msg);
+      }
     }
   }
 
@@ -1464,12 +1487,38 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */
         }
       }
 
+
      /*
       * Add localized text for PWG keyword to message catalog...
       */
 
       snprintf(msg_id, sizeof(msg_id), "media-type.%s", map->pwg);
-      pwg_add_message(pc->strings, msg_id, choice->text);
+      msg.msg = msg_id;
+
+      for (lang = langs; lang; lang = lang->next)
+      {
+        // See if the string is already localized...
+        if (cupsArrayFind(lang->strings, &msg))
+          continue;                    // Yes
+
+        // Otherwise add the text...
+        if (!strcmp(lang->language, "en"))
+        {
+          // English
+          msg.str = choice->text;
+       }
+       else
+       {
+         // Other languauge...
+          snprintf(ppd_name, sizeof(ppd_name), "%s.MediaType", lang->language);
+          if ((ppd_attr = ppdFindAttr(ppd, ppd_name, choice->choice)) != NULL)
+            msg.str = ppd_attr->text;
+         else
+           continue;
+       }
+
+       cupsArrayAdd(lang->strings, &msg);
+      }
     }
   }
 
@@ -1497,12 +1546,38 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */
       map->pwg = strdup(pwg_keyword);
       map->ppd = strdup(choice->choice);
 
+
      /*
       * Add localized text for PWG keyword to message catalog...
       */
 
-      snprintf(msg_id, sizeof(msg_id), "output-bin.%s", pwg_keyword);
-      pwg_add_message(pc->strings, msg_id, choice->text);
+      snprintf(msg_id, sizeof(msg_id), "output-bin.%s", pwg_name);
+      msg.msg = msg_id;
+
+      for (lang = langs; lang; lang = lang->next)
+      {
+        // See if the string is already localized...
+        if (cupsArrayFind(lang->strings, &msg))
+          continue;                    // Yes
+
+        // Otherwise add the text...
+        if (!strcmp(lang->language, "en"))
+        {
+          // English
+          msg.str = choice->text;
+       }
+       else
+       {
+         // Other languauge...
+          snprintf(ppd_name, sizeof(ppd_name), "%s.OutputBin", lang->language);
+          if ((ppd_attr = ppdFindAttr(ppd, ppd_name, choice->choice)) != NULL)
+            msg.str = ppd_attr->text;
+         else
+           continue;
+       }
+
+       cupsArrayAdd(lang->strings, &msg);
+      }
     }
   }
 
@@ -1520,12 +1595,14 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */
 
     do
     {
+#if 0
      /*
       * 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);
+#endif // 0
 
      /*
       * Get the options for this preset...
@@ -1978,7 +2055,32 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd)  /* I - PPD file */
       */
 
       snprintf(msg_id, sizeof(msg_id), "finishing-template.%s", choice->choice);
-      pwg_add_message(pc->strings, msg_id, choice->text);
+      msg.msg = msg_id;
+
+      for (lang = langs; lang; lang = lang->next)
+      {
+        // See if the string is already localized...
+        if (cupsArrayFind(lang->strings, &msg))
+          continue;                    // Yes
+
+        // Otherwise add the text...
+        if (!strcmp(lang->language, "en"))
+        {
+          // English
+          msg.str = choice->text;
+       }
+       else
+       {
+         // Other languauge...
+          snprintf(ppd_name, sizeof(ppd_name), "%s.cupsFinishingTemplate", lang->language);
+          if ((ppd_attr = ppdFindAttr(ppd, ppd_name, choice->choice)) != NULL)
+            msg.str = ppd_attr->text;
+         else
+           continue;
+       }
+
+       cupsArrayAdd(lang->strings, &msg);
+      }
     }
   }
 
@@ -2132,8 +2234,6 @@ _ppdCacheDestroy(_ppd_cache_t *pc)        /* I - PPD cache and mapping data */
 
   cupsArrayDelete(pc->support_files);
 
-  cupsArrayDelete(pc->strings);
-
   free(pc);
 }
 
@@ -5483,13 +5583,13 @@ ppd_get_string(cups_lang_t *base,       // I - Base (CUPS) localization
         return ("");
 
       cupsCopyString(buffer, msgptr, bufsize);
-      buffer[0] = toupper(buffer[0] & 255);
+      buffer[0] = (char)toupper(buffer[0] & 255);
       for (bufptr = buffer + 1; *bufptr; bufptr ++)
       {
         if (*bufptr == '-')
         {
           *bufptr   = ' ';
-          bufptr[1] = toupper(bufptr[1] & 255);
+          bufptr[1] = (char)toupper(bufptr[1] & 255);
         }
       }
 
@@ -5548,27 +5648,6 @@ 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.
  */
index ef3e2534058bb5b4357d0fb1760ca7ab7cde5cf6..1b1f5f211d2e9e8f593f9b2303584a24ecaf4554 100644 (file)
  * PostScript is a trademark of Adobe Systems, Inc.
  */
 
-/*
- * Include necessary headers...
- */
-
 #include "cups-private.h"
 #include "ppd-private.h"
 #include "debug-internal.h"
@@ -97,7 +93,7 @@ cupsMarkOptions(
     * Load PPD cache and mapping data as needed...
     */
 
-    ppd->cache = _ppdCacheCreateWithPPD(ppd);
+    ppd->cache = _ppdCacheCreateWithPPD(NULL, ppd);
   }
 
   cache = ppd->cache;
index f264406ccede9a98f09de9fc2367189fa2ba2974..fbeac2d5599bee3b3a9a4267d45bbf5541526e6d 100644 (file)
@@ -136,8 +136,6 @@ struct _ppd_cache_s                 /**** PPD cache and PWG conversion data ****/
   char         *password;              /* cupsJobPassword value */
   cups_array_t *mandatory;             /* cupsMandatory value */
   char         *charge_info_uri;       /* cupsChargeInfoURI value */
-  cups_lang_t  *langs;                 /* Localization languages/strings */
-  cups_array_t *strings;               /* TODO: REMOVE ME */
   cups_array_t *support_files;         /* Support files - ICC profiles, etc. */
 };
 
@@ -151,7 +149,7 @@ extern int          _cupsRasterExecPS(cups_page_header2_t *h, int *preferred_bits, const
 extern int             _cupsRasterInterpretPPD(cups_page_header2_t *h, ppd_file_t *ppd, int num_options, cups_option_t *options, cups_interpret_cb_t func) _CUPS_PRIVATE;
 
 extern _ppd_cache_t    *_ppdCacheCreateWithFile(const char *filename, ipp_t **attrs) _CUPS_PRIVATE;
-extern _ppd_cache_t    *_ppdCacheCreateWithPPD(ppd_file_t *ppd) _CUPS_PRIVATE;
+extern _ppd_cache_t    *_ppdCacheCreateWithPPD(cups_lang_t *langs, ppd_file_t *ppd) _CUPS_PRIVATE;
 extern void            _ppdCacheDestroy(_ppd_cache_t *pc) _CUPS_PRIVATE;
 extern const char      *_ppdCacheGetBin(_ppd_cache_t *pc, const char *output_bin) _CUPS_PRIVATE;
 extern int             _ppdCacheGetFinishingOptions(_ppd_cache_t *pc, ipp_t *job, ipp_finishings_t value, int num_options, cups_option_t **options) _CUPS_PRIVATE;
index c80b45fcb16d43a958a2f18a6b3aea6e551c4b5b..19b5c1621b8a386ed03a681d6c1629499c0c7b24 100644 (file)
@@ -110,6 +110,8 @@ VAR char            *ConfigurationFile      VALUE(NULL),
                                        /* Directory for request files */
                        *DocumentRoot           VALUE(NULL);
                                        /* Root directory for documents */
+VAR cups_lang_t                *Languages              VALUE(NULL);
+                                       /* Languages that cupsd is providing */
 VAR cups_array_t       *ServerAlias            VALUE(NULL);
                                        /* Alias names for server */
 VAR int                        ServerNameIsIP          VALUE(0);
index a1511cd6b95f8681a784332ed87671bc1b8c0d09..ebe6a37773e072b990892542c664fd9557a8f7b4 100644 (file)
@@ -8,10 +8,6 @@
  * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
-/*
- * Include necessary headers...
- */
-
 #include <cups/cups-private.h>
 #include <cups/file-private.h>
 #include <cups/ppd-private.h>
@@ -714,7 +710,7 @@ add_printer_filters(
     return (NULL);
   }
 
-  pc = _ppdCacheCreateWithPPD(ppd);
+  pc = _ppdCacheCreateWithPPD(NULL, ppd);
   if (!pc)
     return (NULL);
 
index 087253407193f008ea2dfda2e8e30ea97b8e2daa..e4384abc63c623484b38744f12d33ece73fc5c94 100644 (file)
@@ -9,10 +9,6 @@
  * information.
  */
 
-/*
- * Include necessary headers...
- */
-
 #include "cupsd.h"
 #include <cups/dir.h>
 #ifdef HAVE_APPLICATIONSERVICES_H
@@ -4028,7 +4024,7 @@ load_ppd(cupsd_printer_t *p)              /* I - Printer */
     * Add make/model and other various attributes...
     */
 
-    p->pc = _ppdCacheCreateWithPPD(ppd);
+    p->pc = _ppdCacheCreateWithPPD(Languages, ppd);
 
     if (!p->pc)
       cupsdLogMessage(CUPSD_LOG_WARN, "Unable to create cache of \"%s\": %s", ppd_name, cupsGetErrorString());
@@ -4154,6 +4150,7 @@ load_ppd(cupsd_printer_t *p)              /* I - Printer */
     ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
                 "printer-make-and-model", NULL, p->make_model);
 
+#if 0 // TODO: Save global strings
     if (p->pc && p->pc->strings)
       _cupsMessageSave(strings_name, _CUPS_MESSAGE_STRINGS, p->pc->strings);
 
@@ -4161,6 +4158,7 @@ load_ppd(cupsd_printer_t *p)              /* I - Printer */
       cupsdSetString(&p->strings, strings_name);
     else
       cupsdClearString(&p->strings);
+#endif // 0
 
     num_urf         = 0;
     urf[num_urf ++] = "V1.4";
index 7a740980586d5ae08dc5113998fb0786adcfa83c..e4082f1f329854dc2e9468d14ad14072aab118f8 100644 (file)
@@ -421,7 +421,7 @@ get_options(cups_option_t **options)        /* O - Options */
   * Load PPD file and the corresponding IPP <-> PPD cache data...
   */
 
-  if ((ppd = ppdOpenFile(getenv("PPD"))) != NULL && (ppd_cache = _ppdCacheCreateWithPPD(ppd)) != NULL)
+  if ((ppd = ppdOpenFile(getenv("PPD"))) != NULL && (ppd_cache = _ppdCacheCreateWithPPD(NULL, ppd)) != NULL)
   {
     /* TODO: Fix me - values are names, not numbers... Also need to support finishings-col */
     if ((value = getenv("IPP_FINISHINGS")) == NULL)