summaryrefslogtreecommitdiffstats
path: root/doc/msgcat.n
diff options
context:
space:
mode:
Diffstat (limited to 'doc/msgcat.n')
-rw-r--r--doc/msgcat.n91
1 files changed, 73 insertions, 18 deletions
diff --git a/doc/msgcat.n b/doc/msgcat.n
index c2c0abd..af6be7f 100644
--- a/doc/msgcat.n
+++ b/doc/msgcat.n
@@ -13,7 +13,7 @@ msgcat \- Tcl message catalog
.SH SYNOPSIS
\fBpackage require Tcl 8.5\fR
.sp
-\fBpackage require msgcat 1.4.5\fR
+\fBpackage require msgcat 1.5.0\fR
.sp
\fB::msgcat::mc \fIsrc-string\fR ?\fIarg arg ...\fR?
.sp
@@ -29,6 +29,12 @@ msgcat \- Tcl message catalog
.sp
\fB::msgcat::mcmset \fIlocale src-trans-list\fR
.sp
+.VS "TIP 404"
+\fB::msgcat::mcflset \fIsrc-string \fR?\fItranslate-string\fR?
+.sp
+\fB::msgcat::mcflmset \fIsrc-trans-list\fR
+.VE "TIP 404"
+.sp
\fB::msgcat::mcunknown \fIlocale src-string\fR
.BE
.SH DESCRIPTION
@@ -49,6 +55,7 @@ wishes to be enabled for multi-lingual applications.
.SH COMMANDS
.TP
\fB::msgcat::mc \fIsrc-string\fR ?\fIarg arg ...\fR?
+.
Returns a translation of \fIsrc-string\fR according to the
user's current locale. If additional arguments past \fIsrc-string\fR
are given, the \fBformat\fR command is used to substitute the
@@ -71,12 +78,14 @@ later simply by defining new message catalog entries.
.RE
.TP
\fB::msgcat::mcmax ?\fIsrc-string src-string ...\fR?
+.
Given several source strings, \fB::msgcat::mcmax\fR returns the length
of the longest translated string. This is useful when designing
localized GUIs, which may require that all buttons, for example, be a
fixed width (which will be the width of the widest button).
.TP
-\fB::msgcat::mclocale \fR?\fInewLocale\fR?
+\fB::msgcat::mclocale \fR?\fInewLocale\fR?
+.
This function sets the locale to \fInewLocale\fR. If \fInewLocale\fR
is omitted, the current locale is returned, otherwise the current locale
is set to \fInewLocale\fR. msgcat stores and compares the locale in a
@@ -86,6 +95,7 @@ the user's environment. See \fBLOCALE SPECIFICATION\fR
below for a description of the locale string format.
.TP
\fB::msgcat::mcpreferences\fR
+.
Returns an ordered list of the locales preferred by
the user, based on the user's language specification.
The list is ordered from most specific to least
@@ -93,11 +103,10 @@ preference. The list is derived from the current
locale set in msgcat by \fB::msgcat::mclocale\fR, and
cannot be set independently. For example, if the
current locale is en_US_funky, then \fB::msgcat::mcpreferences\fR
-.VS 1.4
returns \fB{en_US_funky en_US en {}}\fR.
-.VE 1.4
.TP
\fB::msgcat::mcload \fIdirname\fR
+.
Searches the specified directory for files that match
the language specifications returned by \fB::msgcat::mcpreferences\fR
(note that these are all lowercase), extended by the file extension
@@ -111,12 +120,14 @@ evaluation. The number of message files which matched the specification
and were loaded is returned.
.TP
\fB::msgcat::mcset \fIlocale src-string \fR?\fItranslate-string\fR?
+.
Sets the translation for \fIsrc-string\fR to \fItranslate-string\fR
in the specified \fIlocale\fR and the current namespace. If
\fItranslate-string\fR is not specified, \fIsrc-string\fR is used
for both. The function returns \fItranslate-string\fR.
.TP
\fB::msgcat::mcmset \fIlocale src-trans-list\fR
+.
Sets the translation for multiple source strings in
\fIsrc-trans-list\fR in the specified \fIlocale\fR and the current
namespace.
@@ -126,7 +137,28 @@ translate-string ...\fR?} \fB::msgcat::mcmset\fR can be significantly
faster than multiple invocations of \fB::msgcat::mcset\fR. The function
returns the number of translations set.
.TP
+\fB::msgcat::mcflset \fIsrc-string \fR?\fItranslate-string\fR?
+.VS "TIP 404"
+Sets the translation for \fIsrc-string\fR to \fItranslate-string\fR in the
+current namespace for the locale implied by the name of the message catalog
+being loaded via \fB::msgcat::mcload\fR. If \fItranslate-string\fR is not
+specified, \fIsrc-string\fR is used for both. The function returns
+\fItranslate-string\fR.
+.VE "TIP 404"
+.TP
+\fB::msgcat::mcflmset \fIsrc-trans-list\fR
+.VS "TIP 404"
+Sets the translation for multiple source strings in \fIsrc-trans-list\fR in
+the current namespace for the locale implied by the name of the message
+catalog being loaded via \fB::msgcat::mcload\fR. \fIsrc-trans-list\fR must
+have an even number of elements and is in the form {\fIsrc-string
+translate-string\fR ?\fIsrc-string translate-string ...\fR?}
+\fB::msgcat::mcflmset\fR can be significantly faster than multiple invocations
+of \fB::msgcat::mcflset\fR. The function returns the number of translations set.
+.VE "TIP 404"
+.TP
\fB::msgcat::mcunknown \fIlocale src-string\fR
+.
This routine is called by \fB::msgcat::mc\fR in the case when
a translation for \fIsrc-string\fR is not defined in the
current locale. The default action is to return
@@ -157,14 +189,18 @@ according to the user's environment. The variables \fBenv(LC_ALL)\fR,
\fBenv(LC_MESSAGES)\fR, and \fBenv(LANG)\fR are examined in order.
The first of them to have a non-empty value is used to determine the
initial locale. The value is parsed according to the XPG4 pattern
+.PP
.CS
language[_country][.codeset][@modifier]
.CE
+.PP
to extract its parts. The initial locale is then set by calling
\fB::msgcat::mclocale\fR with the argument
+.PP
.CS
language[_country][_modifier]
.CE
+.PP
On Windows and Cygwin, if none of those environment variables is set,
msgcat will attempt to extract locale information from the registry.
From Windows Vista on, the RFC4747 locale name "lang-script-country-options"
@@ -179,7 +215,6 @@ When a locale is specified by the user, a
.QW "best match"
search is performed during string translation. For example, if a user
specifies
-.VS 1.4
en_GB_Funky, the locales
.QW en_GB_Funky ,
.QW en_GB ,
@@ -187,7 +222,6 @@ en_GB_Funky, the locales
and
.MT
(the empty string)
-.VE 1.4
are searched in order until a matching translation
string is found. If no translation string is available, then
\fB::msgcat::mcunknown\fR is called.
@@ -201,15 +235,18 @@ source string to be shorter and less prone to typographical
error.
.PP
For example, executing the code
+.PP
.CS
\fB::msgcat::mcset\fR en hello "hello from ::"
namespace eval foo {
- \fB::msgcat::mcset\fR en hello "hello from ::foo"
+ \fB::msgcat::mcset\fR en hello "hello from ::foo"
}
puts [\fB::msgcat::mc\fR hello]
namespace eval foo {puts [\fB::msgcat::mc\fR hello]}
.CE
+.PP
will print
+.PP
.CS
hello from ::
hello from ::foo
@@ -225,23 +262,26 @@ messages from their parent namespace.
For example, executing (in the
.QW en
locale) the code
+.PP
.CS
\fB::msgcat::mcset\fR en m1 ":: message1"
\fB::msgcat::mcset\fR en m2 ":: message2"
\fB::msgcat::mcset\fR en m3 ":: message3"
namespace eval ::foo {
- \fB::msgcat::mcset\fR en m2 "::foo message2"
- \fB::msgcat::mcset\fR en m3 "::foo message3"
+ \fB::msgcat::mcset\fR en m2 "::foo message2"
+ \fB::msgcat::mcset\fR en m3 "::foo message3"
}
namespace eval ::foo::bar {
- \fB::msgcat::mcset\fR en m3 "::foo::bar message3"
+ \fB::msgcat::mcset\fR en m3 "::foo::bar message3"
}
namespace import \fB::msgcat::mc\fR
puts "[\fBmc\fR m1]; [\fBmc\fR m2]; [\fBmc\fR m3]"
namespace eval ::foo {puts "[\fBmc\fR m1]; [\fBmc\fR m2]; [\fBmc\fR m3]"}
namespace eval ::foo::bar {puts "[\fBmc\fR m1]; [\fBmc\fR m2]; [\fBmc\fR m3]"}
.CE
+.PP
will print
+.PP
.CS
:: message1; :: message2; :: message3
:: message1; ::foo message2; ::foo message3
@@ -257,11 +297,12 @@ All message files for a package are in the same directory.
The message file name is a msgcat locale specifier (all lowercase) followed by
.QW .msg .
For example:
+.PP
.CS
es.msg \(em spanish
en_gb.msg \(em United Kingdom English
.CE
-.VS 1.4
+.PP
\fIException:\fR The message file for the root locale
.MT
is called
@@ -270,16 +311,16 @@ This exception is made so as not to
cause peculiar behavior, such as marking the message file as
.QW hidden
on Unix file systems.
-.VE 1.4
.IP [3]
-The file contains a series of calls to \fBmcset\fR and
-\fBmcmset\fR, setting the necessary translation strings
+The file contains a series of calls to \fBmcflset\fR and
+\fBmcflmset\fR, setting the necessary translation strings
for the language, likely enclosed in a \fBnamespace eval\fR
so that all source strings are tied to the namespace of
the package. For example, a short \fBes.msg\fR might contain:
+.PP
.CS
namespace eval ::mypackage {
- \fB::msgcat::mcset\fR es "Free Beer!" "Cerveza Gracias!"
+ \fB::msgcat::mcflset\fR "Free Beer!" "Cerveza Gracias!"
}
.CE
.SH "RECOMMENDED MESSAGE SETUP FOR PACKAGES"
@@ -293,8 +334,8 @@ During package installation, create a subdirectory
.IP [2]
Copy your *.msg files into that directory.
.IP [3]
- Add the following command to your package
-initialization script:
+Add the following command to your package initialization script:
+.PP
.CS
# load language files, stored in msgs subdirectory
\fB::msgcat::mcload\fR [file join [file dirname [info script]] msgs]
@@ -306,6 +347,7 @@ to \fBformat\fR might have positionally dependent parameters that
might need to be repositioned. For example, it might be
syntactically desirable to rearrange the sentence structure
while translating.
+.PP
.CS
format "We produced %d units in location %s" $num $city
format "In location %s we produced %d units" $city $num
@@ -313,13 +355,23 @@ format "In location %s we produced %d units" $city $num
.PP
This can be handled by using the positional
parameters:
+.PP
.CS
format "We produced %1\e$d units in location %2\e$s" $num $city
format "In location %2\e$s we produced %1\e$d units" $num $city
.CE
.PP
Similarly, positional parameters can be used with \fBscan\fR to
-extract values from internationalized strings.
+extract values from internationalized strings. Note that it is not
+necessary to pass the output of \fB::msgcat::mc\fR to \fBformat\fR
+directly; by passing the values to substitute in as arguments, the
+formatting substitution is done directly.
+.PP
+.CS
+\fBmsgcat::mc\fR {Produced %1$d at %2$s} $num $city
+# ... where that key is mapped to one of the
+# human-oriented versions by \fBmsgcat::mcset\fR
+.CE
.SH CREDITS
.PP
The message catalog code was developed by Mark Harrison.
@@ -327,3 +379,6 @@ The message catalog code was developed by Mark Harrison.
format(n), scan(n), namespace(n), package(n)
.SH KEYWORDS
internationalization, i18n, localization, l10n, message, text, translation
+.\" Local Variables:
+.\" mode: nroff
+.\" End: