intllib/init.lua

45 lines
1020 B
Lua
Raw Normal View History

-- Support the old multi-load method
intllib = intllib or {}
2013-10-29 20:37:36 +01:00
local MP = minetest.get_modpath("intllib")
2013-10-29 20:37:36 +01:00
dofile(MP.."/lib.lua")
2013-10-29 20:37:36 +01:00
local strings = {}
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)
-- Support the old multi-load method
intllib.getters = intllib.getters or {}
2013-10-29 20:37:36 +01:00
local function noop_getter(s)
return s
end
function intllib.Getter(modname)
modname = modname or minetest.get_current_modname()
if not intllib.getters[modname] then
2013-10-29 20:37:36 +01:00
local modpath = minetest.get_modpath(modname)
if modpath then
local filename = modpath.."/locale/"..LANG..".txt"
2013-12-18 02:29:01 +01:00
local msgstr = intllib.load_strings(filename)
2013-10-29 20:37:36 +01:00
if msgstr then
intllib.getters[modname] = function (s)
2013-11-27 18:38:59 +01:00
if msgstr[s] and msgstr[s] ~= "" then
return msgstr[s]
end
return s
2013-10-29 20:37:36 +01:00
end
else
intllib.getters[modname] = noop_getter
end
end
end
return intllib.getters[modname]
end