Modulo:I18n: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
+tableMergeNotOverwrite
Prune code duplication
Riga 3:
-- Credit to http://stackoverflow.com/a/1283608/2644759
-- cc-by-sa 3.0
local function tableMerge(t1, t2, overwrite)
for k,v in pairs(t2) do
if type(v) == "table" and type(t1[k]) == "table" then
-- since type(t1[k]) == type(v) == "table", so t1[k] and v is true
tableMerge(t1[k], v, overwrite) -- t2[k] == v
else
if overwrite or t1[k] == nil then t1[k] = v end
end
end
return t1
end
 
local function tableMergeNotOverwrite(t1, t2)
for k,v in pairs(t2) do
if type(v) == "table" and type(t1[k]) == "table" then
-- since type(t1[k]) == type(v) == "table", so t1[k] and v is true
tableMergeNotOverwrite(t1[k], v) -- t2[k] == v
else
if t1[k] == nil then t1[k] = v end
end
end
Riga 31 ⟶ 19:
if exist and next(res) ~= nil then
if i18n_arg then
tableMerge(i18n_arg, res.i18n, true)
else
-- merge to global i18n
if type(i18n) == "table" then tableMerge(i18n, res.i18n, true) end
end
end