2015-02-17 05:57:22 +01:00
|
|
|
|
|
|
|
-- Old multi-load method compatibility
|
|
|
|
if rawget(_G, "intllib") then return end
|
|
|
|
|
|
|
|
intllib = {
|
|
|
|
getters = {},
|
|
|
|
strings = {},
|
|
|
|
}
|
|
|
|
|
2013-10-29 16:19:35 +01:00
|
|
|
|
2013-10-29 20:37:36 +01:00
|
|
|
local MP = minetest.get_modpath("intllib")
|
2013-10-29 16:19:35 +01:00
|
|
|
|
2013-10-29 20:37:36 +01:00
|
|
|
dofile(MP.."/lib.lua")
|
2013-10-29 16:19:35 +01:00
|
|
|
|
|
|
|
|
2013-10-29 20:37:36 +01:00
|
|
|
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)
|
2013-10-29 16:19:35 +01:00
|
|
|
|
2015-02-02 00:10:09 +01:00
|
|
|
|
|
|
|
local INS_CHAR = intllib.INSERTION_CHAR
|
|
|
|
local insertion_pattern = "("..INS_CHAR.."?)"..INS_CHAR.."(%(?)(%d+)(%)?)"
|
|
|
|
|
2015-02-03 23:21:35 +01:00
|
|
|
local function make_getter(msgstrs)
|
2015-02-02 00:10:09 +01:00
|
|
|
return function(s, ...)
|
2015-02-03 23:21:35 +01:00
|
|
|
local str
|
2015-02-17 05:22:21 +01:00
|
|
|
if msgstrs then
|
2015-02-03 23:21:35 +01:00
|
|
|
str = msgstrs[s]
|
|
|
|
end
|
2015-02-02 00:10:09 +01:00
|
|
|
if not str or str == "" then
|
2015-02-03 23:21:35 +01:00
|
|
|
str = s
|
2015-02-02 00:10:09 +01:00
|
|
|
end
|
|
|
|
if select("#", ...) == 0 then
|
|
|
|
return str
|
|
|
|
end
|
|
|
|
local args = {...}
|
2015-02-03 23:21:35 +01:00
|
|
|
str = str:gsub(insertion_pattern, function(escape, open, num, close)
|
2015-02-02 00:10:09 +01:00
|
|
|
if escape == "" then
|
|
|
|
local replacement = tostring(args[tonumber(num)])
|
|
|
|
if open == "" then
|
|
|
|
replacement = replacement..close
|
2013-10-29 20:37:36 +01:00
|
|
|
end
|
2015-02-02 00:10:09 +01:00
|
|
|
return replacement
|
2013-10-29 20:37:36 +01:00
|
|
|
else
|
2015-02-02 00:10:09 +01:00
|
|
|
return INS_CHAR..open..num..close
|
2013-10-29 20:37:36 +01:00
|
|
|
end
|
2015-02-02 00:10:09 +01:00
|
|
|
end)
|
|
|
|
return str
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function intllib.Getter(modname)
|
|
|
|
modname = modname or minetest.get_current_modname()
|
|
|
|
if not intllib.getters[modname] then
|
|
|
|
local msgstr = intllib.get_strings(modname)
|
2015-02-03 23:21:35 +01:00
|
|
|
intllib.getters[modname] = make_getter(msgstr)
|
2013-10-29 16:19:35 +01:00
|
|
|
end
|
|
|
|
return intllib.getters[modname]
|
|
|
|
end
|
|
|
|
|
2015-02-02 00:10:09 +01:00
|
|
|
|
2014-02-12 23:27:09 +01:00
|
|
|
function intllib.get_strings(modname)
|
|
|
|
modname = modname or minetest.get_current_modname()
|
|
|
|
local msgstr = intllib.strings[modname]
|
2015-02-02 00:10:09 +01:00
|
|
|
if not msgstr then
|
2014-02-12 23:27:09 +01:00
|
|
|
local modpath = minetest.get_modpath(modname)
|
|
|
|
msgstr = intllib.load_strings(modpath.."/locale/"..LANG..".txt")
|
|
|
|
intllib.strings[modname] = msgstr
|
|
|
|
end
|
|
|
|
return msgstr or nil
|
|
|
|
end
|
|
|
|
|