summaryrefslogtreecommitdiff
path: root/init.lua
blob: e63d709c88c4e92126db6f444d79aa93b3c628ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

-- 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 = intllib.load_strings(filename)
			if msgstr then
				intllib.getters[modname] = function (s)
					if msgstr[s] and msgstr[s] ~= "" then
						return msgstr[s]
					end
					return s
				end
			else
				intllib.getters[modname] = noop_getter
			end
		end
	end
	return intllib.getters[modname]
end