1
0
mirror of https://github.com/minetest-mods/intllib.git synced 2024-11-15 15:00:32 +01:00
intllib/init.lua
2013-10-29 17:37:36 -02:00

42 lines
950 B
Lua

-- Support the old multi-load method
intllib = intllib or {}
local MP = minetest.get_modpath("intllib")
dofile(MP.."/lib.lua")
local strings = {}
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 {}
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
local modpath = minetest.get_modpath(modname)
if modpath then
local filename = modpath.."/locale/"..LANG..".txt"
local msgstr = load_strings(filename)
if msgstr then
intllib.getters[modname] = function (s)
return msgstr[s] or s
end
else
intllib.getters[modname] = noop_getter
end
end
end
return intllib.getters[modname]
end