tcl and language support

2 views
Skip to first unread message

Christoph Panwinkler

unread,
Apr 28, 1999, 3:00:00 AM4/28/99
to
Is there a possibility to configure widgets in specific language, e.g.
german language.
For example, I would like to configure the "yes" and "no" buttons of a
message box to "ja" and "nein".

Panny

--
| | |\ | | | \/ www : http://cscw1.inflab.uni-linz.ac.at/~panny/
|_ | | \| |_| /\ mail: mailto:pa...@cscw1.inflab.uni-linz.ac.at
tel : +43 (0)7211 8509
my favourite OS


Chang LI

unread,
Apr 28, 1999, 3:00:00 AM4/28/99
to
Christoph Panwinkler wrote:
>

Use Tcl8.1 and unicode

But I think the core should be modified for German error
message output. So it is better to have an international version Tcl for
each language.

--
--------------------------------------------------------------
Chang LI, Neatware
email: cha...@neatware.com
--------------------------------------------------------------

Marco R. Gazzetta

unread,
Apr 28, 1999, 3:00:00 AM4/28/99
to
Well,

Using Tcl 8.1 and Unicode won't help you in changing the text of a message
box, anyway.

Fortunately, as long as it is such a minor change to labels, you just have to
go to the directory where the Tk tcl-files are stored (tk/library) and play
around in the files stored there. For the message box, this would be
msgbox.tcl.

Just do a global search and replace of Ok, Cancel, Yes etc. with their
corresponding German translations, and you'll be fine. This works, by the way,
both for the source and install versions.

If you want to do a smart thing, create a global array that stores the words
in different languages, like in:

set Cat(de,Cancel) Abbrechen
set Cat(en,Cancel) Cancel

Then, instead of hard-wiring the strings in msgbox.tcl, you would add a
'global Cat LANG' statement at the beginning of each proc and replace, say
'-text Cancel' with '-text $Cat($LANG,Cancel)'.

At this point, you 'set LANG de', and Cancel will appear as Abbrechen,
whenever you create a message box box with a Cancel button.

And since you were so smart as to read this message, you are surely likely to
send the results of your change to Scriptics, so that they don't have to do
the work all by themselves...

Greets,

Marco

In article <372718...@neatware.com>,

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

lvi...@cas.org

unread,
Apr 28, 1999, 3:00:00 AM4/28/99
to

According to Chang LI <cha...@neatware.com>:
:Use Tcl8.1 and unicode

:
:But I think the core should be modified for German error
:message output. So it is better to have an international version Tcl for
:each language.

Tcl 8.1 includes the message catalog feature which provides the
frame work for localizing the scripts in one's tcl scripts.

When I read <URL: http://www.scriptics.com/software/8.1.html> I
see a reference to this. However, there is no mention that I see there
on whether Scriptics actually applied the technlogy to the
release.
--
<URL: mailto:lvi...@cas.org> Quote: Saving the world before bedtime.
<*> O- <URL: http://www.purl.org/NET/lvirden/>
Unless explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.

Scott Stanton

unread,
Apr 28, 1999, 3:00:00 AM4/28/99
to
lvi...@cas.org wrote:
> When I read <URL: http://www.scriptics.com/software/8.1.html> I
> see a reference to this. However, there is no mention that I see there
> on whether Scriptics actually applied the technlogy to the
> release.

We have not had the time to go back and change the Tk library to use message
catalogs. Obviously this would be a good thing to do, although there are some
installation/layout issues that would need to be resolved. Perhaps someone
would be willing to submit a patch for this?

___________________________________________________________
Scott Stanton 650-210-0105 tel
Sr. Software Engineer 650-210-0101 fax
Scriptics Corporation scott....@scriptics.com
The Tcl Platform Company http://www.scriptics.com

Eric Boudaillier

unread,
Apr 29, 1999, 3:00:00 AM4/29/99
to
Christoph Panwinkler wrote:
>
> Is there a possibility to configure widgets in specific language, e.g.
> german language.
> For example, I would like to configure the "yes" and "no" buttons of a
> message box to "ja" and "nein".

You can also use BWidget. It redifines button and label widget
to add (among other things) a -name option.
The value of this option is a token which reference a resource
defining both text and accelerator.
For example, for english language, we define the resource:
*cancelName: &Cancel
For german:
*cancelName: &Abbrechen
Source code is the same for both:
Button .b -name cancel

In a general manner, you can define any token:
*tokenName: Your &text

Button .b -name token
would display "Your text", with the letter t underlined and
<Alt-t> automatically binded to the toplevel.

For message dialog box, simply use:
MessageBox .msgdlg -type yesno -message "Hello, world"
MessageBox splits -type option into two buttons, the first
has its -name option set to yes, and the second to no.
The BWidget resource file de.rc defines the resources:
*yesName: &Ja
*noName: &Nein

--
Eric Boudaillier
Unifix
http://www.unifix-online.com/

Frederic BONNET

unread,
Apr 30, 1999, 3:00:00 AM4/30/99
to
Hi,

Christoph Panwinkler wrote:
> Is there a possibility to configure widgets in specific language, e.g.
> german language.
> For example, I would like to configure the "yes" and "no" buttons of a
> message box to "ja" and "nein".

Here's a quick and effective way of defining language-specific strings and even
changing them on the fly:

People usually specify widget strings using -text option:

label .l -text "blah"

However there is another method that, when cleverly used, can make multilingual
GUIs very easy to build. Most widgets that provide -text option also provide
-textvariable or similar option. The idea is to provide the name of a global
variable that contains the string, rather than the string itself:

label .l -textvariable var
set var "blah"

The advantage is that you can change widget strings with "set" rather than
"configure". You can also share strings between widgets.

Now let's see what happens if we choose to associate a widget to an array
element:

button .yes -textvariable Lang(Yes)
button .no -textvariable Lang(No)

The Tcl array syntax makes it very easy to set a series of array elements:

array set English {
Yes "Yes"
No "No"
}

With one line you can also set the values of an array to the values of another:

array set Lang [array get English]

The complete script:

# Create buttons with Lang array elements as textvariables
button .yes -textvariable Lang(Yes)
button .no -textvariable Lang(No)
pack .yes .no

# Define interface strings in several languages: associate
# symbolic names (eg. Yes) to language-specific values (eg. "Ja")
array set English {
Yes "Yes"
No "No"
}
array set Deutsch {
Yes "Ja"
No "Nein"
}

# Procedure to change language on the fly
proc setLang {newLang} {
global Lang $newLang
array set Lang [array get $newLang]
}
setLang English

Now type on the console and enjoy:

setLang Deutsch

That way you can build localizable apps very easily: you can put all the strings
for one language into one file and source it when needed. It also makes
translation very easy (you just have to translate one file).

See you, Fred
--
Frédéric BONNET frederi...@ciril.fr
---------------------------------------------------------------
"Theory may inform, but Practice convinces"
George Bain

Donald G Porter

unread,
Apr 30, 1999, 3:00:00 AM4/30/99
to
Christoph Panwinkler wrote:
>> Is there a possibility to configure widgets in specific language, e.g.
>> german language.

Frederic BONNET <frederi...@ciril.fr> wrote:
> Here's a quick and effective way of defining language-specific strings
> and even changing them on the fly:

[ snipped ]

For someone just starting on a project now, though, is there a strong
reason not to recommend that they use the msgcat package distributed
with Tcl 8.1 ? Although it is distributed only with Tcl 8.1, it is
perfectly compatible with Tcl 8.0.

--
| Don Porter, D.Sc. Mathematical and Computational Sciences Division |
| donald...@nist.gov Information Technology Laboratory |
| http://math.nist.gov/mcsd/Staff/DPorter/ NIST |
|______________________________________________________________________|

Frederic BONNET

unread,
May 2, 1999, 3:00:00 AM5/2/99
to
Hi Donal,

Donald G Porter wrote:
> For someone just starting on a project now, though, is there a strong
> reason not to recommend that they use the msgcat package distributed
> with Tcl 8.1 ? Although it is distributed only with Tcl 8.1, it is
> perfectly compatible with Tcl 8.0.

You can use both at a time: define and manage strings using msgcat, and define
widget strings with -textvariable rather than -text, so that you can write a
small msgcat-based proc that changes strings on the fly without having to know
where they are used in the widget tree. Just associate symbolic names with
localized strings using msgcat, build a corresponding array with these strings
(this can be done automatically) and use array elements as textvariables when
creating widgets.

Now that Tcl8.1 is officially released, users should of course move to msgcat
for building localized apps, but this hopefully doesn't prevent efficient use of
Tcl features (eg. variable traces like -textvariable).

we...@scriptics.com

unread,
May 3, 1999, 3:00:00 AM5/3/99
to
In article <3729C4DD...@ciril.fr>,
Frederic BONNET <frederi...@ciril.fr> wrote:

> People usually specify widget strings using -text option:
>
> label .l -text "blah"
>
> However there is another method that, when cleverly used, can make
multilingual
> GUIs very easy to build. Most widgets that provide -text option also provide
> -textvariable or similar option. The idea is to provide the name of a global
> variable that contains the string, rather than the string itself:
>
> label .l -textvariable var
> set var "blah"

Yet another way, which I've used for other reasons for a long time,
is to put all your strings into the option database. I originally
did this for exmh so you could customize buttons and menus by
creating a new app-defaults file. I was suprised one day to receive
screen shots of another my apps, WebTk, that had been converted to Japanese
just by editting the app-defaults file. (This was pre-8.1, with the
Japanese patch).

Anyway, the big picture is that anything you hardwire in a Tcl command
cannot be easily changed. Any attribute you set via the option database
can be tuned by the end user in various ways, either by loading Xresources
on UNIX, or by editting the app-defaults file.

You'll want to set the application name with "tk appname", and
also use the -class option on frames to organize your widgets in
a way that the app-defaults file makes sense. You can either have
a Tcl source file with a bunch of "option add" commands:

# In your main sources, just do
tk appname Myapp
set t [toplevel .dialog1 -class Dialog1]
button $t.ok -command Dialog1Ok
button $t.cancel -command Dialog1Cancel

# In a different file, do
option add Myapp.Dialog1.ok.text Yes startup
option add Myapp.Dialog1.cancel.text Cancel startup

# Or in a file you read with "option readfile"
Myapp.Dialog1.ok.text: Yes
Myapp.Dialog1.cancel.text: Cancel

The next thing for me personally to figure out is how to compose
this approach with files in different encodings and the message
catalog of Tcl 8.1!

-- Brent Welch

Reply all
Reply to author
Forward
0 new messages