]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/localize.c
2 * "$Id: localize.c 177 2006-06-21 00:20:03Z jlovell $"
4 * PPD custom option routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
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
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * PostScript is a trademark of Adobe Systems, Inc.
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
33 * This file is subject to the Apple OS-Developed Software exception.
37 * ppdLocalize() - Localize the PPD file to the current locale.
41 * Include necessary headers.
52 static const char *ppd_text(ppd_file_t
*ppd
, const char *keyword
,
53 const char *spec
, const char *ll_CC
,
58 * 'ppdLocalize()' - Localize the PPD file to the current locale.
63 int /* O - 0 on success, -1 on error */
64 ppdLocalize(ppd_file_t
*ppd
) /* I - PPD file */
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 */
80 * Range check input...
87 * Get the default language...
90 if ((lang
= cupsLangDefault()) == NULL
)
93 strlcpy(ll_CC
, lang
->language
, sizeof(ll_CC
));
94 strlcpy(ll
, lang
->language
, sizeof(ll
));
97 * Now lookup all of the groups, options, choices, etc.
100 for (i
= ppd
->num_groups
, group
= ppd
->groups
; i
> 0; i
--, group
++)
102 if ((text
= ppd_text(ppd
, "Translation", group
->name
, ll_CC
, ll
)) != NULL
)
103 strlcpy(group
->text
, text
, sizeof(group
->text
));
105 for (j
= group
->num_options
, option
= group
->options
; j
> 0; j
--, option
++)
107 if ((text
= ppd_text(ppd
, "Translation", option
->keyword
, ll_CC
,
109 strlcpy(option
->text
, text
, sizeof(option
->text
));
111 for (k
= option
->num_choices
, choice
= option
->choices
;
115 if (strcmp(choice
->choice
, "Custom"))
116 text
= ppd_text(ppd
, option
->keyword
, choice
->choice
, ll_CC
, ll
);
119 snprintf(ckeyword
, sizeof(ckeyword
), "Custom%s", option
->keyword
);
121 text
= ppd_text(ppd
, ckeyword
, "True", ll_CC
, ll
);
125 strlcpy(choice
->text
, text
, sizeof(choice
->text
));
131 * Translate any custom parameters...
134 for (coption
= (ppd_coption_t
*)cupsArrayFirst(ppd
->coptions
);
136 coption
= (ppd_coption_t
*)cupsArrayNext(ppd
->coptions
))
138 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
140 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
142 snprintf(ckeyword
, sizeof(ckeyword
), "ParamCustom%s", coption
->keyword
);
144 if ((text
= ppd_text(ppd
, ckeyword
, cparam
->name
, ll_CC
, ll
)) != NULL
)
145 strlcpy(cparam
->text
, text
, sizeof(cparam
->text
));
154 * 'ppd_text()' - Find the localized text as needed...
157 static const char * /* O - Localized text or NULL */
158 ppd_text(ppd_file_t
*ppd
, /* I - PPD file */
159 const char *keyword
, /* I - Main keyword */
160 const char *spec
, /* I - Option keyword */
161 const char *ll_CC
, /* I - Language + country locale */
162 const char *ll
) /* I - Language locale */
164 char lkeyword
[PPD_MAX_NAME
]; /* Localization keyword */
165 ppd_attr_t
*attr
; /* Current attribute */
169 * Look for Keyword.ll_CC, then Keyword.ll...
172 snprintf(lkeyword
, sizeof(lkeyword
), "%s.%s", keyword
, ll_CC
);
173 if ((attr
= ppdFindAttr(ppd
, lkeyword
, spec
)) == NULL
)
175 snprintf(lkeyword
, sizeof(lkeyword
), "%s.%s", keyword
, ll
);
176 attr
= ppdFindAttr(ppd
, lkeyword
, spec
);
180 * Return text if we find it...
183 return (attr
? attr
->text
: NULL
);
188 * End of "$Id: localize.c 177 2006-06-21 00:20:03Z jlovell $".