Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / man / mann / msgcat.n
CommitLineData
86530b38
AT
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'\" SCCS: @(#) msgcat.n
8'\"
9'\" The definitions below are for supplemental macros used in Tcl/Tk
10'\" manual entries.
11'\"
12'\" .AP type name in/out ?indent?
13'\" Start paragraph describing an argument to a library procedure.
14'\" type is type of argument (int, etc.), in/out is either "in", "out",
15'\" or "in/out" to describe whether procedure reads or modifies arg,
16'\" and indent is equivalent to second arg of .IP (shouldn't ever be
17'\" needed; use .AS below instead)
18'\"
19'\" .AS ?type? ?name?
20'\" Give maximum sizes of arguments for setting tab stops. Type and
21'\" name are examples of largest possible arguments that will be passed
22'\" to .AP later. If args are omitted, default tab stops are used.
23'\"
24'\" .BS
25'\" Start box enclosure. From here until next .BE, everything will be
26'\" enclosed in one large box.
27'\"
28'\" .BE
29'\" End of box enclosure.
30'\"
31'\" .CS
32'\" Begin code excerpt.
33'\"
34'\" .CE
35'\" End code excerpt.
36'\"
37'\" .VS ?version? ?br?
38'\" Begin vertical sidebar, for use in marking newly-changed parts
39'\" of man pages. The first argument is ignored and used for recording
40'\" the version when the .VS was added, so that the sidebars can be
41'\" found and removed when they reach a certain age. If another argument
42'\" is present, then a line break is forced before starting the sidebar.
43'\"
44'\" .VE
45'\" End of vertical sidebar.
46'\"
47'\" .DS
48'\" Begin an indented unfilled display.
49'\"
50'\" .DE
51'\" End of indented unfilled display.
52'\"
53'\" .SO
54'\" Start of list of standard options for a Tk widget. The
55'\" options follow on successive lines, in four columns separated
56'\" by tabs.
57'\"
58'\" .SE
59'\" End of list of standard options for a Tk widget.
60'\"
61'\" .OP cmdName dbName dbClass
62'\" Start of description of a specific option. cmdName gives the
63'\" option's name as specified in the class command, dbName gives
64'\" the option's name in the option database, and dbClass gives
65'\" the option's class in the option database.
66'\"
67'\" .UL arg1 arg2
68'\" Print arg1 underlined, then print arg2 normally.
69'\"
70'\" RCS: @(#) $Id: man.macros,v 1.4 2000/08/25 06:18:32 ericm Exp $
71'\"
72'\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
73.if t .wh -1.3i ^B
74.nr ^l \n(.l
75.ad b
76'\" # Start an argument description
77.de AP
78.ie !"\\$4"" .TP \\$4
79.el \{\
80. ie !"\\$2"" .TP \\n()Cu
81. el .TP 15
82.\}
83.ta \\n()Au \\n()Bu
84.ie !"\\$3"" \{\
85\&\\$1 \\fI\\$2\\fP (\\$3)
86.\".b
87.\}
88.el \{\
89.br
90.ie !"\\$2"" \{\
91\&\\$1 \\fI\\$2\\fP
92.\}
93.el \{\
94\&\\fI\\$1\\fP
95.\}
96.\}
97..
98'\" # define tabbing values for .AP
99.de AS
100.nr )A 10n
101.if !"\\$1"" .nr )A \\w'\\$1'u+3n
102.nr )B \\n()Au+15n
103.\"
104.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
105.nr )C \\n()Bu+\\w'(in/out)'u+2n
106..
107.AS Tcl_Interp Tcl_CreateInterp in/out
108'\" # BS - start boxed text
109'\" # ^y = starting y location
110'\" # ^b = 1
111.de BS
112.br
113.mk ^y
114.nr ^b 1u
115.if n .nf
116.if n .ti 0
117.if n \l'\\n(.lu\(ul'
118.if n .fi
119..
120'\" # BE - end boxed text (draw box now)
121.de BE
122.nf
123.ti 0
124.mk ^t
125.ie n \l'\\n(^lu\(ul'
126.el \{\
127.\" Draw four-sided box normally, but don't draw top of
128.\" box if the box started on an earlier page.
129.ie !\\n(^b-1 \{\
130\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
131.\}
132.el \}\
133\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
134.\}
135.\}
136.fi
137.br
138.nr ^b 0
139..
140'\" # VS - start vertical sidebar
141'\" # ^Y = starting y location
142'\" # ^v = 1 (for troff; for nroff this doesn't matter)
143.de VS
144.if !"\\$2"" .br
145.mk ^Y
146.ie n 'mc \s12\(br\s0
147.el .nr ^v 1u
148..
149'\" # VE - end of vertical sidebar
150.de VE
151.ie n 'mc
152.el \{\
153.ev 2
154.nf
155.ti 0
156.mk ^t
157\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
158.sp -1
159.fi
160.ev
161.\}
162.nr ^v 0
163..
164'\" # Special macro to handle page bottom: finish off current
165'\" # box/sidebar if in box/sidebar mode, then invoked standard
166'\" # page bottom macro.
167.de ^B
168.ev 2
169'ti 0
170'nf
171.mk ^t
172.if \\n(^b \{\
173.\" Draw three-sided box if this is the box's first page,
174.\" draw two sides but no top otherwise.
175.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
176.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
177.\}
178.if \\n(^v \{\
179.nr ^x \\n(^tu+1v-\\n(^Yu
180\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
181.\}
182.bp
183'fi
184.ev
185.if \\n(^b \{\
186.mk ^y
187.nr ^b 2
188.\}
189.if \\n(^v \{\
190.mk ^Y
191.\}
192..
193'\" # DS - begin display
194.de DS
195.RS
196.nf
197.sp
198..
199'\" # DE - end display
200.de DE
201.fi
202.RE
203.sp
204..
205'\" # SO - start of list of standard options
206.de SO
207.SH "STANDARD OPTIONS"
208.LP
209.nf
210.ta 5.5c 11c
211.ft B
212..
213'\" # SE - end of list of standard options
214.de SE
215.fi
216.ft R
217.LP
218See the \\fBoptions\\fR manual entry for details on the standard options.
219..
220'\" # OP - start of full description for a single option
221.de OP
222.LP
223.nf
224.ta 4c
225Command-Line Name: \\fB\\$1\\fR
226Database Name: \\fB\\$2\\fR
227Database Class: \\fB\\$3\\fR
228.fi
229.IP
230..
231'\" # CS - begin code excerpt
232.de CS
233.RS
234.nf
235.ta .25i .5i .75i 1i
236..
237'\" # CE - end code excerpt
238.de CE
239.fi
240.RE
241..
242.de UL
243\\$1\l'|0\(ul'\\$2
244..
245.TH "msgcat" n 1.3 msgcat "Tcl Bundled Packages"
246.BS
247'\" Note: do not modify the .SH NAME line immediately below!
248.SH NAME
249msgcat \- Tcl message catalog
250.SH SYNOPSIS
251\fBpackage require Tcl 8.2\fR
252.sp
253\fBpackage require msgcat 1.3\fR
254.sp
255\fB::msgcat::mc \fIsrc-string\fR ?\fIarg arg ...\fR?
256.sp
257\fB::msgcat::mcmax ?\fIsrc-string src-string ...\fR?
258.sp
259\fB::msgcat::mclocale \fR?\fInewLocale\fR?
260.sp
261\fB::msgcat::mcpreferences\fR
262.sp
263\fB::msgcat::mcload \fIdirname\fR
264.sp
265\fB::msgcat::mcset \fIlocale src-string \fR?\fItranslate-string\fR?
266.sp
267\fB::msgcat::mcmset \fIlocale src-trans-list\fR
268.sp
269\fB::msgcat::mcunknown \fIlocale src-string\fR
270.BE
271
272.SH DESCRIPTION
273.PP
274The \fBmsgcat\fR package provides a set of functions
275that can be used to manage multi-lingual user interfaces.
276Text strings are defined in a ``message catalog'' which
277is independent from the application, and
278which can be edited or localized without modifying
279the application source code. New languages
280or locales are provided by adding a new file to
281the message catalog.
282.PP
283Use of the message catalog is optional by any application
284or package, but is encouraged if the application or package
285wishes to be enabled for multi-lingual applications.
286.SH COMMANDS
287.TP
288\fB::msgcat::mc \fIsrc-string\fR ?\fIarg arg ...\fR?
289Returns a translation of \fIsrc-string\fR according to the
290user's current locale. If additional arguments past \fIsrc-string\fR
291are given, the \fBformat\fR command is used to substitute the
292additional arguments in the translation of \fIsrc-string\fR.
293.PP
294\fB::msgcat::mc\fR will search the messages defined
295in the current namespace for a translation of \fIsrc-string\fR; if
296none is found, it will search in the parent of the current namespace,
297and so on until it reaches the global namespace. If no translation
298string exists, \fB::msgcat::mcunknown\fR is called and the string
299returned from \fB::msgcat::mcunknown\fR is returned.
300.PP
301\fB::msgcat::mc\fR is the main function used to localize an
302application. Instead of using an English string directly, an
303application can pass the English string through \fB::msgcat::mc\fR and
304use the result. If an application is written for a single language in
305this fashion, then it is easy to add support for additional languages
306later simply by defining new message catalog entries.
307.TP
308\fB::msgcat::mcmax ?\fIsrc-string src-string ...\fR?
309Given several source strings, \fB::msgcat::mcmax\fR returns the length
310of the longest translated string. This is useful when designing
311localized GUIs, which may require that all buttons, for example, be a
312fixed width (which will be the width of the widest button).
313.TP
314\fB::msgcat::mclocale \fR?\fInewLocale\fR?
315This function sets the locale to \fInewLocale\fR. If \fInewLocale\fR
316is omitted, the current locale is returned, otherwise the current locale
317is set to \fInewLocale\fR. msgcat stores and compares the locale in a
318case-insensitive manner, and returns locales in lowercase.
319The initial locale is determined by the locale specified in
320the user's environment. See \fBLOCALE SPECIFICATION\fR
321below for a description of the locale string format.
322.TP
323\fB::msgcat::mcpreferences\fR
324Returns an ordered list of the locales preferred by
325the user, based on the user's language specification.
326The list is ordered from most specific to least
327preference. The list is derived from the current
328locale set in msgcat by \fB::msgcat::mclocale\fR, and
329cannot be set independently. For example, if the
330current locale is en_US_funky, then \fB::msgcat::mcpreferences\fR
331returns \fB{en_US_funky en_US en}\fR.
332.TP
333\fB::msgcat::mcload \fIdirname\fR
334Searches the specified directory for files that match
335the language specifications returned by \fB::msgcat::mcpreferences\fR
336(note that these are all lowercase), extended by the file
337extension ``.msg''. Each matching file is
338read in order, assuming a UTF-8 encoding. The file contents are
339then evaluated as a Tcl script. This means that Unicode characters
340may be present in the message file either directly in their UTF-8
341encoded form, or by use of the backslash-u quoting recognized by Tcl
342evaluation. The number of message files which matched the specification
343and were loaded is returned.
344.TP
345\fB::msgcat::mcset \fIlocale src-string \fR?\fItranslate-string\fR?
346Sets the translation for \fIsrc-string\fR to \fItranslate-string\fR
347in the specified \fIlocale\fR and the current namespace. If
348\fItranslate-string\fR is not specified, \fIsrc-string\fR is used
349for both. The function returns \fItranslate-string\fR.
350.TP
351\fB::msgcat::mcmset \fIlocale src-trans-list\fR
352Sets the translation for multiple source strings in
353\fIsrc-trans-list\fR in the specified \fIlocale\fR and the current
354namespace.
355\fIsrc-trans-list\fR must have an even number of elements and is in
356the form {\fIsrc-string translate-string\fR ?\fIsrc-string
357translate-string ...\fR?} \fB::msgcat::mcmset\fR can be significantly
358faster than multiple invocations of \fB::msgcat::mcset\fR. The function
359returns the number of translations set.
360.TP
361\fB::msgcat::mcunknown \fIlocale src-string\fR
362This routine is called by \fB::msgcat::mc\fR in the case when
363a translation for \fIsrc-string\fR is not defined in the
364current locale. The default action is to return
365\fIsrc-string\fR. This procedure can be redefined by the
366application, for example to log error messages for each unknown
367string. The \fB::msgcat::mcunknown\fR procedure is invoked at the
368same stack context as the call to \fB::msgcat::mc\fR. The return value
369of \fB::msgcat::mcunknown\fR is used as the return value for the call
370to \fB::msgcat::mc\fR.
371.SH "LOCALE SPECIFICATION"
372.PP
373The locale is specified to \fBmsgcat\fR by a locale string
374passed to \fB::msgcat::mclocale\fR.
375The locale string consists of
376a language code, an optional country code, and an optional
377system-specific code, each separated by ``_''. The country and language
378codes are specified in standards ISO-639 and ISO-3166.
379For example, the locale ``en'' specifies English and ``en_US'' specifies
380U.S. English.
381.PP
382When the msgcat package is first loaded, the locale is initialized
383according to the user's environment. The variables \fBenv(LC_ALL)\fR,
384\fBenv(LC_MESSAGES)\fR, and \fBenv(LANG)\fR are examined in order.
385The first of them to have a non-empty value is used to determine the
386initial locale. The value is parsed according to the XPG4 pattern
387.CS
388language[_country][.codeset][@modifier]
389.CE
390to extract its parts. The initial locale is then set by calling
391\fB::msgcat::mclocale\fR with the argument
392.CS
393language[_country][_modifier]
394.CE
395On Windows, if none of those environment variables is set, msgcat will
396attempt to extract locale information from the
397registry. If all these attempts to discover an initial locale
398from the user's environment fail, msgcat defaults to an initial
399locale of ``C''.
400.PP
401When a locale is specified by the user, a ``best match'' search is
402performed during string translation. For example, if a user specifies
403en_GB_Funky, the locales ``en_GB_Funky'', ``en_GB'', and ``en'' are
404searched in order until a matching translation string is found. If no
405translation string is available, then \fB::msgcat::unknown\fR is
406called.
407.SH "NAMESPACES AND MESSAGE CATALOGS"
408.PP
409Strings stored in the message catalog are stored relative
410to the namespace from which they were added. This allows
411multiple packages to use the same strings without fear
412of collisions with other packages. It also allows the
413source string to be shorter and less prone to typographical
414error.
415.PP
416For example, executing the code
417.CS
418\fB::msgcat::mcset\fR en hello "hello from ::"
419namespace eval foo {
420 \fB::msgcat::mcset\fR en hello "hello from ::foo"
421}
422puts [\fB::msgcat::mc\fR hello]
423namespace eval foo {puts [\fB::msgcat::mc\fR hello]}
424.CE
425will print
426.CS
427hello from ::
428hello from ::foo
429.CE
430.PP
431When searching for a translation of a message, the
432message catalog will search first the current namespace,
433then the parent of the current namespace, and so on until
434the global namespace is reached. This allows child namespaces
435to "inherit" messages from their parent namespace.
436.PP
437For example, executing (in the ``en'' locale) the code
438.CS
439\fB::msgcat::mcset\fR en m1 ":: message1"
440\fB::msgcat::mcset\fR en m2 ":: message2"
441\fB::msgcat::mcset\fR en m3 ":: message3"
442namespace eval ::foo {
443 \fB::msgcat::mcset\fR en m2 "::foo message2"
444 \fB::msgcat::mcset\fR en m3 "::foo message3"
445}
446namespace eval ::foo::bar {
447 \fB::msgcat::mcset\fR en m3 "::foo::bar message3"
448}
449namespace import \fB::msgcat::mc\fR
450puts "[\fBmc\fR m1]; [\fBmc\fR m2]; [\fBmc\fR m3]"
451namespace eval ::foo {puts "[\fBmc\fR m1]; [\fBmc\fR m2]; [\fBmc\fR m3]"}
452namespace eval ::foo::bar {puts "[\fBmc\fR m1]; [\fBmc\fR m2]; [\fBmc\fR m3]"}
453.CE
454will print
455.CS
456:: message1; :: message2; :: message3
457:: message1; ::foo message2; ::foo message3
458:: message1; ::foo message2; ::foo::bar message3
459.CE
460.SH "LOCATION AND FORMAT OF MESSAGE FILES"
461.PP
462Message files can be located in any directory, subject
463to the following conditions:
464.IP [1]
465All message files for a package are in the same directory.
466.IP [2]
467The message file name is a msgcat locale specifier (all lowercase)
468followed by ``.msg''. For example:
469.CS
470es.msg -- spanish
471en_gb.msg -- United Kingdom English
472.CE
473.IP [3]
474The file contains a series of calls to \fBmcset\fR and
475\fBmcmset\fR, setting the necessary translation strings
476for the language, likely enclosed in a \fBnamespace eval\fR
477so that all source strings are tied to the namespace of
478the package. For example, a short \fBes.msg\fR might contain:
479.CS
480namespace eval ::mypackage {
481 \fB::msgcat::mcset\fR es "Free Beer!" "Cerveza Gracias!"
482}
483.CE
484.SH "RECOMMENDED MESSAGE SETUP FOR PACKAGES"
485.PP
486If a package is installed into a subdirectory of the
487\fBtcl_pkgPath\fR and loaded via \fBpackage require\fR, the
488following procedure is recommended.
489.IP [1]
490During package installation, create a subdirectory
491\fBmsgs\fR under your package directory.
492.IP [2]
493Copy your *.msg files into that directory.
494.IP [3]
495 Add the following command to your package
496initialization script:
497.CS
498# load language files, stored in msgs subdirectory
499\fB::msgcat::mcload\fR [file join [file dirname [info script]] msgs]
500.CE
501.SH "POSITIONAL CODES FOR FORMAT AND SCAN COMMANDS"
502.PP
503It is possible that a message string used as an argument
504to \fBformat\fR might have positionally dependent parameters that
505might need to be repositioned. For example, it might be
506syntactically desirable to rearrange the sentence structure
507while translating.
508.CS
509format "We produced %d units in location %s" $num $city
510format "In location %s we produced %d units" $city $num
511.CE
512.PP
513This can be handled by using the positional
514parameters:
515.CS
516format "We produced %1\\$d units in location %2\\$s" $num $city
517format "In location %2\\$s we produced %1\\$d units" $num $city
518.CE
519.PP
520Similarly, positional parameters can be used with \fBscan\fR to
521extract values from internationalized strings.
522.SH CREDITS
523.PP
524The message catalog code was developed by Mark Harrison.
525
526.SH "SEE ALSO"
527format(n), scan(n), namespace(n), package(n)
528
529.SH KEYWORDS
530internationalization, i18n, localization, l10n, message, text, translation