From 88061b323e756cb2a3d49ab300dc802a82ec1f2e Mon Sep 17 00:00:00 2001 From: chrox Date: Sun, 8 Jun 2014 20:48:33 +0800 Subject: [PATCH] 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. --- frontend/gettext.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/gettext.lua b/frontend/gettext.lua index 895f8d56c..f098c83e8 100644 --- a/frontend/gettext.lua +++ b/frontend/gettext.lua @@ -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")