বিষয়বস্তুতে চলুন

মডিউল: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[3]]
		if fdata then
			table.insert(fdata.langs, code)
		end
	end

	for code, data in pairs(families) do
		local fdata = stats[data.family]
		if fdata then
			table.insert(fdata.subfams, code)
		end
	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 .. (data.canonicalName:find("[Ll]anguages") and "" or " languages")
			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 ~= nil) 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" ..
		"! Code\n" ..
		"! Canonical name\n" ..
		"! Parent family\n" ..
		"! Other names\n" ..
		"! Subfamilies\n" ..
		"! Languages\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