The old $LANG-in-a-box trick (was Re: X11R7.5 and C.UTF-8)

Andy Koppe
Thu Dec 3 20:15:00 GMT 2009

2009/12/3 Corinna Vinschen:
> I created a new, simplified version of my tiny getlocale tool, which
> prints "export LANG=..." to stdout, or "setenv LANG ..." if the -c
> option has been given.  See attached source.

Good idea!

Two more additions would be good: GetUserDefaultUILanguage, and
GetSystemDefaultUILanguage. (These return LANGIDs; to turn them into

Bit of background: the language returned by GetUserDefaultUILanguage
is what Windows itself uses for its UIs. If you've got multiple
language packs installed, a 'Display Language' choice appears on the
'Keyboard and Languages' tab of the 'Region and Language' control
panel. Only problem: the function is not available on NT.

The LOCALE_USER_DEFAULT, meanwhile, reflects what's set on the
'Formats' tab of the 'Region and Language' panel.

More on this at the blog of MS's internationalization expert Michael

> In theory we could use it in /etc/profile.d/lang.{c}sh:
> /etc/profile.d/
>  test -z "${LC_ALL:-${LC_CTYPE:-$LANG}}" && eval $(getlocale -U)
> /etc/profile.d/lang.csh:
>  if ( $?LC_ALL == 0 && $?LC_CTYPE == 0 && $?LANG == 0 ) eval `getlocale -cU`
> If that's desired, I could easily create a getlocale package for the
> Base category.

It's very tempting, but I'm not sure. A couple of issues to consider:
- The setting is too late for terminal and shell, but then again, do
any of them care about the language setting (rather than the charset)?
- It would change the UI language of localized apps. I'd guess most
users would welcome programs speaking their language, but some would
complain loudly and demand to know how to get back to English.

> One problem we still have is that the iso639 language code returned by
> Windows is a three-letter code in rare cases (see the --testloop output)
> This is not feasible for newlib so far.  Maybe the getlocale tool should
> drop back to "C" in these cases.

Seems fair enough. I think our Mohawk and Quechua users would understand. :)


More information about the Cygwin-developers mailing list