"Fossies" - the Fresh Open Source Software Archive

Member "SAOImageDS9/tcl8.6/doc/msgcat.n" (13 Nov 2019, 23444 Bytes) of package /linux/misc/ds9.8.1.tar.gz:


Caution: As a special service "Fossies" has tried to format the requested manual source page into HTML format but links to other man pages may be missing or even erroneous. Alternatively you can here view or download the uninterpreted manual source code. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

msgcat

NAME
SYNOPSIS
DESCRIPTION
COMMANDS
LOCALE SPECIFICATION

NAME

msgcat − Tcl message catalog

SYNOPSIS

package require Tcl 8.5

package require msgcat 1.6

::msgcat::mc src-string ?arg arg ...?

::msgcat::mcmax ?src-string src-string ...?

::msgcat::mcexists ?-exactnamespace? ?-exactlocale? src-string

::msgcat::mclocale ?newLocale?

::msgcat::mcpreferences

::msgcat::mcloadedlocales subcommand ?locale?

::msgcat::mcload dirname

::msgcat::mcset locale src-string ?translate-string?

::msgcat::mcmset locale src-trans-list

::msgcat::mcflset src-string ?translate-string?

::msgcat::mcflmset src-trans-list

::msgcat::mcunknown locale src-string ?arg arg ...?

::msgcat::mcpackagelocale subcommand ?locale?

::msgcat::mcpackageconfig subcommand option ?value?

::msgcat::mcforgetpackage

DESCRIPTION

The msgcat package provides a set of functions that can be used to manage multi-lingual user interfaces. Text strings are defined in a which is independent from the application, and which can be edited or localized without modifying the application source code. New languages or locales may be provided by adding a new file to the message catalog.

msgcat distinguises packages by its namespace. Each package has its own message catalog and configuration settings in msgcat.

A locale is a specification string describing a user language like de_ch for Swiss German. In msgcat, there is a global locale initialized by the system locale of the current system. Each package may decide to use the global locale or to use a package specific locale.

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.

COMMANDS

::msgcat::mc src-string ?arg arg ...?

Returns a translation of src-string according to the current locale. If additional arguments past src-string are given, the format command is used to substitute the additional arguments in the translation of src-string.

::msgcat::mc will search the messages defined in the current namespace for a translation of src-string; if none is found, it will search in the parent of the current namespace, and so on until it reaches the global namespace. If no translation string exists, ::msgcat::mcunknown is called and the string returned from ::msgcat::mcunknown is returned.

::msgcat::mc is the main function used to localize an application. Instead of using an English string directly, an application can pass the English string through ::msgcat::mc and use the result. If an application is written for a single language in this fashion, then it is easy to add support for additional languages later simply by defining new message catalog entries.

::msgcat::mcmax ?src-string src-string ...?

Given several source strings, ::msgcat::mcmax 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).

::msgcat::mcexists ?-exactnamespace? ?-exactlocale? src-string

Return true, if there is a translation for the given src-string.

The search may be limited by the option −exactnamespace to only check the current namespace and not any parent namespaces.

It may also be limited by the option −exactlocale to only check the first prefered locale (e.g. first element returned by ::msgcat::mcpreferences if global locale is used).

::msgcat::mclocale ?newLocale?

This function sets the locale to newLocale. If newLocale is omitted, the current locale is returned, otherwise the current locale is set to newLocale. msgcat stores and compares the locale in a case-insensitive manner, and returns locales in lowercase. The initial locale is determined by the locale specified in the user’s environment. See LOCALE SPECIFICATION below for a description of the locale string format.

If the locale is set, the preference list of locales is evaluated. Locales in this list are loaded now, if not jet loaded.

::msgcat::mcpreferences

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 preference. The list is derived from the current locale set in msgcat by ::msgcat::mclocale, and cannot be set independently. For example, if the current locale is en_US_funky, then ::msgcat::mcpreferences returns {en_us_funky en_us en {}}.

::msgcat:mcloadedlocales subcommand ?locale?

This group of commands manage the list of loaded locales for packages not setting a package locale.

The subcommand get returns the list of currently loaded locales.

The subcommand present requires the argument locale and returns true, if this locale is loaded.

The subcommand clear removes all locales and their data, which are not in the current preference list.

::msgcat::mcload dirname

Searches the specified directory for files that match the language specifications returned by ::msgcat::mcloadedlocales get (or msgcat::mcpackagelocale preferences if a package locale is set) (note that these are all lowercase), extended by the file extension Each matching file is read in order, assuming a UTF-8 encoding. The file contents are then evaluated as a Tcl script. This means that Unicode characters may be present in the message file either directly in their UTF-8 encoded form, or by use of the backslash-u quoting recognized by Tcl evaluation. The number of message files which matched the specification and were loaded is returned.

In addition, the given folder is stored in the msgcat package configuration option mcfolder to eventually load message catalog files required by a locale change.

::msgcat::mcset locale src-string ?translate-string?

Sets the translation for src-string to translate-string in the specified locale and the current namespace. If translate-string is not specified, src-string is used for both. The function returns translate-string.

::msgcat::mcmset locale src-trans-list

Sets the translation for multiple source strings in src-trans-list in the specified locale and the current namespace. src-trans-list must have an even number of elements and is in the form {src-string translate-string ?src-string translate-string ...?} ::msgcat::mcmset can be significantly faster than multiple invocations of ::msgcat::mcset. The function returns the number of translations set.

::msgcat::mcflset src-string ?translate-string?

Sets the translation for src-string to translate-string in the current namespace for the locale implied by the name of the message catalog being loaded via ::msgcat::mcload. If translate-string is not specified, src-string is used for both. The function returns translate-string.

::msgcat::mcflmset src-trans-list

Sets the translation for multiple source strings in src-trans-list in the current namespace for the locale implied by the name of the message catalog being loaded via ::msgcat::mcload. src-trans-list must have an even number of elements and is in the form {src-string translate-string ?src-string translate-string ...?} ::msgcat::mcflmset can be significantly faster than multiple invocations of ::msgcat::mcflset. The function returns the number of translations set.

::msgcat::mcunknown locale src-string ?arg arg ...?

This routine is called by ::msgcat::mc in the case when a translation for src-string is not defined in the current locale. The default action is to return src-string passed by format if there are any arguments. This procedure can be redefined by the application, for example to log error messages for each unknown string. The ::msgcat::mcunknown procedure is invoked at the same stack context as the call to ::msgcat::mc. The return value of ::msgcat::mcunknown is used as the return value for the call to ::msgcat::mc.

Note that this routine is only called if the concerned package did not set a package locale unknown command name.

::msgcat::mcforgetpackage

The calling package clears all its state within the msgcat package including all settings and translations.

LOCALE SPECIFICATION

The 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 specifies English and 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 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" is transformed to the locale as "lang_country_script" (Example: sr-Latn-CS -> sr_cs_latin). For Windows XP, the language id is transformed analoguously (Example: 0c1a -> sr_yu_cyrillic). If all these attempts to discover an initial locale from the user’s environment fail, msgcat defaults to an initial locale of

When a locale is specified by the user, a search is performed during string translation. For example, if a user specifies en_GB_Funky, the