]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/localize.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / localize.c
CommitLineData
fa73b229 1/*
f7deaa1a 2 * "$Id: localize.c 5824 2006-08-15 18:19:45Z mike $"
fa73b229 3 *
4 * PPD custom option routines for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
19 *
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * PostScript is a trademark of Adobe Systems, Inc.
25 *
26 * This code and any derivative of it may be used and distributed
27 * freely under the terms of the GNU General Public License when
28 * used with GNU Ghostscript or its derivatives. Use of the code
29 * (or any derivative of it) with software other than GNU
30 * GhostScript (or its derivatives) is governed by the CUPS license
31 * agreement.
32 *
33 * This file is subject to the Apple OS-Developed Software exception.
34 *
35 * Contents:
36 *
37 * ppdLocalize() - Localize the PPD file to the current locale.
38 */
39
40/*
41 * Include necessary headers.
42 */
43
44#include "globals.h"
45#include "debug.h"
46
47
48/*
49 * Local functions...
50 */
51
52static const char *ppd_text(ppd_file_t *ppd, const char *keyword,
53 const char *spec, const char *ll_CC,
54 const char *ll);
55
56
57/*
58 * 'ppdLocalize()' - Localize the PPD file to the current locale.
89d46774 59 *
60 * @since CUPS 1.2@
fa73b229 61 */
62
63int /* O - 0 on success, -1 on error */
64ppdLocalize(ppd_file_t *ppd) /* I - PPD file */
65{
66 int i, j, k; /* Looping vars */
67 ppd_group_t *group; /* Current group */
68 ppd_option_t *option; /* Current option */
69 ppd_choice_t *choice; /* Current choice */
70 ppd_coption_t *coption; /* Current custom option */
71 ppd_cparam_t *cparam; /* Current custom parameter */
72 cups_lang_t *lang; /* Current language */
73 char ckeyword[PPD_MAX_NAME], /* Custom keyword */
74 ll_CC[6], /* Language + country locale */
75 ll[3]; /* Language locale */
76 const char *text; /* Localized text */
77
78
79 /*
80 * Range check input...
81 */
82
d09495fa 83 DEBUG_printf(("ppdLocalize(ppd=%p)\n", ppd));
84
fa73b229 85 if (!ppd)
86 return (-1);
87
88 /*
89 * Get the default language...
90 */
91
92 if ((lang = cupsLangDefault()) == NULL)
93 return (-1);
94
95 strlcpy(ll_CC, lang->language, sizeof(ll_CC));
96 strlcpy(ll, lang->language, sizeof(ll));
97
d09495fa 98 DEBUG_printf((" lang->language=\"%s\", ll=\"%s\", ll_CC=\"%s\"...\n",
99 lang->language, ll, ll_CC));
100
fa73b229 101 /*
102 * Now lookup all of the groups, options, choices, etc.
103 */
104
105 for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++)
106 {
107 if ((text = ppd_text(ppd, "Translation", group->name, ll_CC, ll)) != NULL)
108 strlcpy(group->text, text, sizeof(group->text));
109
110 for (j = group->num_options, option = group->options; j > 0; j --, option ++)
111 {
112 if ((text = ppd_text(ppd, "Translation", option->keyword, ll_CC,
113 ll)) != NULL)
114 strlcpy(option->text, text, sizeof(option->text));
115
116 for (k = option->num_choices, choice = option->choices;
117 k > 0;
118 k --, choice ++)
119 {
120 if (strcmp(choice->choice, "Custom"))
121 text = ppd_text(ppd, option->keyword, choice->choice, ll_CC, ll);
122 else
123 {
124 snprintf(ckeyword, sizeof(ckeyword), "Custom%s", option->keyword);
125
126 text = ppd_text(ppd, ckeyword, "True", ll_CC, ll);
127 }
128
129 if (text)
130 strlcpy(choice->text, text, sizeof(choice->text));
131 }
132 }
133 }
134
135 /*
136 * Translate any custom parameters...
137 */
138
139 for (coption = (ppd_coption_t *)cupsArrayFirst(ppd->coptions);
140 coption;
141 coption = (ppd_coption_t *)cupsArrayNext(ppd->coptions))
142 {
143 for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
144 cparam;
145 cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
146 {
147 snprintf(ckeyword, sizeof(ckeyword), "ParamCustom%s", coption->keyword);
148
149 if ((text = ppd_text(ppd, ckeyword, cparam->name, ll_CC, ll)) != NULL)
150 strlcpy(cparam->text, text, sizeof(cparam->text));
151 }
152 }
153
154 return (0);
155}
156
157
158/*
159 * 'ppd_text()' - Find the localized text as needed...
160 */
161
162static const char * /* O - Localized text or NULL */
163ppd_text(ppd_file_t *ppd, /* I - PPD file */
164 const char *keyword, /* I - Main keyword */
165 const char *spec, /* I - Option keyword */
166 const char *ll_CC, /* I - Language + country locale */
167 const char *ll) /* I - Language locale */
168{
169 char lkeyword[PPD_MAX_NAME]; /* Localization keyword */
170 ppd_attr_t *attr; /* Current attribute */
171
172
d09495fa 173 DEBUG_printf(("ppd_text(ppd=%p, keyword=\"%s\", spec=\"%s\", "
174 "ll_CC=\"%s\", ll=\"%s\")\n",
175 ppd, keyword, spec, ll_CC, ll));
176
fa73b229 177 /*
178 * Look for Keyword.ll_CC, then Keyword.ll...
179 */
180
d09495fa 181 snprintf(lkeyword, sizeof(lkeyword), "%s.%s", ll_CC, keyword);
fa73b229 182 if ((attr = ppdFindAttr(ppd, lkeyword, spec)) == NULL)
183 {
d09495fa 184 snprintf(lkeyword, sizeof(lkeyword), "%s.%s", ll, keyword);
fa73b229 185 attr = ppdFindAttr(ppd, lkeyword, spec);
186 }
187
d09495fa 188#ifdef DEBUG
189 if (attr)
190 printf(" *%s %s/%s: \"%s\"\n", attr->name, attr->spec, attr->text,
191 attr->value ? attr->value : "");
192 else
193 puts(" NOT FOUND");
194#endif /* DEBUG */
195
fa73b229 196 /*
197 * Return text if we find it...
198 */
199
200 return (attr ? attr->text : NULL);
201}
202
203
204/*
f7deaa1a 205 * End of "$Id: localize.c 5824 2006-08-15 18:19:45Z mike $".
fa73b229 206 */