mirror of
https://github.com/minetest-mods/intllib.git
synced 2025-01-08 09:00:26 +01:00
Fix insertions with missing translations
This commit is contained in:
parent
4404c4071c
commit
c497c7b10c
22
init.lua
22
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
|
||||
|
Loading…
Reference in New Issue
Block a user