„Modul:I18n“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
copied/modified from Module:Wikidata |
(kein Unterschied)
|
Version vom 6. Oktober 2017, 17:25 Uhr
Die Dokumentation für dieses Modul kann unter Modul:I18n/Doku erstellt werden
local p = {}
-- Credit to http://stackoverflow.com/a/1283608/2644759
-- cc-by-sa 3.0
local function tableMerge(t1, t2)
for k,v in pairs(t2) do
if type(v) == "table" then
if type(t1[k] or false) == "table" then
tableMerge(t1[k] or {}, t2[k] or {})
else
t1[k] = v
end
else
t1[k] = v
end
end
return t1
end
function p.loadI18n(name, i18n_arg)
local exist, res = pcall(require, name)
if exist and next(res) ~= nil then
if i18n_arg then
tableMerge(i18n_arg, res.i18n)
else
-- merge to global i18n
if type(i18n) == "table" then tableMerge(i18n, res.i18n) end
end
end
end
function p.loadI18nFrame(frame, i18n_arg)
p.loadI18n(frame:getTitle().."/i18n", i18n_arg)
end
return p