mirror of
https://github.com/minetest-mods/intllib.git
synced 2025-01-08 09:00:26 +01:00
Add support for language variants/dialects.
Assuming the detected language is `ll_CC`, the mod tries the following files: - `locale/ll_CC.txt` - `locale/ll.txt` - `locale/en.txt` (assuming it has not been processed already).
This commit is contained in:
parent
e058fc93a8
commit
715ac33715
24
init.lua
24
init.lua
@ -16,7 +16,6 @@ dofile(MP.."/lib.lua")
|
||||
local LANG = minetest.setting_get("language")
|
||||
if not (LANG and (LANG ~= "")) then LANG = os.getenv("LANG") end
|
||||
if not (LANG and (LANG ~= "")) then LANG = "en" end
|
||||
LANG = LANG:sub(1, 2)
|
||||
|
||||
|
||||
local INS_CHAR = intllib.INSERTION_CHAR
|
||||
@ -61,14 +60,31 @@ function intllib.Getter(modname)
|
||||
end
|
||||
|
||||
|
||||
function intllib.get_strings(modname)
|
||||
local function get_locales(code)
|
||||
local ll, cc = code:match("^(..)_(..)")
|
||||
if ll then
|
||||
return { ll.."_"..cc, ll, ll~="en" and "en" or nil }
|
||||
else
|
||||
return { code, code~="en" and "en" or nil }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function intllib.get_strings(modname, langcode)
|
||||
langcode = langcode or LANG
|
||||
modname = modname or minetest.get_current_modname()
|
||||
local msgstr = intllib.strings[modname]
|
||||
if not msgstr then
|
||||
local modpath = minetest.get_modpath(modname)
|
||||
msgstr = intllib.load_strings(modpath.."/locale/"..LANG..".txt")
|
||||
msgstr = { }
|
||||
for _, l in ipairs(get_locales(langcode)) do
|
||||
local t = intllib.load_strings(modpath.."/locale/"..l..".txt") or { }
|
||||
for k, v in pairs(t) do
|
||||
msgstr[k] = msgstr[k] or v
|
||||
end
|
||||
end
|
||||
intllib.strings[modname] = msgstr
|
||||
end
|
||||
return msgstr or nil
|
||||
return msgstr
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user