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

وحدة:list of families

من ويكاموس، القاموس الحر

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

local export = {}
local filters = {}

function export.show(frame)
	local args = frame.args
	local filter = filters[args[1]]
	local families = mw.loadData("Module:families/data")
	local languages = mw.loadData("Module:languages/alldata")
	local stats = {}

	for code, _ in pairs(families) do
		stats[code] = { langs = {}, subfams = {} }
	end 

	for code, data in pairs(languages) do
		local fdata = stats[data.family] or { langs = {} }
		table.insert(fdata.langs, code)
	end

	for code, data in pairs(families) do
		local fdata = stats[data.family] or { subfams = {} }
		table.insert(fdata.subfams, code)
	end

	local codes = {}
 
	for code, _ in pairs(families) do
		table.insert(codes, code)
	end 
	table.sort(codes)
 
	local rows = {}
	for i, code in ipairs(codes) do
		local data = families[code]

		local rt = nil
		if data.otherNames then
			local i = 1
			rt = {}
			while data.otherNames[i] do
				table.insert(rt, data.otherNames[i])
				i = i + 1
			end
		end

		if (not filter) or filter(code, data, args) then
			local catname = (data.canonicalName:find("[Ll]anguage$")  and   ""  or    "   لغات ")  .. data.canonicalName 
			catname = catname:sub(1, 1):upper() .. catname:sub(2)

			table.insert(rows, string.format(
				' id="%s"\n' ..
				'| <code>%s</code>\n' ..
				'| [[:Category:%s|%s]]\n' ..
				'| %s\n' ..
				'| %s\n' ..
				'| %u\n' ..
				'| %u\n',
				code, code,
				catname, data.canonicalName,
				(data.family ~= "qfa-und") and ('[[#' .. data.family .. '|' .. families[data.family].canonicalName .. ']]') or '',
				rt and table.concat(rt, ", ") or "&nbsp;",
				#stats[code].subfams,
				#stats[code].langs
			))
		end
	end

	return
		"{| class=\"wikitable sortable\"\n" ..
		"! الترميز\n" ..
		"! اسم معياري\n" ..
		"! أسر الأم\n" ..
		"! أسماء أخرى\n" ..
		"! أسر فرعية\n" ..
		"! لغات\n" ..
		"|-" .. table.concat(rows, "\n|-") .. "\n|}"
end

filters["three-letter code"] = function (code, data, args)
	local firstletter = args[2]
	return data.family ~= "qfa-not" and code:find("^" .. (firstletter or "[a-z]") .. "[a-z][a-z]$") ~= nil
end

filters["exceptional"] = function (code, data, args)
	return data.family ~= "qfa-not" and code:find("-") ~= nil
end

filters["special"] = function (code, data, args)
	return data.family == "qfa-not"
end

return export