انتقل إلى المحتوى

وحدة:I18n

من ويكيبيديا، الموسوعه الحره

يمكن إنشاء صفحة توثيق الوحدة في وحدة:I18n/شرح

local p = {}

local function tableMerge(t1, t2, overwrite)
	for k,v in pairs(t2) do
		if type(v) == "table" and type(t1[k]) == "table" then
			tableMerge(t1[k], v, overwrite)
		else
			if overwrite or t1[k] == nil then t1[k] = v end
		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, true)
		elseif type(i18n) == "table" then
			tableMerge(i18n, res, true)
		end
	end
end

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

return p