]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/localize.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / localize.c
1 /*
2 * "$Id: localize.c 4937 2006-01-17 04:03:22Z mike $"
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
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.
59 */
60
61 int /* O - 0 on success, -1 on error */
62 ppdLocalize(ppd_file_t *ppd) /* I - PPD file */
63 {
64 int i, j, k; /* Looping vars */
65 ppd_group_t *group; /* Current group */
66 ppd_option_t *option; /* Current option */
67 ppd_choice_t *choice; /* Current choice */
68 ppd_coption_t *coption; /* Current custom option */
69 ppd_cparam_t *cparam; /* Current custom parameter */
70 cups_lang_t *lang; /* Current language */
71 char ckeyword[PPD_MAX_NAME], /* Custom keyword */
72 ll_CC[6], /* Language + country locale */
73 ll[3]; /* Language locale */
74 const char *text; /* Localized text */
75
76
77 /*
78 * Range check input...
79 */
80
81 if (!ppd)
82 return (-1);
83
84 /*
85 * Get the default language...
86 */
87
88 if ((lang = cupsLangDefault()) == NULL)
89 return (-1);
90
91 strlcpy(ll_CC, lang->language, sizeof(ll_CC));
92 strlcpy(ll, lang->language, sizeof(ll));
93
94 /*
95 * Now lookup all of the groups, options, choices, etc.
96 */
97
98 for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++)
99 {
100 if ((text = ppd_text(ppd, "Translation", group->name, ll_CC, ll)) != NULL)
101 strlcpy(group->text, text, sizeof(group->text));
102
103 for (j = group->num_options, option = group->options; j > 0; j --, option ++)
104 {
105 if ((text = ppd_text(ppd, "Translation", option->keyword, ll_CC,
106 ll)) != NULL)
107 strlcpy(option->text, text, sizeof(option->text));
108
109 for (k = option->num_choices, choice = option->choices;
110 k > 0;
111 k --, choice ++)
112 {
113 if (strcmp(choice->choice, "Custom"))
114 text = ppd_text(ppd, option->keyword, choice->choice, ll_CC, ll);
115 else
116 {
117 snprintf(ckeyword, sizeof(ckeyword), "Custom%s", option->keyword);
118
119 text = ppd_text(ppd, ckeyword, "True", ll_CC, ll);
120 }
121
122 if (text)
123 strlcpy(choice->text, text, sizeof(choice->text));
124 }
125 }
126 }
127
128 /*
129 * Translate any custom parameters...
130 */
131
132 for (coption = (ppd_coption_t *)cupsArrayFirst(ppd->coptions);
133 coption;
134 coption = (ppd_coption_t *)cupsArrayNext(ppd->coptions))
135 {
136 for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
137 cparam;
138 cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
139 {
140 snprintf(ckeyword, sizeof(ckeyword), "ParamCustom%s", coption->keyword);
141
142 if ((text = ppd_text(ppd, ckeyword, cparam->name, ll_CC, ll)) != NULL)
143 strlcpy(cparam->text, text, sizeof(cparam->text));
144 }
145 }
146
147 return (0);
148 }
149
150
151 /*
152 * 'ppd_text()' - Find the localized text as needed...
153 */
154
155 static const char * /* O - Localized text or NULL */
156 ppd_text(ppd_file_t *ppd, /* I - PPD file */
157 const char *keyword, /* I - Main keyword */
158 const char *spec, /* I - Option keyword */
159 const char *ll_CC, /* I - Language + country locale */
160 const char *ll) /* I - Language locale */
161 {
162 char lkeyword[PPD_MAX_NAME]; /* Localization keyword */
163 ppd_attr_t *attr; /* Current attribute */
164
165
166 /*
167 * Look for Keyword.ll_CC, then Keyword.ll...
168 */
169
170 snprintf(lkeyword, sizeof(lkeyword), "%s.%s", keyword, ll_CC);
171 if ((attr = ppdFindAttr(ppd, lkeyword, spec)) == NULL)
172 {
173 snprintf(lkeyword, sizeof(lkeyword), "%s.%s", keyword, ll);
174 attr = ppdFindAttr(ppd, lkeyword, spec);
175 }
176
177 /*
178 * Return text if we find it...
179 */
180
181 return (attr ? attr->text : NULL);
182 }
183
184
185 /*
186 * End of "$Id: localize.c 4937 2006-01-17 04:03:22Z mike $".
187 */