There are different contents types in Tk. Here text and icons are of special interest. These contents is accessible through the properties of a window.
Jeszra generates Option Database entries for these properties, which allows customization and localization.
In addition, the Tk MsgCat package can be used. Usage and Local are defined inside the »MSG Catalog« preference page under the »Generate« section. The page is shown in Figure 7.3, “Message Catalog Preferences”.
The Message Catalog is loaded and the localized text stored in the Option Database. The generated code looks like Example 7.10, “Message Catalog Usage”.
Example 7.10. Message Catalog Usage
namespace eval top_1 { # Message Catalog # Requires Tcl/Tk version > 8.0 # Uses a subdirectory of project to locate the # Message Catalog for template 'top_1'. # namespace eval top_1 {} # package require msgcat namespace import ::msgcat::mc ::msgcat::mcload [file join \ [file dirname [info script] ] {top_1} ] option add *Top_1$w(1).text [mc {Test}] option add *Top_1$w(2).text \ [mc {Message Catalog}] ... }
It would be possible to incorporate the message catalog code generation to allow for dynamic language changes. To achieve dynamic language changes: all message catalog Option Database entries must be place inside a procedure and this procedure has to be called after the local changed. In addition, all instances of the given template must be notified and a Option Database lookup performed for all the relevant data.
I don’t think dynamic language changes is an important functionality, yet.
Message Catalog related Code Generation
proc dumper::resourceMsgCat { rwindow rname value } { return [subst -nocommands \ { option add $rwindow.$rname \ [mc "$value"];}] }
Create a Option Database entry for a message catalog string. The message catalog is always deployed this way! A namespace is required. The generated Tcl-code can still utilize X Resource Database & Option Database modifications. The Option Database code is much more efficient than using »mc« on the command line.
proc dumper::resourcesMsgCatT template {
return [subst -nocommands \
-nobackslashes \
{
# ...
package require msgcat
namespace import ::msgcat::mc
::msgcat::mcload [file join \
[file dirname \
[info script] ] \
{$template} ]
}]
}
The Message Catalog usage call; placed inside a namespace eval block.
In comparison to MsgCatT: The template version uses a subdirectory named after the template to search for the message catalog. The non-template version assumes the message catalog lies inside the project directory.
Both »resourceMsgCat« and »resourcesMsgCatT« are
parts of the Tcl-back end, implemented inside
vg26/library/tcldumper.tcl
.