Updated 2012-06-24 03:55:11 by RLE

[Lectus]: This is a page to post ideas for internationalizing Tcl/Tk applications.

Here is one example:

main.tcl
#!/usr/bin/tclsh

# import Tk package
package require Tk 8.5
# make it beautiful on Linux
if {$tcl_platform(os) == "Linux"} {ttk::setTheme clam}

## Begin supported languages
#set ::lang EN
set ::lang ES
#set ::lang DE
## End supported languages

# Load language packs with a simple source command
# English is default
source es.lang
source de.lang


# Procedure to read from language array
proc _t {text} {
  switch -- $::lang {
    EN { return $text }
    ES { return $::words_es($text) }
    DE { return $::words_de($text) }
  }
}
# End

## Begin GUI code
ttk::frame .f
pack .f -fill both -expand 1

set f [ttk::frame .f.fwidgets]
ttk::label $f.lName -text "[_t Name]: "
ttk::entry $f.eName
ttk::label $f.lPhone -text "[_t Phone]: "
ttk::entry $f.ePhone

pack $f -fill both -expand 1
grid $f.lName $f.eName -padx 5 -pady 2
grid $f.lPhone $f.ePhone -padx 5 -pady 2

set f2 [ttk::frame .f.fbuttons]
ttk::button $f2.ok -text [_t OK]
ttk::button $f2.cancel -text [_t "Exit application"] -command exit

pack $f2 -fill x -expand 1
grid $f2.ok $f2.cancel -padx 5 -pady 5

Following translations were created using Google translate. They may be wrong.

Language packs are simple files with Tcl arrays:

es.lang
## Begin Spanish dictionary
array set ::words_es {
"Name" "Nombre"
"Phone" "Teléfono"
"Exit application" "Salir de la aplicación"
"OK" "OK"
}
## End

de.lang
## Begin German dictionary
array set ::words_de {
"Name" "Name"
"Phone" "Telefon"
"Exit application" "Anwendung beenden"
"OK" "OK"
}
## End

When I created this I was not aware there's a standard way to do this: msgcat