New features in #Tcl9 – part 5:
msgcat supports custom locale search list.
This is a nice one! When you are working in multi-lingual environments, you may want to translate strings according to your locale. But when there is no translation, msgcat falls back to some predefined other locales (or the "root" locale). But what if you want Japanese and failing that you like to keep English instead unless there is a German translation available?
You can do that now in Tcl9! You then just specify:
% msgcat::mcpreferences jp de en {}
That will make msgcat look for a Japanese translation first. It none is found, it looks for a German one and failing that for an English one.
Read more about this and some other enhancements here:
Pitfall of the day:
Try this:
foreach {name value} {
one 1
two 2
three 3
} {
set name($value) $name
}
Can you guess what is wrong ...?
Yes, you get the error
can't set "name(1)": variable isn't array
That is because the plain loop variable 'name' gets defined first, before the loop body defines the array variable 'name'. But at that point, the variable name 'name' is already taken. Ups!