Re: [code] [textadept] Detecting the locale in Windows

From: Mitchell <m.att.foicica.com>
Date: Fri, 4 Sep 2015 20:09:20 -0400 (EDT)

Hi Giovanni,

On Fri, 4 Sep 2015, Giovanni Salmeri wrote:

> Hello everybody.
>
> Presently core/locale.lua:14 detects the locale as follows:
>
> local lang = (os.getenv('LANG') or ''):match('^[^_.@]+')
>
> Unfortunately that cannot work in Windows, which makes no use of the
> environment variable LANG. After some experimenting I wrote the
> following code:
>
> if WIN32 then
> local conv_lang = {
> Arab = "ar",
> Dutch = "nl",
> English = "en",
> French = "fr",
> German = "de",
> Italian = "it",
> Portuguese = "pt",
> Russian = "ru",
> Spanish = "es",
> Swedish = "sv",
> }
> lang = (os.setlocale(nil, 'ctype') or ''):match('^[^_.@]+')
> lang = conv_lang[lang_os] or lang
> end
>
> That seems more or less to work (I learnt that detecting properly the
> UI language in Windows is a tricky affair).

I found that out too and decided that it was a hopeless cause and added
the ability for the user to set their locale manually by copying a
locale.conf file to their `/Users/name/.textadept/` directory :)

> Perhaps a more robust
> approach would involve using something like
>
> f = package.loadlib("kernel32.dll", "GetUserDefaultUILanguage")
>
> but I don't know how one should proceed. Any comments or ideas? Thank
> you!

If you find something that works as well as LANG on *nix, please let me
know!

Cheers,
Mitchell

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Fri 04 Sep 2015 - 20:09:20 EDT

This archive was generated by hypermail 2.2.0 : Sat 05 Sep 2015 - 06:50:55 EDT