Version 0 of Tk internationalization

Updated 2005-08-12 16:57:58

Although tcl has a general mechanism for internationalization, the msgcat package, some Tk widgets are not internationalized. I recently encountered this problem with tk_optionMenu. The problem is that the labels on radiobuttons are the same as the values, which in many cases forces the use of English names since the values must be meaningful to other functions. Here's an internationalized version of tk_optionMenu.

#Internationalized version of tk_optionMenu. proc OptionMenu {w varName firstValue args} {

    upvar #0 $varName var

    if {![info exists var]} {
        set var $firstValue
    }
    menubutton $w -text [::msgcat::mc $firstValue] -indicatoron 1 -menu $w.menu \
            -relief raised -bd 2 -highlightthickness 2 -anchor c \
            -direction flush
    menu $w.menu -tearoff 0
    $w.menu add radiobutton -label [::msgcat::mc $firstValue] -variable $varName \
            -command "UpdateOptionMenuLabel $w $varName"
    foreach i $args {
            $w.menu add radiobutton -label [::msgcat::mc $i] -variable $varName\
            -command "UpdateOptionMenuLabel $w $varName"
    }
    return $w.menu

}

proc UpdateOptionMenuLabel {w v} {

    upvar #0 $v x
    $w configure -text [::msgcat::mc $x]

}