Translations
A ztk app shows its texts in the language of its user with the msgcat package of Tcl: each text goes through mc, and a table for each locale gives its translation. The ztcl page Translations has the commands of msgcat: locales and the fallback, the arguments of a text, plurals, and message files. This page covers the parts of a window: a menu that changes the language at once, the menus, the dialogs, and dates.
| English | German |
|---|---|
![]() |
![]() |
The example
examples/i18n.tcl has a window in English, Spanish, German, French, and Chinese:
ztk examples/i18n.tcl
ztk examples/i18n.tcl --lang de --date 1795996800
With no --lang, the window starts in the locale of msgcat: the first of LC_ALL, LC_MESSAGES, and LANG of the environment. The menu Language lists each language in its own name, and a choice changes each text of the window at once.
Change the language at once
A widget keeps the text that it got, so a change of the locale changes no text by itself. The app keeps the English source texts in its code, and one proc sets each text again from them:
package require msgcat
namespace import msgcat::mc
proc relabel {} {
wm title . [mc Translations]
.menu entryconfigure 0 -label [mc File]
.menu.file entryconfigure 0 -label [mc "New message"]
.body.hello configure -text [mc "Hello, %1\$s!" Ana]
}
# The command of each entry of the menu Language.
proc setLang {} {
msgcat::mclocale $::lang
relabel
}
.menu.lang add radiobutton -label Deutsch -value de -variable lang -command setLang
A menu changes by the index of each entry: entryconfigure finds an entry by its index or by a pattern of its label, and the label changes with the language. Make the menu bar with -tearoff 0, so the first cascade has the index 0, as in Tk.
The dialogs
The dialogs that ztk draws take their texts from the messages of the namespace ::tk, as the dialogs of Tk do: the buttons OK, Cancel, Yes, and No, and the default titles such as Open and Save As. An app gives the texts of its locales there:
namespace eval ::tk {
::msgcat::mcmset de {OK OK Cancel Abbrechen Yes Ja No Nein}
::msgcat::mcmset fr {OK OK Cancel Annuler Yes Oui No Non}
}
The title and the message of a dialog are arguments of the app, so the app passes [mc ...]. ztk draws tk_messageBox, tk_dialog, and tk_chooseColor on Linux, on the web, and in a headless run, and the file dialogs where the desktop has none. A native dialog, such as each dialog of Windows and the file dialog of the portal of Linux, has the texts of the language of the system.
Dates
clock format with -locale gives the names of the days and the months of a locale. ztcl has the names of English only, so the example gives the names of its other locales with mcset in the namespace ::tcl::clock (the ztcl page):
namespace eval ::tcl::clock {
::msgcat::mcset de DAYS_OF_WEEK_FULL {Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag}
::msgcat::mcset de MONTHS_FULL {Januar Februar März April Mai Juni Juli August September Oktober November Dezember}
}
.body.date configure -text [clock format $t -format "%A, %e. %B %Y" -locale [msgcat::mclocale]]
Fonts
On Windows and macOS, the text engine of the system (DirectWrite, Core Text) draws the text with the fonts of the system. The built-in text path of Linux, the web, and headless runs draws only the glyphs of its fonts, which have no Chinese: a run there shows a box for each such character. ZTK_EMOJI_FONT names one more font file for that path, such as a font with the glyphs of Chinese.
Differences from Tk
- Tk ships message files with the texts of its dialogs in many languages. ztk ships none: an app gives the texts of its locales in
::tk.

