This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: suggestion (was Re: 1.7.7: Localization does not follow the language of the OS)

On 12 January 2011 17:47, cornwarecjp wrote:
>> The official way to set the locale is to use the locale(1) tool, see the
>> User's Guide
>> Â export LANG=`locale -u` Â Â Â setenv LANG `locale -u`
>> Â export LANG=`locale -s` Â Â Â setenv LANG `locale -s`
>> or better
>> Â export LANG=`locale -uU` Â Â Âsetenv LANG `locale -uU`
>> Â export LANG=`locale -sU Â Â Â setenv LANG `locale -sU`
> Thanks for this suggestion. I tested the locale command, and it does
> what you describe.
> Unfortunately, the people who download my application usually don't have
> Cygwin, so I'll have to distribute locale.exe with my application. Also,
> this trick will add extra complexity to my software, which is (AFAIK) not
> necessary on other UNIX platforms.
> Despite these disadvantages, I think this is a useful solution for me.
> locale.exe is only 18kB; I'll just check the license again to see if this
> distributing is OK.
> About the quotation method discussion: I think this is irrelevant for me,
> as I am planning to call locale directly from the C++ code, to retrieve
> the system locale, and then, again from C++, set the LANG variable, before
> initializing the localization.

Instead of invoking `locale`, you could call the relevant Windows
functions directly. Locales in Windows are represented by numeric IDs,
but luckily there is a function that allows to translate them into ISO
language and country codes as used in POSIX locales.

int GetLocaleInfo(LCID Locale, LCTYPE LCType, LPTSTR lpLCData, int cchData);

See MSDN for the details, but passing LOCALE_SISO639LANGNAME and
LOCALE_SISO3166CTRYNAME as the LCTYPE parameter allows to obtain the
two/three-letter language and country codes. Concatenate with an
underscore and append ".UTF-8", and you get a locale such as

Now where do you get the locale ID from? Two important ones are
available as constants:

- LOCALE_USER_DEFAULT: This is the one selected on the 'Formats' tab
of the 'Region and Language' control panel, and it's also what's
returned by `locale -u`.

- LOCALE_SYSTEM_DEFAULT: This is the one selected as the "Language for
non-Unicode programs" on the 'Administrative' tab of the 'Region and
Language' control panel. It's a system-wide setting, so changing it
requires administrator privileges. This is what's returned by `locale

Two more are available through function calls. Unlike the first two,
these ones actually concern the Windows UI language.

- GetSystemDefaultUILanguage(void): The system's default UI language,
which is used for example in the installer.

- GetUserDefaultUILanguage(void): The language of the user's Windows
UI. Some Windows versions allow to select different UI languages
through a setting in the 'Region and Language' control panel.
Otherwise, this is to the same as GetSystemDefaultUILanguage().

I think GetUserDefaultUILanguage() is the correct one to use when
deciding what language to use for a program's UI, but many use
LOCALE_USER_DEFAULT instead. See also

> I am curious what sort of advantages are achieved by
> always setting LANG to C.UTF-8.

It avoids or at least reduces complaints like this:

- Upgrading from Cygwin 1.5 (which didn't support locales) to 1.7
changed the language, but I'd much prefer to stick with English.
- Program X speaks my language when doing this, but English when doing that.
- Non-ASCII characters in my language don't work in the console (with
the default raster font), rxvt (without -unicode), or puttycyg (where
UTF-8 needs to be selected manually).

Obviously a good case can be made for automatically reflecting the
Windows locale settings in the POSIX locale settings, but at the time
this was felt to be one change too far.

(Btw, in the mintty terminal, the user can set the language fairly
easily on the Text page of its options.)


Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]