Fix insertions with missing translations

This commit is contained in:
ShadowNinja 2015-02-03 17:21:35 -05:00
parent 4404c4071c
commit c497c7b10c
1 changed files with 8 additions and 14 deletions

View File

@ -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