]>
Commit | Line | Data |
---|---|---|
fa73b229 | 1 | /* |
f42414bf | 2 | * "$Id: localize.c 6388 2007-03-24 14:21:31Z mike $" |
fa73b229 | 3 | * |
4 | * PPD custom option routines for the Common UNIX Printing System (CUPS). | |
5 | * | |
7594b224 | 6 | * Copyright 1997-2007 by Easy Software Products, all rights reserved. |
fa73b229 | 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 | ||
52 | static 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 | ||
63 | int /* O - 0 on success, -1 on error */ | |
64 | ppdLocalize(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 */ | |
f42414bf | 72 | ppd_attr_t *attr; /* Current attribute */ |
fa73b229 | 73 | cups_lang_t *lang; /* Current language */ |
74 | char ckeyword[PPD_MAX_NAME], /* Custom keyword */ | |
75 | ll_CC[6], /* Language + country locale */ | |
76 | ll[3]; /* Language locale */ | |
77 | const char *text; /* Localized text */ | |
78 | ||
79 | ||
80 | /* | |
81 | * Range check input... | |
82 | */ | |
83 | ||
d09495fa | 84 | DEBUG_printf(("ppdLocalize(ppd=%p)\n", ppd)); |
85 | ||
fa73b229 | 86 | if (!ppd) |
87 | return (-1); | |
88 | ||
89 | /* | |
90 | * Get the default language... | |
91 | */ | |
92 | ||
93 | if ((lang = cupsLangDefault()) == NULL) | |
94 | return (-1); | |
95 | ||
96 | strlcpy(ll_CC, lang->language, sizeof(ll_CC)); | |
97 | strlcpy(ll, lang->language, sizeof(ll)); | |
98 | ||
d09495fa | 99 | DEBUG_printf((" lang->language=\"%s\", ll=\"%s\", ll_CC=\"%s\"...\n", |
100 | lang->language, ll, ll_CC)); | |
101 | ||
fa73b229 | 102 | /* |
103 | * Now lookup all of the groups, options, choices, etc. | |
104 | */ | |
105 | ||
106 | for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++) | |
107 | { | |
108 | if ((text = ppd_text(ppd, "Translation", group->name, ll_CC, ll)) != NULL) | |
109 | strlcpy(group->text, text, sizeof(group->text)); | |
110 | ||
111 | for (j = group->num_options, option = group->options; j > 0; j --, option ++) | |
112 | { | |
113 | if ((text = ppd_text(ppd, "Translation", option->keyword, ll_CC, | |
114 | ll)) != NULL) | |
115 | strlcpy(option->text, text, sizeof(option->text)); | |
116 | ||
117 | for (k = option->num_choices, choice = option->choices; | |
118 | k > 0; | |
119 | k --, choice ++) | |
120 | { | |
121 | if (strcmp(choice->choice, "Custom")) | |
122 | text = ppd_text(ppd, option->keyword, choice->choice, ll_CC, ll); | |
123 | else | |
124 | { | |
125 | snprintf(ckeyword, sizeof(ckeyword), "Custom%s", option->keyword); | |
126 | ||
127 | text = ppd_text(ppd, ckeyword, "True", ll_CC, ll); | |
128 | } | |
129 | ||
130 | if (text) | |
131 | strlcpy(choice->text, text, sizeof(choice->text)); | |
132 | } | |
133 | } | |
134 | } | |
135 | ||
136 | /* | |
137 | * Translate any custom parameters... | |
138 | */ | |
139 | ||
140 | for (coption = (ppd_coption_t *)cupsArrayFirst(ppd->coptions); | |
141 | coption; | |
142 | coption = (ppd_coption_t *)cupsArrayNext(ppd->coptions)) | |
143 | { | |
144 | for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params); | |
145 | cparam; | |
146 | cparam = (ppd_cparam_t *)cupsArrayNext(coption->params)) | |
147 | { | |
148 | snprintf(ckeyword, sizeof(ckeyword), "ParamCustom%s", coption->keyword); | |
149 | ||
150 | if ((text = ppd_text(ppd, ckeyword, cparam->name, ll_CC, ll)) != NULL) | |
151 | strlcpy(cparam->text, text, sizeof(cparam->text)); | |
152 | } | |
153 | } | |
154 | ||
f42414bf | 155 | /* |
156 | * Translate ICC profile names... | |
157 | */ | |
158 | ||
159 | if ((attr = ppdFindAttr(ppd, "APCustomColorMatchingName", NULL)) != NULL) | |
160 | { | |
161 | if ((text = ppd_text(ppd, "APCustomColorMatchingName", attr->spec, | |
162 | ll_CC, ll)) != NULL) | |
163 | strlcpy(attr->text, text, sizeof(attr->text)); | |
164 | } | |
165 | ||
166 | for (attr = ppdFindAttr(ppd, "cupsICCProfile", NULL); | |
167 | attr; | |
168 | attr = ppdFindNextAttr(ppd, "cupsICCProfile", NULL)) | |
169 | { | |
170 | cupsArraySave(ppd->sorted_attrs); | |
171 | ||
172 | if ((text = ppd_text(ppd, "cupsICCProfile", attr->spec, ll_CC, ll)) != NULL) | |
173 | strlcpy(attr->text, text, sizeof(attr->text)); | |
174 | ||
175 | cupsArrayRestore(ppd->sorted_attrs); | |
176 | } | |
177 | ||
fa73b229 | 178 | return (0); |
179 | } | |
180 | ||
181 | ||
182 | /* | |
183 | * 'ppd_text()' - Find the localized text as needed... | |
184 | */ | |
185 | ||
186 | static const char * /* O - Localized text or NULL */ | |
187 | ppd_text(ppd_file_t *ppd, /* I - PPD file */ | |
188 | const char *keyword, /* I - Main keyword */ | |
189 | const char *spec, /* I - Option keyword */ | |
190 | const char *ll_CC, /* I - Language + country locale */ | |
191 | const char *ll) /* I - Language locale */ | |
192 | { | |
193 | char lkeyword[PPD_MAX_NAME]; /* Localization keyword */ | |
194 | ppd_attr_t *attr; /* Current attribute */ | |
195 | ||
196 | ||
d09495fa | 197 | DEBUG_printf(("ppd_text(ppd=%p, keyword=\"%s\", spec=\"%s\", " |
198 | "ll_CC=\"%s\", ll=\"%s\")\n", | |
199 | ppd, keyword, spec, ll_CC, ll)); | |
200 | ||
fa73b229 | 201 | /* |
202 | * Look for Keyword.ll_CC, then Keyword.ll... | |
203 | */ | |
204 | ||
d09495fa | 205 | snprintf(lkeyword, sizeof(lkeyword), "%s.%s", ll_CC, keyword); |
fa73b229 | 206 | if ((attr = ppdFindAttr(ppd, lkeyword, spec)) == NULL) |
207 | { | |
d09495fa | 208 | snprintf(lkeyword, sizeof(lkeyword), "%s.%s", ll, keyword); |
fa73b229 | 209 | attr = ppdFindAttr(ppd, lkeyword, spec); |
7594b224 | 210 | |
211 | if (!attr && !strcmp(ll, "ja")) | |
212 | { | |
213 | /* | |
214 | * Due to a bug in the CUPS DDK 1.1.0 ppdmerge program, Japanese | |
215 | * PPD files were incorrectly assigned "jp" as the locale name | |
216 | * instead of "ja". Support both the old (incorrect) and new | |
217 | * locale names for Japanese... | |
218 | */ | |
219 | ||
220 | snprintf(lkeyword, sizeof(lkeyword), "jp.%s", keyword); | |
221 | attr = ppdFindAttr(ppd, lkeyword, spec); | |
222 | } | |
fa73b229 | 223 | } |
224 | ||
d09495fa | 225 | #ifdef DEBUG |
226 | if (attr) | |
227 | printf(" *%s %s/%s: \"%s\"\n", attr->name, attr->spec, attr->text, | |
228 | attr->value ? attr->value : ""); | |
229 | else | |
230 | puts(" NOT FOUND"); | |
231 | #endif /* DEBUG */ | |
232 | ||
fa73b229 | 233 | /* |
234 | * Return text if we find it... | |
235 | */ | |
236 | ||
237 | return (attr ? attr->text : NULL); | |
238 | } | |
239 | ||
240 | ||
241 | /* | |
f42414bf | 242 | * End of "$Id: localize.c 6388 2007-03-24 14:21:31Z mike $". |
fa73b229 | 243 | */ |