Runtime interface language switching

Anssi Hannula anssi.hannula@gmail.com
Sun Sep 9 13:47:00 GMT 2007


Hi!

Some programs offer a selection of the used interface language at runtime.

Unfortunately I don't see how that should be implemented properly so 
that it works independently from the user's environment with current glibc.

This gettext manual section:
http://www.gnu.org/software/gettext/manual/gettext.html#gettext-grok
advises re-setting the LANGUAGE environment variable to the wanted 
language. However, that section is marked as "outdated", and indeed it 
does not work properly anymore.

This is because this change in 2001-01-02:
>         * intl/dcigettext.c (guess_category_value): Rewrite so that LANGUAGE
>         value is ignored if the selected locale is the C locale.

So, if the environment locale variables happen to be C (or equivalent 
such as POSIX or invalid locale), the LANGUAGE variable is ignored, thus 
making it not possible to switch language using it.

Just using setlocale() instead or in addition of LANGUAGE variable is 
not possible, since the program cannot really guess what locales are 
actually installed in the system (i.e. listed by "locale -a").
You cannot setlocale() to an unexistent locale, but you can use the 
LANGUAGE variable to set glibc to use the translation from the .mo files 
anyway (that is, if locale is not C).

We encountered this problem with the VDR project (GPL set-top-box style 
software).

-- 
Anssi Hannula



More information about the Libc-alpha mailing list