[code] [textadept] Detecting the locale in Windows

From: Giovanni Salmeri <g.salmeri.att.mondodomani.org>
Date: Fri, 4 Sep 2015 20:47:18 +0200

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). 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!

-- 
Giovanni Salmeri
http://mondodomani.org/pers/salmeri/
-- 
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 - 14:47:18 EDT

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