strip encoding suffix in locale name like zh_CN.utf8

So that we can automatically change to language defined in
the LANGUAGE or LANG env variable.
This commit is contained in:
chrox
2014-06-08 20:48:33 +08:00
parent 940beff044
commit 88061b323e

View File

@@ -39,7 +39,10 @@ function GetText_mt.__index.changeLang(new_lang)
GetText.current_lang = "C"
-- the "C" locale disables localization alltogether
if new_lang == "C" then return end
if new_lang == "C" or new_lang == nil then return end
-- strip encoding suffix in locale like "zh_CN.utf8"
new_lang = new_lang:sub(1, new_lang:find(".%."))
local file = GetText.dirname .. "/" .. new_lang .. "/" .. GetText.textdomain .. ".po"
local po = io.open(file, "r")