summaryrefslogtreecommitdiff
path: root/script/language.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/language.lua')
-rw-r--r--script/language.lua41
1 files changed, 19 insertions, 22 deletions
diff --git a/script/language.lua b/script/language.lua
index 6077e4c6..f23d09ab 100644
--- a/script/language.lua
+++ b/script/language.lua
@@ -12,16 +12,15 @@ local function supportLanguage()
return list
end
-local function osLanguage()
- return LANG:lower()
-end
-
local function getLanguage(id)
local support = supportLanguage()
-- 检查是否支持语言
if support[id] then
return id
end
+ if not id then
+ return 'en-us'
+ end
-- 根据语言的前2个字母来找近似语言
for _, lang in ipairs(support) do
if lang:sub(1, 2) == id:sub(1, 2) then
@@ -29,7 +28,7 @@ local function getLanguage(id)
end
end
-- 使用英文
- return 'enUS'
+ return 'en-us'
end
local function loadFileByLanguage(name, language)
@@ -87,8 +86,8 @@ local function formatAsTable(str, ...)
end
local function loadLang(name, language)
- local tbl = loadFileByLanguage(name, 'en-US')
- if language ~= 'en-US' then
+ local tbl = loadFileByLanguage(name, 'en-us')
+ if language ~= 'en-us' then
local other = loadFileByLanguage(name, language)
for k, v in pairs(other) do
tbl[k] = v
@@ -123,18 +122,16 @@ local function loadLang(name, language)
})
end
-local function init()
- local id = osLanguage()
- local language = getLanguage(id)
- log.info(('VSC language: %s'):format(id))
- log.info(('LS language: %s'):format(language))
- return setmetatable({ id = language }, {
- __index = function (self, name)
- local tbl = loadLang(name, language)
- self[name] = tbl
- return tbl
- end,
- })
-end
-
-return init()
+return setmetatable({}, {
+ __index = function (self, name)
+ local tbl = loadLang(name, self.id)
+ self[name] = tbl
+ return tbl
+ end,
+ __call = function (self, id)
+ local language = getLanguage(id)
+ log.info(('VSC language: %s'):format(id))
+ log.info(('LS language: %s'):format(language))
+ self.id = language
+ end,
+})