summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Martínez <lkaezadl3@yahoo.com>2016-10-06 05:24:15 -0300
committerDiego Martínez <lkaezadl3@yahoo.com>2016-10-06 20:39:41 -0300
commit715ac337159da1e2dca59363f612f7e1ba6654e2 (patch)
tree06892e8cf98ec186489b05f073fa2fed6f04c5ea
parente058fc93a88c1844d0236ec5b331fecb7cd87bf6 (diff)
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).
-rw-r--r--init.lua24
1 files changed, 20 insertions, 4 deletions
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