OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/base.git] / util / src / TclTk / tcl8.6.12 / doc / msgcat.n
1 '\"
2 '\" Copyright (c) 1998 Mark Harrison.
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\"
7 .TH "msgcat" n 1.5 msgcat "Tcl Bundled Packages"
8 .so man.macros
9 .BS
10 '\" Note:  do not modify the .SH NAME line immediately below!
11 .SH NAME
12 msgcat \- Tcl message catalog
13 .SH SYNOPSIS
14 \fBpackage require Tcl 8.5\fR
15 .sp
16 \fBpackage require msgcat 1.6\fR
17 .sp
18 \fB::msgcat::mc \fIsrc-string\fR ?\fIarg arg ...\fR?
19 .sp
20 \fB::msgcat::mcmax ?\fIsrc-string src-string ...\fR?
21 .sp
22 .VS "TIP 412"
23 \fB::msgcat::mcexists\fR ?\fB-exactnamespace\fR? ?\fB-exactlocale\fR? \fIsrc-string\fR
24 .VE "TIP 412"
25 .sp
26 \fB::msgcat::mclocale \fR?\fInewLocale\fR?
27 .sp
28 \fB::msgcat::mcpreferences\fR
29 .sp
30 .VS "TIP 412"
31 \fB::msgcat::mcloadedlocales subcommand\fR ?\fIlocale\fR?
32 .VE "TIP 412"
33 .sp
34 \fB::msgcat::mcload \fIdirname\fR
35 .sp
36 \fB::msgcat::mcset \fIlocale src-string \fR?\fItranslate-string\fR?
37 .sp
38 \fB::msgcat::mcmset \fIlocale src-trans-list\fR
39 .sp
40 \fB::msgcat::mcflset \fIsrc-string \fR?\fItranslate-string\fR?
41 .sp
42 \fB::msgcat::mcflmset \fIsrc-trans-list\fR
43 .sp
44 \fB::msgcat::mcunknown \fIlocale src-string\fR ?\fIarg arg ...\fR?
45 .sp
46 .VS "TIP 412"
47 \fB::msgcat::mcpackagelocale subcommand\fR ?\fIlocale\fR?
48 .sp
49 \fB::msgcat::mcpackageconfig subcommand\fR \fIoption\fR ?\fIvalue\fR?
50 .sp
51 \fB::msgcat::mcforgetpackage\fR
52 .VE "TIP 412"
53 .BE
54 .SH DESCRIPTION
55 .PP
56 The \fBmsgcat\fR package provides a set of functions
57 that can be used to manage multi-lingual user interfaces.
58 Text strings are defined in a
59 .QW "message catalog"
60 which is independent from the application, and
61 which can be edited or localized without modifying
62 the application source code.  New languages
63 or locales may be provided by adding a new file to
64 the message catalog.
65 .PP
66 \fBmsgcat\fR distinguises packages by its namespace.
67 Each package has its own message catalog and configuration settings in \fBmsgcat\fR.
68 .PP
69 A \fIlocale\fR is a specification string describing a user language like \fBde_ch\fR for Swiss German.
70 In \fBmsgcat\fR, there is a global locale initialized by the system locale of the current system.
71 Each package may decide to use the global locale or to use a package specific locale.
72 .PP
73 The global locale may be changed on demand, for example by a user initiated language change or within a multi user application like a web server.
74 .SH COMMANDS
75 .TP
76 \fB::msgcat::mc \fIsrc-string\fR ?\fIarg arg ...\fR?
77 .
78 Returns a translation of \fIsrc-string\fR according to the
79 current locale.  If additional arguments past \fIsrc-string\fR
80 are given, the \fBformat\fR command is used to substitute the
81 additional arguments in the translation of \fIsrc-string\fR.
82 .RS
83 .PP
84 \fB::msgcat::mc\fR will search the messages defined
85 in the current namespace for a translation of \fIsrc-string\fR; if
86 none is found, it will search in the parent of the current namespace,
87 and so on until it reaches the global namespace.  If no translation
88 string exists, \fB::msgcat::mcunknown\fR is called and the string
89 returned from \fB::msgcat::mcunknown\fR is returned.
90 .PP
91 \fB::msgcat::mc\fR is the main function used to localize an
92 application.  Instead of using an English string directly, an
93 application can pass the English string through \fB::msgcat::mc\fR and
94 use the result.  If an application is written for a single language in
95 this fashion, then it is easy to add support for additional languages
96 later simply by defining new message catalog entries.
97 .RE
98 .TP
99 \fB::msgcat::mcmax ?\fIsrc-string src-string ...\fR?
100 .
101 Given several source strings, \fB::msgcat::mcmax\fR returns the length
102 of the longest translated string.  This is useful when designing
103 localized GUIs, which may require that all buttons, for example, be a
104 fixed width (which will be the width of the widest button).
105 .TP
106 \fB::msgcat::mcexists\fR ?\fB-exactnamespace\fR? ?\fB-exactlocale\fR? \fIsrc-string\fR
107 .
108 .VS "TIP 412"
109 Return true, if there is a translation for the given \fIsrc-string\fR.
110 .PP
111 .RS
112 The search may be limited by the option \fB\-exactnamespace\fR to only check the current namespace and not any parent namespaces.
113 .PP
114 It may also be limited by the option \fB\-exactlocale\fR to only check the first prefered locale (e.g. first element returned by \fB::msgcat::mcpreferences\fR if global locale is used).
115 .RE
116 .VE "TIP 412"
117 .TP
118 \fB::msgcat::mclocale \fR?\fInewLocale\fR?
119 .
120 This function sets the locale to \fInewLocale\fR.  If \fInewLocale\fR
121 is omitted, the current locale is returned, otherwise the current locale
122 is set to \fInewLocale\fR.  msgcat stores and compares the locale in a
123 case-insensitive manner, and returns locales in lowercase.
124 The initial locale is determined by the locale specified in
125 the user's environment.  See \fBLOCALE SPECIFICATION\fR
126 below for a description of the locale string format.
127 .RS
128 .PP
129 .VS "TIP 412"
130 If the locale is set, the preference list of locales is evaluated.
131 Locales in this list are loaded now, if not jet loaded.
132 .VE "TIP 412"
133 .RE
134 .TP
135 \fB::msgcat::mcpreferences\fR
136 .
137 Returns an ordered list of the locales preferred by
138 the user, based on the user's language specification.
139 The list is ordered from most specific to least
140 preference.  The list is derived from the current
141 locale set in msgcat by \fB::msgcat::mclocale\fR, and
142 cannot be set independently.  For example, if the
143 current locale is en_US_funky, then \fB::msgcat::mcpreferences\fR
144 returns \fB{en_us_funky en_us en {}}\fR.
145 .TP
146 \fB::msgcat::mcloadedlocales subcommand\fR ?\fIlocale\fR?
147 .
148 This group of commands manage the list of loaded locales for packages not setting a package locale.
149 .PP
150 .RS
151 The subcommand \fBget\fR returns the list of currently loaded locales.
152 .PP
153 The subcommand \fBpresent\fR requires the argument \fIlocale\fR and returns true, if this locale is loaded.
154 .PP
155 The subcommand \fBclear\fR removes all locales and their data, which are not in the current preference list.
156 .RE
157 .TP
158 \fB::msgcat::mcload \fIdirname\fR
159 .
160 .VS "TIP 412"
161 Searches the specified directory for files that match
162 the language specifications returned by \fB::msgcat::mcloadedlocales get\fR
163 (or \fBmsgcat::mcpackagelocale preferences\fR if a package locale is set) (note that these are all lowercase), extended by the file extension
164 .QW .msg .
165 Each matching file is
166 read in order, assuming a UTF-8 encoding.  The file contents are
167 then evaluated as a Tcl script.  This means that Unicode characters
168 may be present in the message file either directly in their UTF-8
169 encoded form, or by use of the backslash-u quoting recognized by Tcl
170 evaluation.  The number of message files which matched the specification
171 and were loaded is returned.
172 .RS
173 .PP
174 In addition, the given folder is stored in the \fBmsgcat\fR package configuration option \fImcfolder\fR to eventually load message catalog files required by a locale change.
175 .VE "TIP 412"
176 .RE
177 .TP
178 \fB::msgcat::mcset \fIlocale src-string \fR?\fItranslate-string\fR?
179 .
180 Sets the translation for \fIsrc-string\fR to \fItranslate-string\fR
181 in the specified \fIlocale\fR and the current namespace.  If
182 \fItranslate-string\fR is not specified, \fIsrc-string\fR is used
183 for both.  The function returns \fItranslate-string\fR.
184 .TP
185 \fB::msgcat::mcmset \fIlocale src-trans-list\fR
186 .
187 Sets the translation for multiple source strings in
188 \fIsrc-trans-list\fR in the specified \fIlocale\fR and the current
189 namespace.
190 \fIsrc-trans-list\fR must have an even number of elements and is in
191 the form {\fIsrc-string translate-string\fR ?\fIsrc-string
192 translate-string ...\fR?} \fB::msgcat::mcmset\fR can be significantly
193 faster than multiple invocations of \fB::msgcat::mcset\fR. The function
194 returns the number of translations set.
195 .TP
196 \fB::msgcat::mcflset \fIsrc-string \fR?\fItranslate-string\fR?
197 Sets the translation for \fIsrc-string\fR to \fItranslate-string\fR in the
198 current namespace for the locale implied by the name of the message catalog
199 being loaded via \fB::msgcat::mcload\fR.  If \fItranslate-string\fR is not
200 specified, \fIsrc-string\fR is used for both.  The function returns
201 \fItranslate-string\fR.
202 .TP
203 \fB::msgcat::mcflmset \fIsrc-trans-list\fR
204 Sets the translation for multiple source strings in \fIsrc-trans-list\fR in
205 the current namespace for the locale implied by the name of the message
206 catalog being loaded via \fB::msgcat::mcload\fR. \fIsrc-trans-list\fR must
207 have an even number of elements and is in the form {\fIsrc-string
208 translate-string\fR ?\fIsrc-string translate-string ...\fR?}
209 \fB::msgcat::mcflmset\fR can be significantly faster than multiple invocations
210 of \fB::msgcat::mcflset\fR. The function returns the number of translations set.
211 .TP
212 \fB::msgcat::mcunknown \fIlocale src-string\fR ?\fIarg arg ...\fR?
213 .
214 This routine is called by \fB::msgcat::mc\fR in the case when
215 a translation for \fIsrc-string\fR is not defined in the
216 current locale.  The default action is to return
217 \fIsrc-string\fR passed by format if there are any arguments.  This
218 procedure can be redefined by the
219 application, for example to log error messages for each unknown
220 string.  The \fB::msgcat::mcunknown\fR procedure is invoked at the
221 same stack context as the call to \fB::msgcat::mc\fR.  The return value
222 of \fB::msgcat::mcunknown\fR is used as the return value for the call
223 to \fB::msgcat::mc\fR.
224 .VS "TIP 412"
225 .RS
226 .PP
227 Note that this routine is only called if the concerned package did not set a package locale unknown command name.
228 .RE
229 .TP
230 \fB::msgcat::mcforgetpackage\fR
231 .
232 The calling package clears all its state within the \fBmsgcat\fR package including all settings and translations.
233 .VE "TIP 412"
234 .PP
235 .SH "LOCALE SPECIFICATION"
236 .PP
237 The locale is specified to \fBmsgcat\fR by a locale string
238 passed to \fB::msgcat::mclocale\fR.
239 The locale string consists of
240 a language code, an optional country code, and an optional
241 system-specific code, each separated by
242 .QW _ .
243 The country and language
244 codes are specified in standards ISO-639 and ISO-3166.
245 For example, the locale
246 .QW en
247 specifies English and
248 .QW en_US
249 specifies U.S. English.
250 .PP
251 When the msgcat package is first loaded, the locale is initialized
252 according to the user's environment.  The variables \fBenv(LC_ALL)\fR,
253 \fBenv(LC_MESSAGES)\fR, and \fBenv(LANG)\fR are examined in order.
254 The first of them to have a non-empty value is used to determine the
255 initial locale.  The value is parsed according to the XPG4 pattern
256 .PP
257 .CS
258 language[_country][.codeset][@modifier]
259 .CE
260 .PP
261 to extract its parts.  The initial locale is then set by calling
262 \fB::msgcat::mclocale\fR with the argument
263 .PP
264 .CS
265 language[_country][_modifier]
266 .CE
267 .PP
268 On Windows and Cygwin, if none of those environment variables is set,
269 msgcat will attempt to extract locale information from the registry.
270 From Windows Vista on, the RFC4747 locale name "lang-script-country-options"
271 is transformed to the locale as "lang_country_script" (Example:
272 sr-Latn-CS -> sr_cs_latin). For Windows XP, the language id is
273 transformed analoguously (Example: 0c1a -> sr_yu_cyrillic).
274 If all these attempts to discover an initial locale from the user's
275 environment fail, msgcat defaults to an initial locale of
276 .QW C .
277 .PP
278 When a locale is specified by the user, a
279 .QW "best match"
280 search is performed during string translation.  For example, if a user
281 specifies
282 en_GB_Funky, the locales
283 .QW en_gb_funky ,
284 .QW en_gb ,
285 .QW en
286 and
287 .MT
288 (the empty string)
289 are searched in order until a matching translation
290 string is found.  If no translation string is available, then
291 the unknown handler is called.
292 .SH "NAMESPACES AND MESSAGE CATALOGS"
293 .PP
294 Strings stored in the message catalog are stored relative
295 to the namespace from which they were added.  This allows
296 multiple packages to use the same strings without fear
297 of collisions with other packages.  It also allows the
298 source string to be shorter and less prone to typographical
299 error.
300 .PP
301 For example, executing the code
302 .PP
303 .CS
304 \fB::msgcat::mcset\fR en hello "hello from ::"
305 namespace eval foo {
306     \fB::msgcat::mcset\fR en hello "hello from ::foo"
307 }
308 puts [\fB::msgcat::mc\fR hello]
309 namespace eval foo {puts [\fB::msgcat::mc\fR hello]}
310 .CE
311 .PP
312 will print
313 .PP
314 .CS
315 hello from ::
316 hello from ::foo
317 .CE
318 .PP
319 When searching for a translation of a message, the
320 message catalog will search first the current namespace,
321 then the parent of the current namespace, and so on until
322 the global namespace is reached.  This allows child namespaces to
323 .QW inherit
324 messages from their parent namespace.
325 .PP
326 For example, executing (in the
327 .QW en
328 locale) the code
329 .PP
330 .CS
331 \fB::msgcat::mcset\fR en m1 ":: message1"
332 \fB::msgcat::mcset\fR en m2 ":: message2"
333 \fB::msgcat::mcset\fR en m3 ":: message3"
334 namespace eval ::foo {
335     \fB::msgcat::mcset\fR en m2 "::foo message2"
336     \fB::msgcat::mcset\fR en m3 "::foo message3"
337 }
338 namespace eval ::foo::bar {
339     \fB::msgcat::mcset\fR en m3 "::foo::bar message3"
340 }
341 namespace import \fB::msgcat::mc\fR
342 puts "[\fBmc\fR m1]; [\fBmc\fR m2]; [\fBmc\fR m3]"
343 namespace eval ::foo {puts "[\fBmc\fR m1]; [\fBmc\fR m2]; [\fBmc\fR m3]"}
344 namespace eval ::foo::bar {puts "[\fBmc\fR m1]; [\fBmc\fR m2]; [\fBmc\fR m3]"}
345 .CE
346 .PP
347 will print
348 .PP
349 .CS
350 :: message1; :: message2; :: message3
351 :: message1; ::foo message2; ::foo message3
352 :: message1; ::foo message2; ::foo::bar message3
353 .CE
354 .SH "LOCATION AND FORMAT OF MESSAGE FILES"
355 .PP
356 Message files can be located in any directory, subject
357 to the following conditions:
358 .IP [1]
359 All message files for a package are in the same directory.
360 .IP [2]
361 The message file name is a msgcat locale specifier (all lowercase) followed by
362 .QW .msg .
363 For example:
364 .PP
365 .CS
366 es.msg    \(em spanish
367 en_gb.msg \(em United Kingdom English
368 .CE
369 .PP
370 \fIException:\fR The message file for the root locale
371 .MT
372 is called
373 .QW \fBROOT.msg\fR .
374 This exception is made so as not to
375 cause peculiar behavior, such as marking the message file as
376 .QW hidden
377 on Unix file systems.
378 .IP [3]
379 The file contains a series of calls to \fBmcflset\fR and
380 \fBmcflmset\fR, setting the necessary translation strings
381 for the language, likely enclosed in a \fBnamespace eval\fR
382 so that all source strings are tied to the namespace of
383 the package. For example, a short \fBes.msg\fR might contain:
384 .PP
385 .CS
386 namespace eval ::mypackage {
387     \fB::msgcat::mcflset\fR "Free Beer" "Cerveza Gratis"
388 }
389 .CE
390 .SH "RECOMMENDED MESSAGE SETUP FOR PACKAGES"
391 .PP
392 If a package is installed into a subdirectory of the
393 \fBtcl_pkgPath\fR and loaded via \fBpackage require\fR, the
394 following procedure is recommended.
395 .IP [1]
396 During package installation, create a subdirectory
397 \fBmsgs\fR under your package directory.
398 .IP [2]
399 Copy your *.msg files into that directory.
400 .IP [3]
401 Add the following command to your package initialization script:
402 .PP
403 .CS
404 # load language files, stored in msgs subdirectory
405 \fB::msgcat::mcload\fR [file join [file dirname [info script]] msgs]
406 .CE
407 .SH "POSITIONAL CODES FOR FORMAT AND SCAN COMMANDS"
408 .PP
409 It is possible that a message string used as an argument
410 to \fBformat\fR might have positionally dependent parameters that
411 might need to be repositioned.  For example, it might be
412 syntactically desirable to rearrange the sentence structure
413 while translating.
414 .PP
415 .CS
416 format "We produced %d units in location %s" $num $city
417 format "In location %s we produced %d units" $city $num
418 .CE
419 .PP
420 This can be handled by using the positional
421 parameters:
422 .PP
423 .CS
424 format "We produced %1\e$d units in location %2\e$s" $num $city
425 format "In location %2\e$s we produced %1\e$d units" $num $city
426 .CE
427 .PP
428 Similarly, positional parameters can be used with \fBscan\fR to
429 extract values from internationalized strings. Note that it is not
430 necessary to pass the output of \fB::msgcat::mc\fR to \fBformat\fR
431 directly; by passing the values to substitute in as arguments, the
432 formatting substitution is done directly.
433 .PP
434 .CS
435 \fBmsgcat::mc\fR {Produced %1$d at %2$s} $num $city
436 # ... where that key is mapped to one of the
437 # human-oriented versions by \fBmsgcat::mcset\fR
438 .CE
439 .VS "TIP 412"
440 .SH Package private locale
441 .PP
442 A package using \fBmsgcat\fR may choose to use its own package private
443 locale and its own set of loaded locales, independent to the global
444 locale set by \fB::msgcat::mclocale\fR.
445 .PP
446 This allows a package to change its locale without causing any locales load or removal in other packages and not to invoke the global locale change callback (see below).
447 .PP
448 This action is controled by the following ensemble:
449 .TP
450 \fB::msgcat::mcpackagelocale set\fR ?\fIlocale\fR?
451 .
452 Set or change a package private locale.
453 The package private locale is set to the given \fIlocale\fR if the \fIlocale\fR is given.
454 If the option \fIlocale\fR is not given, the package is set to package private locale mode, but no locale is changed (e.g. if the global locale was valid for the package before, it is copied to the package private locale).
455 .PP
456 .RS
457 This command may cause the load of locales.
458 .RE
459 .TP
460 \fB::msgcat::mcpackagelocale get\fR
461 .
462 Return the package private locale or the global locale, if no package private locale is set.
463 .TP
464 \fB::msgcat::mcpackagelocale preferences\fR
465 .
466 Return the package private preferences or the global preferences,
467 if no package private locale is set.
468 .TP
469 \fB::msgcat::mcpackagelocale loaded\fR
470 .
471 Return the list of locales loaded for this package.
472 .TP
473 \fB::msgcat::mcpackagelocale isset\fR
474 .
475 Returns true, if a package private locale is set.
476 .TP
477 \fB::msgcat::mcpackagelocale unset\fR
478 .
479 Unset the package private locale and use the globale locale.
480 Load and remove locales to adjust the list of loaded locales for the
481 package to the global loaded locales list.
482 .TP
483 \fB::msgcat::mcpackagelocale present\fR \fIlocale\fR
484 .
485 Returns true, if the given locale is loaded for the package.
486 .TP
487 \fB::msgcat::mcpackagelocale clear\fR
488 .
489 Clear any loaded locales of the package not present in the package preferences.
490 .PP
491 .SH Changing package options
492 .PP
493 Each package using msgcat has a set of options within \fBmsgcat\fR.
494 The package options are described in the next sectionPackage options.
495 Each package option may be set or unset individually using the following ensemble:
496 .TP
497 \fB::msgcat::mcpackageconfig get\fR \fIoption\fR
498 .
499 Return the current value of the given \fIoption\fR.
500 This call returns an error if the option is not set for the package.
501 .TP
502 \fB::msgcat::mcpackageconfig isset\fR \fIoption\fR
503 .
504 Returns 1, if the given \fIoption\fR is set for the package, 0 otherwise.
505 .TP
506 \fB::msgcat::mcpackageconfig set\fR \fIoption\fR \fIvalue\fR
507 .
508 Set the given \fIoption\fR to the given \fIvalue\fR.
509 This may invoke additional actions in dependency of the \fIoption\fR.
510 The return value is 0 or the number of loaded packages for the option \fBmcfolder\fR.
511 .TP
512 \fB::msgcat::mcpackageconfig unset\fR \fIoption\fR
513 .
514 Unsets the given \fIoption\fR for the package.
515 No action is taken if the \fIoption\fR is not set for the package.
516 The empty string is returned.
517 .SS Package options
518 .PP
519 The following package options are available for each package:
520 .TP
521 \fBmcfolder\fR
522 .
523 This is the message folder of the package. This option is set by mcload and by the subcommand set. Both are identical and both return the number of loaded message catalog files.
524 .RS
525 .PP
526 Setting or changing this value will load all locales contained in the preferences valid for the package. This implies also to invoke any set loadcmd (see below).
527 .PP
528 Unsetting this value will disable message file load for the package.
529 .RE
530 .TP
531 \fBloadcmd\fR
532 .
533 This callback is invoked before a set of message catalog files are loaded for the package which has this property set.
534 .PP
535 .RS
536 This callback may be used to do any preparation work for message file load or to get the message data from another source like a data base. In this case, no message files are used (mcfolder is unset).
537 .PP
538 See section \fBcallback invocation\fR below.
539 The parameter list appended to this callback is the list of locales to load.
540 .PP
541 If this callback is changed, it is called with the preferences valid for the package.
542 .RE
543 .TP
544 \fBchangecmd\fR
545 .
546 This callback is invoked when a default local change was performed. Its purpose is to allow a package to update any dependency on the default locale like showing the GUI in another language.
547 .PP
548 .RS
549 See the callback invocation section below.
550 The parameter list appended to this callback is \fBmcpreferences\fR.
551 The registered callbacks are invoked in no particular order.
552 .RE
553 .TP
554 \fBunknowncmd\fR
555 .
556 Use a package locale mcunknown procedure instead of the standard version supplied by the msgcat package (msgcat::mcunknown).
557 .PP
558 .RS
559 The called procedure must return the formatted message which will finally be returned by msgcat::mc.
560 .PP
561 A generic unknown handler is used if set to the empty string. This consists in returning the key if no arguments are given. With given arguments, format is used to process the arguments.
562 .PP
563 See section \fBcallback invocation\fR below.
564 The appended arguments are identical to \fB::msgcat::mcunknown\fR.
565 .RE
566 .SS Callback invocation
567 A package may decide to register one or multiple callbacks, as described above.
568 .PP
569 Callbacks are invoked, if:
570 .PP
571 1. the callback command is set,
572 .PP
573 2. the command is not the empty string,
574 .PP
575 3. the registering namespace exists.
576 .PP
577 If a called routine fails with an error, the \fBbgerror\fR routine for the interpreter is invoked after command completion.
578 Only exception is the callback \fBunknowncmd\fR, where an error causes the invoking \fBmc\fR-command to fail with that error.
579 .PP
580 .SS Examples
581 Packages which display a GUI may update their widgets when the global locale changes.
582 To register to a callback, use:
583 .CS
584 namespace eval gui {
585     msgcat::mcpackageconfig changecmd updateGUI
586
587     proc updateGUI args {
588         puts "New locale is '[lindex $args 0]'."
589     }
590 }
591 % msgcat::mclocale fr
592 fr
593 % New locale is 'fr'.
594 .CE
595 .PP
596 If locales (or additional locales) are contained in another source like a data base, a package may use the load callback and not mcload:
597 .CS
598 namespace eval db {
599     msgcat::mcpackageconfig loadcmd loadMessages
600
601     proc loadMessages args {
602         foreach locale $args {
603             if {[LocaleInDB $locale]} {
604                 msgcat::mcmset $locale [GetLocaleList $locale]
605             }
606         }
607     }
608 }
609 .CE
610 .PP
611 The \fBclock\fR command implementation uses \fBmsgcat\fR with a package locale to implement the command line parameter \fB-locale\fR.
612 Here are some sketches of the implementation:
613 .PP
614 First, a package locale is initialized and the generic unknown function is desactivated:
615 .CS
616 msgcat::mcpackagelocale set
617 msgcat::mcpackageconfig unknowncmd ""
618 .CE
619 As an example, the user requires the week day in a certain locale as follows:
620 .CS
621 clock format [clock seconds] -format %A -locale fr
622 .CE
623 \fBclock\fR sets the package locale to \fBfr\fR and looks for the day name as follows:
624 .CS
625 msgcat::mcpackagelocale set $locale
626 return [lindex [msgcat::mc DAYS_OF_WEEK_FULL] $day]
627 ### Returns "mercredi"
628 .CE
629 Within \fBclock\fR, some message-catalog items are heavy in computation and thus are dynamically cached using:
630 .CS
631 proc ::tcl::clock::LocalizeFormat { locale format } {
632     set key FORMAT_$format
633     if { [::msgcat::mcexists -exactlocale -exactnamespace $key] } {
634         return [mc $key]
635     }
636     #...expensive computation of format clipped...
637     mcset $locale $key $format
638     return $format
639 }
640 .CE
641 .VE "TIP 412"
642 .SH CREDITS
643 .PP
644 The message catalog code was developed by Mark Harrison.
645 .SH "SEE ALSO"
646 format(n), scan(n), namespace(n), package(n)
647 .SH KEYWORDS
648 internationalization, i18n, localization, l10n, message, text, translation
649 .\" Local Variables:
650 .\" mode: nroff
651 .\" End: