diff options
author | Michael R Sweet <michaelrsweet@gmail.com> | 2017-12-19 14:53:00 -0500 |
---|---|---|
committer | Michael R Sweet <michaelrsweet@gmail.com> | 2017-12-19 14:53:00 -0500 |
commit | 2fa1ba3cc0e02799b739ef0e06efc940a8c5a33e (patch) | |
tree | 3d9da027144be82db3acea277a4c7dcd58d0f40f /cups/ppd-cache.c | |
parent | 3d90ace3170087acd66d189fcf2362242815f88d (diff) | |
download | cups-2fa1ba3cc0e02799b739ef0e06efc940a8c5a33e.tar.gz |
Generate strings files for localizing PPD options (Issue #5194)
cups/language-private.h:
- New _cupsMessageAdd and _cupsMessageSave private APIs.
cups/language.c:
- Implement new _cupsMessageAdd and _cupsMessageSave private APIs.
cups/ppd-cache.c:
- Generate strings array when loading cache from PPD.
- Remove strings_uri (just pulling strings from PPD now).
cups/ppd-private.h:
- Remove strings_uri and add strings array to cache.
scheduler/client.c:
- Add support for /strings/NAME.strings
- Cleanup implementation of GET/HEAD/POST to files.
scheduler/ipp.c:
- Return local strings file URI.
- Clean up copy_printer_attrs implementation.
scheduler/printers.c:
- Save strings array to cache file, drop support for strings_uri.
scheduler/printers.h:
- Add strings filename to cupsd_printer_t structure.
Diffstat (limited to 'cups/ppd-cache.c')
-rw-r--r-- | cups/ppd-cache.c | 84 |
1 files changed, 68 insertions, 16 deletions
diff --git a/cups/ppd-cache.c b/cups/ppd-cache.c index 23e34be4b..177db7b08 100644 --- a/cups/ppd-cache.c +++ b/cups/ppd-cache.c @@ -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); + } } /* @@ -1871,13 +1914,6 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ 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); } @@ -2948,13 +2986,6 @@ _ppdCacheWriteFile( cupsFilePutConf(fp, "Mandatory", value); /* - * (Remote) strings file... - */ - - if (pc->strings_uri) - cupsFilePutConf(fp, "StringsURI", pc->strings_uri); - - /* * Support files... */ @@ -4614,6 +4645,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. */ |