ข้ามไปเนื้อหา

มอดูล:I18n

จากวิกิพีเดีย สารานุกรมเสรี
Documentation iconคู่มือการใช้งานมอดูล[สร้าง]
localp={}

-- Credit to http://stackoverflow /a/1283608/2644759
-- cc-by-sa 3.0
localfunctiontableMerge(t1,t2,overwrite)
fork,vinpairs(t2)do
iftype(v)=="table"andtype(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
ifoverwriteort1[k]==nilthent1[k]=vend
end
end
returnt1
end

functionp.loadI18n(name,i18n_arg)
localexist,res=pcall(require,name)
ifexistandnext(res)~=nilthen
ifi18n_argthen
tableMerge(i18n_arg,res.i18n,true)
elseiftype(i18n)=="table"then
-- merge to global i18n
tableMerge(i18n,res.i18n,true)
end
end
end

functionp.loadI18nFrame(frame,i18n_arg)
p.loadI18n(frame:getTitle().."/i18n",i18n_arg)
end

returnp