diff --git a/init.lua b/init.lua index 21d4e02..79d4c31 100644 --- a/init.lua +++ b/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