વિભાગ:ભાષાઓની સૂચિ

વિકિકોશમાંથી

This module is used to generate the content of વિક્શનરી:ભાષાઓની સૂચિ and similar pages.


local m_languages = mw.loadData("Module:ભાષાઓ/સર્વઆંકડા")
local m_families = mw.loadData("Module:પરિવારો/આંકડા")

local export = {}
local filters = {}

function export.show(frame)
	local args = frame.args
	local filter = filters[args[1]]
	local ids = args["ઓળખો"]; if not ids or ids == "" then ids = false else ids = true end

	-- Get a list of all language codes
	local codes = {}

	for code, _ in pairs(m_languages) do
		table.insert(codes, code)
	end

	-- Sort the list
	table.sort(codes)

	-- Now go over each code, and create table rows for those that are selected
	local rows = {}

	for i, code in ipairs(codes) do
		local data = m_languages[code]

		-- Only show the codes that pass the filter
		if filter and filter(code, data, args) then
			local row =
				"\n|" .. (ids and " ઓળખ=\"" .. code .. "\"|" or "") .. "<code>" .. code .. "</code>" ..
				"\n| [[:શ્રેણી:" .. data.names[1] .. (data.names[1]:find("ભાષા$") and "" or " ભાષા") .. "|" .. data.names[1] .. "]]" ..
				"\n|" .. (data.family ~= "qfa-und" and ("[[વિક્શનરી:પરિવારોની સૂચિ#%s|%s]]"):format(data.family, m_families[data.family] and m_families[data.family].names[1] or ("<code>" .. data.family .. "</code>")) or "") ..
				"\n|"

			-- Can't use table.concat here as Module:languages returns a metatable
			if data.scripts[1] ~= "કંઈ નહિં" then
				row = row .. "[[વિક્શનરી:લિપિઓની સૂચિ#" .. data.scripts[1] .. "|<code>" .. data.scripts[1] .. "</code>]]"
				i = 2

				while data.scripts[i] do
					row = row .. ", [[વિક્શનરી:લિપિઓની સૂચિ#" .. data.scripts[i] .. "|<code>" .. data.scripts[i] .. "</code>]]"
					i = i + 1
				end
			end

			row = row .. "\n|"

			if data.names[2] then
				row = row .. data.names[2]
				i = 3

				while data.names[i] do
					row = row .. ", " .. data.names[i]
					i = i + 1
				end
			end

			row = row ..
				"\n|" .. (data.sort_key and "હા" or "") ..
				"\n|" .. (data.entry_name and "હા" or "")

			table.insert(rows, row)
		end
	end

	return
		"{| class=\"વિકિકોષ્ટક ક્રમશકાય\"\n" ..
		"! સંકેત\n" ..
		"! પ્રમાણભૂત નામ\n" ..
		"! પરિવાર\n" ..
		"! style=\"width: 12em\" | લિપિઓ\n" ..
		"! બીજા નામો\n" ..
		"! ક્રમ?\n" ..
		"! ઉચ્ચારદર્શક ?\n" ..
		"|-" .. table.concat(rows, "\n|-") .. "\n|}"
end

-- Filter functions
-- These return true or false depending on whether a given code
-- should be included in the table or not.
-- They're used to build shorter sublists.

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

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

filters["અપવાદરૂપ"] = function (code, data, args)
	return code:find("-") ~= nil
end

filters["વર્ગ"] = function (code, data, args)
	local type = args[2]
	return data.type == type
end

filters["અવેજી"] = function (code, data, args)
	return data.sort_key or data.entry_name
end

filters["વિશેષ"] = function (code, data, args)
	return data.family == "qfa-not"
end

--

function export.show_etym(frame)
	local m_etym_data = require('Module:વ્યુત્પત્તિશાસ્ત્ર_ભાષા/આંકડા') -- this probably HAS to be a require here
	local codes_list = {}
	local items = {}

	for code, data in pairs(m_etym_data) do
		if not codes_list[data] then
			codes_list[data] = {}
			table.insert(items, data)
		end
		table.insert(codes_list[data], code)
	end

	table.sort(items, function (apple, orange)
		return apple.names[1] < orange.names[1]
	end)

	local function make_link(code)
		if m_languages[code] then
			return ('[[વિક્શનરી:ભાષાઓની સૂચિ#%s|%s]]'):format(code, m_languages[code].names[1])
		elseif m_families[code] then
			return ('[[વિક્શનરી:પરિવારોની સૂચિ#%s|%s પરિવાર]]'):format(code, m_families[code].names[1])
		elseif m_etym_data[code] then
			return ('[[વિક્શનરી:ભાષાઓની સૂચિ/વિશેષ#%s|%s]]'):format(code, m_etym_data[code].names[1])
		else
			return '<code>' .. code .. '</code>'
		end
	end

	local rows = {}
	for i, data in ipairs(items) do
		local codes = codes_list[data]
		table.sort(codes)
		table.insert(rows,
			' \n' ..
			'| <code>' .. table.concat(codes, "</code>, <code>") .. '</code>\n' ..
			'| ' .. data.names[1] .. '\n' ..
			'| ' .. table.concat(data.names, ", ", 2) .. '\n' ..
			'| ' .. make_link(data.parent)
		)
	end

	return
		"{| class=\"વિકિકોષ્ટક ક્રમશકાય\"\n" ..
		"! સંકેત\n" ..
		"! પ્રમાણભૂત નામ\n" ..
		"! બીજા નામો\n" ..
		"! પૂર્વજ\n" ..
		"|-" .. table.concat(rows, "\n|-") .. "\n|}"
end

return export