![]() | ![]() | ![]() | ![]() |
Tcl8.5.7/Tk8.5.7 Documentation > TclCmd > msgcatTcl/Tk Applications | Tcl Commands | Tk Commands | Tcl Library | Tk Library
NAMEmsgcat - Tcl message catalogSYNOPSISpackage require Tcl 8.5package require msgcat 1.4.2 ::msgcat::mc src-string ?arg arg ...? ::msgcat::mcmax ?src-string src-string ...? ::msgcat::mclocale ?newLocale? ::msgcat::mcpreferences ::msgcat::mcload dirname ::msgcat::mcset locale src-string ?translate-string? ::msgcat::mcmset locale src-trans-list ::msgcat::mcunknown locale src-string DESCRIPTIONThe msgcat package provides a set of functions that can be used to manage multi-lingual user interfaces. Text strings are defined in a “message catalog” which is independent from the application, and which can be edited or localized without modifying the application source code. New languages or locales are provided by adding a new file to the message catalog.Use of the message catalog is optional by any application or package, but is encouraged if the application or package wishes to be enabled for multi-lingual applications. COMMANDS
LOCALE SPECIFICATIONThe locale is specified to msgcat by a locale string passed to ::msgcat::mclocale. The locale string consists of a language code, an optional country code, and an optional system-specific code, each separated by “_”. The country and language codes are specified in standards ISO-639 and ISO-3166. For example, the locale “en” specifies English and “en_US” specifies U.S. English.When the msgcat package is first loaded, the locale is initialized according to the user's environment. The variables env(LC_ALL), env(LC_MESSAGES), and env(LANG) 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 language[_country][.codeset][@modifier]to extract its parts. The initial locale is then set by calling ::msgcat::mclocale with the argument language[_country][_modifier]On Windows, if none of those environment variables is set, msgcat will attempt to extract locale information from the registry. If all these attempts to discover an initial locale from the user's environment fail, msgcat defaults to an initial locale of “C”. When a locale is specified by the user, a “best match” search is performed during string translation. For example, if a user specifies en_GB_Funky, the locales “en_GB_Funky”, “en_GB”, “en” and “” (the empty string) are searched in order until a matching translation string is found. If no translation string is available, then ::msgcat::mcunknown is called. NAMESPACES AND MESSAGE CATALOGSStrings stored in the message catalog are stored relative to the namespace from which they were added. This allows multiple packages to use the same strings without fear of collisions with other packages. It also allows the source string to be shorter and less prone to typographical error.For example, executing the code ::msgcat::mcset en hello "hello from ::"
namespace eval foo {
::msgcat::mcset en hello "hello from ::foo"
}
puts [::msgcat::mc hello]
namespace eval foo {puts [::msgcat::mc hello]}
will print
hello from :: hello from ::foo When searching for a translation of a message, the message catalog will search first the current namespace, then the parent of the current namespace, and so on until the global namespace is reached. This allows child namespaces to “inherit” messages from their parent namespace. For example, executing (in the “en” locale) the code ::msgcat::mcset en m1 ":: message1"
::msgcat::mcset en m2 ":: message2"
::msgcat::mcset en m3 ":: message3"
namespace eval ::foo {
::msgcat::mcset en m2 "::foo message2"
::msgcat::mcset en m3 "::foo message3"
}
namespace eval ::foo::bar {
::msgcat::mcset en m3 "::foo::bar message3"
}
namespace import ::msgcat::mc
puts "[mc m1]; [mc m2]; [mc m3]"
namespace eval ::foo {puts "[mc m1]; [mc m2]; [mc m3]"}
namespace eval ::foo::bar {puts "[mc m1]; [mc m2]; [mc m3]"}
will print
:: message1; :: message2; :: message3 :: message1; ::foo message2; ::foo message3 :: message1; ::foo message2; ::foo::bar message3 LOCATION AND FORMAT OF MESSAGE FILESMessage files can be located in any directory, subject to the following conditions:
RECOMMENDED MESSAGE SETUP FOR PACKAGESIf a package is installed into a subdirectory of the tcl_pkgPath and loaded via package require, the following procedure is recommended.
POSITIONAL CODES FOR FORMAT AND SCAN COMMANDSIt is possible that a message string used as an argument to format 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.format "We produced %d units in location %s" $num $city format "In location %s we produced %d units" $city $num This can be handled by using the positional parameters: format "We produced %1\$d units in location %2\$s" $num $city format "In location %2\$s we produced %1\$d units" $num $city Similarly, positional parameters can be used with scan to extract values from internationalized strings. CREDITSThe message catalog code was developed by Mark Harrison.SEE ALSOformat, scan, namespace, packageKEYWORDSinternationalization, i18n, localization, l10n, message, text, translationCopyright © 1995-1997 Roger E. Critchlow Jr.
Copyright © 1998 Mark Harrison.
|