diff --git a/init.lua b/init.lua index 3712bea..cb30b8c 100644 --- a/init.lua +++ b/init.lua @@ -17,25 +17,23 @@ intllib.getters = intllib.getters or {} intllib.strings = {} -local function noop_getter(s) - return s -end - - local INS_CHAR = intllib.INSERTION_CHAR local insertion_pattern = "("..INS_CHAR.."?)"..INS_CHAR.."(%(?)(%d+)(%)?)" -local function make_getter(strs) +local function make_getter(msgstrs) return function(s, ...) - local str = strs[s] + local str + if strs then + str = msgstrs[s] + end if not str or str == "" then - return s + str = s end if select("#", ...) == 0 then return str end local args = {...} - local str = str:gsub(insertion_pattern, function(escape, open, num, close) + str = str:gsub(insertion_pattern, function(escape, open, num, close) if escape == "" then local replacement = tostring(args[tonumber(num)]) if open == "" then @@ -55,11 +53,7 @@ function intllib.Getter(modname) modname = modname or minetest.get_current_modname() if not intllib.getters[modname] then local msgstr = intllib.get_strings(modname) - if msgstr then - intllib.getters[modname] = make_getter(msgstr) - else - intllib.getters[modname] = noop_getter - end + intllib.getters[modname] = make_getter(msgstr) end return intllib.getters[modname] end