mirror of
https://github.com/minetest-mods/intllib.git
synced 2025-01-09 09:30:26 +01:00
Fix insertions with missing translations
This commit is contained in:
parent
4404c4071c
commit
c497c7b10c
20
init.lua
20
init.lua
@ -17,25 +17,23 @@ intllib.getters = intllib.getters or {}
|
|||||||
intllib.strings = {}
|
intllib.strings = {}
|
||||||
|
|
||||||
|
|
||||||
local function noop_getter(s)
|
|
||||||
return s
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local INS_CHAR = intllib.INSERTION_CHAR
|
local INS_CHAR = intllib.INSERTION_CHAR
|
||||||
local insertion_pattern = "("..INS_CHAR.."?)"..INS_CHAR.."(%(?)(%d+)(%)?)"
|
local insertion_pattern = "("..INS_CHAR.."?)"..INS_CHAR.."(%(?)(%d+)(%)?)"
|
||||||
|
|
||||||
local function make_getter(strs)
|
local function make_getter(msgstrs)
|
||||||
return function(s, ...)
|
return function(s, ...)
|
||||||
local str = strs[s]
|
local str
|
||||||
|
if strs then
|
||||||
|
str = msgstrs[s]
|
||||||
|
end
|
||||||
if not str or str == "" then
|
if not str or str == "" then
|
||||||
return s
|
str = s
|
||||||
end
|
end
|
||||||
if select("#", ...) == 0 then
|
if select("#", ...) == 0 then
|
||||||
return str
|
return str
|
||||||
end
|
end
|
||||||
local args = {...}
|
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
|
if escape == "" then
|
||||||
local replacement = tostring(args[tonumber(num)])
|
local replacement = tostring(args[tonumber(num)])
|
||||||
if open == "" then
|
if open == "" then
|
||||||
@ -55,11 +53,7 @@ function intllib.Getter(modname)
|
|||||||
modname = modname or minetest.get_current_modname()
|
modname = modname or minetest.get_current_modname()
|
||||||
if not intllib.getters[modname] then
|
if not intllib.getters[modname] then
|
||||||
local msgstr = intllib.get_strings(modname)
|
local msgstr = intllib.get_strings(modname)
|
||||||
if msgstr then
|
|
||||||
intllib.getters[modname] = make_getter(msgstr)
|
intllib.getters[modname] = make_getter(msgstr)
|
||||||
else
|
|
||||||
intllib.getters[modname] = noop_getter
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return intllib.getters[modname]
|
return intllib.getters[modname]
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user