This is not necessarily the current version of this TIP.
| TIP: | 399 |
| Title: | Dynamic Locale Changing for msgcat |
| Version: | $Revision: 1.1 $ |
| Author: | Harald Oehlmann <Harald dot Oehlmann at elmicron dot de> |
| State: | Draft |
| Type: | Project |
| Tcl-Version: | 8.6 |
| Vote: | Pending |
| Created: | Tuesday, 27 March 2012 |
| Keywords: | Tcl, localization |
This TIP adds dynamic locale switching to the msgcat package.
The msgcat package has a 3 stage processing model:
mclocale locale
mcload catalog
mc key args...
If the locale should be changed after other packages are loaded, one must restart at step 2.
Within a multi-language application like a web-server, one may change the language quite quickly, for example if users with different locales are requesting pages.
The issue is that mcload only loads language files included in the current locale (mcpreferences) and does not load any others.
The aim of this tip is to extend mcload to load additional language files. Then mclocale may be called to change the language on runtime.
This TIP proposes to add a new command:
msgcat::mcconfig -pattern ?patternlist?
This command may get or set package options. There is currently one option "-pattern". Options may be set using
msgcat::mcconfig option value ?option? ?value?
Current option values may be read using:
msgcat::mcconfig option
The option '-pattern consists of a list of language file name patterns like fr*, *, fr_ch.
Initialise msgcat within an application which supports the current user language and french, german and english.
package require msgcat 1.5
msgcat::mcconfig -pattern {fr.* de.* en.*}
# require any other package
package require BWidget
# switch to french
msgcat::mclocale fr
See Tcl Feature Request 3511941. [1]
No incompatibilities are introduced
This implementation requires the setting of the pattern before any package with msgcat is loaded. To avoid this, msgcat must store all paths passed by any mcload call. In case of a locale change, any currently missing files are loaded. This requires much more housekeeping and may lead to side effects, especially if packages are not aware of the fact that their package files are loaded outside of the mcload command.
This document has been placed in the public domain.
This is not necessarily the current version of this TIP.