blob: 30acdadb99a1d4295f0211a5335dc64149d4ce0b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
local fs = require 'bee.filesystem'
local function supportLanguage()
local list = {}
for path in (ROOT / 'locale'):list_directory() do
if fs.is_directory(path) then
list[#list+1] = path:filename():string():lower()
end
end
return list
end
local function osLanguage()
return LANG:lower()
end
local function getLanguage(id)
local support = supportLanguage()
-- 检查是否支持语言
if support[id] then
return id
end
-- 根据语言的前2个字母来找近似语言
for _, lang in ipairs(support) do
if lang:sub(1, 2) == id:sub(1, 2) then
return lang
end
end
-- 使用英文
return 'enUS'
end
local function init()
local id = osLanguage()
local language = getLanguage(id)
log.info(('VSC language: %s'):format(id))
log.info(('LSP language: %s'):format(language))
return language
end
return init()
|