[fpc-pascal] GetLocaleInfo returns ZZZ

Henry Vermaak henry.vermaak at gmail.com
Wed Feb 28 10:58:55 CET 2018


On Wed, Feb 21, 2018 at 12:11:10PM +0100, Darius Blaszyk wrote:
> On my machine getlocaleinfo returns ZZZ when requesting the abbrev
> langname. The country code is correctly set to NL. This makes
> gettext.GetLanguageIDs return zz_NL. What could be causing this?
> 
> Also the behavior of GetLocaleInfoIDs does not seem to be according to
> the gettext manual. On windows the locale is determined by the Win API
> and on all other platforms the environment variables are checked as
> they are described in the manual but the first LANGUAGE env var is not
> probed and followed. This env var gives the preferred order of
> translations.

The Windows implementation of GetLanguageIDs() in gettext.pp is not
right.  It uses GetLocaleInfo() with LOCALE_SABBREVLANGNAME and
LOCALE_SABBREVCTRYNAME where it should probably be using
LOCALE_SISO639LANGNAME and LOCALE_SISO3166CTRYNAME, respectively.  The
*_SISO* constants work on Windows 98 and later, maybe that was the
reason for using *_SABBREV* originally.

I guess the fix belongs in FPC, but it can also be fixed in lazarus,
which overrides GetLanguageIDs() for darwin already.  Have a look at
LazGetLanguageIDs() in lazutf8.pas.  I override the lot of them and then
call SetDefaultLang() in LCLTranslator.pas.

For reference, the reason I had to fix it was because of the language
codes for Chinese don't agree (CHS/CHT vs zh) and I didn't want to
duplicate the locale directories.  There's a table here:

http://archives.miloush.net/michkap/archive/2005/02/17/375235.html

Henry



More information about the fpc-pascal mailing list