Module:list of languages

Hello, you have come here looking for the meaning of the word Module:list of languages. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:list of languages, but we will also tell you about its etymology, its characteristics and you will know how to say Module:list of languages in singular and plural. Everything you need to know about the word Module:list of languages you have here. The definition of the word Module:list of languages will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:list of languages, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module is used to generate the content of Wiktionary:List of languages and similar pages.


local m_fun = require("Module:fun")
local m_languages = require("Module:languages")
local m_families_data = require("Module:families/data")
local m_table = require("Module:table")

local concat = table.concat
local insert = table.insert
local ipairs = ipairs
local pairs = pairs
local remove = table.remove
local size = m_table.size
local sort = table.sort
local sorted_pairs = m_table.sortedPairs

local export = {}
local filters = {}
local split = require("Module:string utilities").split

function export.count()
	return size(require("Module:languages/data/all"))
end

local function mergeExtra(langdata, extradata)
	for lkey, lvalue in pairs(extradata) do
		if langdata then
			for key in pairs(lvalue) do
				langdata = lvalue
			end
		end
	end
end

function export.show(frame)
	local args = frame.args
	local filter_name = args
	local filter = filters
	local arg2 = args
	local ids = require("Module:yesno")(args)
	
	local m_languages_data
	local use_filter = false
	
	-- Choose a data module.
	if filter_name == "two-letter code" then
		m_languages_data = require("Module:languages/data/2")
		mergeExtra(m_languages_data, require("Module:languages/data/2/extra"))
		if arg2 then
			use_filter = true
		end
	elseif filter_name == "three-letter code" then
		if arg2 and arg2:find("^$") then
			m_languages_data = require("Module:languages/data/3/" .. arg2)
			mergeExtra(m_languages_data, require("Module:languages/data/3/" .. arg2 .. "/extra"))
		else
			m_languages_data = require("Module:languages/data/all")
		end
	elseif filter_name == "exceptional" then
		m_languages_data = require("Module:languages/data/exceptional")
		mergeExtra(m_languages_data, require("Module:languages/data/exceptional/extra"))
	else
		m_languages_data = require("Module:languages/data/all")
		-- data/all already merges extradata
		use_filter = true
	end
	
	-- Select language codes to display.
	local data_tables = {}
	if use_filter then
		filter = filter(arg2)
		data_tables = m_fun.filter(filter, m_languages_data)
	else
		data_tables = m_languages_data
	end
	
	-- Now go over each code, and create table rows for those that are selected
	local rows = {}
	local row_i = 1
	
	local function link_script(script)
		return "]"
	end	
	
	for code, data in sorted_pairs(data_tables) do
		local lang = m_languages.makeObject(code, data)
		local canonicalName = lang:getCanonicalName()
		local family = lang:getFamilyCode()
		local scripts = lang:getScriptCodes()
		local row = {
			"\n|-", (ids and " id=\"" .. code .. "\" |" or ""),
			"\n|", '<code class="language-code">', code, "</code>",
			"\n|", (ids and " id=\"" .. canonicalName .. "\" |" or ""),
			" anguage$") and "" or " language"), "|", canonicalName, "]]",
			"\n|", (family and family ~= "qfa-und" and ("]"):format(family, m_families_data and m_families_data or ("<code>" .. family .. "</code>")) or ""),
			"\n|"
		}
		
		if type(scripts) == "string" then
			scripts = split(scripts, ",")
		end
		
		if scripts and scripts ~= "None" then
			insert(row, concat(m_fun.map(link_script, scripts), ", "))
		end
		
		insert(row, "\n|")
		
		local names = lang:getAllNames()
		remove(names, 1) -- Remove the canonical name.
		insert(row, concat(names, ", "))

		insert(row,
			"\n| " .. (data.sort_key and "Yes" or "") ..
			"\n| " .. (data.entry_name and "Yes" or "")
		)
		
		rows = concat(row)
		row_i = row_i + 1
	end

	return concat {
[[
{| class="wikitable sortable mw-datatable"
! Code
! Canonical name
! Family
! style="width: 12em" | Scripts
! Other names
! Sort?
! Diacr?]], concat(rows), "\n|}"
	} .. require("Module:TemplateStyles")("Module:list of languages/styles.css")
end

-- Filter functions
-- They receive parameter 2 as argument and generate a new function.
-- This function returns true or false depending on whether a given code
-- should be included in the table or not.
-- They're used to build shorter sublists.
-- The arguments are in the order "data, code" because the filter function in
-- ] supplies arguments to it in the order value, key.

filters = function (firstletter)
	local pattern = "^" .. (firstletter or "") .. "$"
	
	return function (data, code)
		return code:find(pattern) ~= nil
	end
end

filters = function (type)
	return function (data, code)
		return data.type == type
	end
end

filters = function (arg2)
	return function (data, code)
		return data.sort_key or data.entry_name
	end
end

filters = function (arg2)
	return function (data, code)
		return data == "qfa-not"
	end
end

--

function export.show_etym()
	local m_languages_data = require("Module:languages/data/all")
	local m_etym_data = require('Module:etymology_languages/data')
	local alias_codes = require("Module:languages/data").aliases
	local data_to_codes = {}
	local items = {}

	for code, data in sorted_pairs(m_etym_data) do
		local codes_list = data_to_codes
		if not codes_list then
			codes_list = {}
			data_to_codes = codes_list
			insert(items, data)
		end
		insert(codes_list, code)
		for alias_code, main_code in pairs(alias_codes) do
			if main_code == code then
				insert(codes_list, alias_code)
			end
		end
	end

	local function make_parent_link(code)
		if m_languages_data then
			return (']'):format(code, m_languages_data)
		elseif m_families_data then
			return (']'):format(code, m_families_data)
		elseif m_etym_data then
			return (']'):format(code, m_etym_data)
		elseif code then
			return '<code>' .. code .. '</code>'
		else
			return ''
		end
	end

	local rows = {}
	for _, data in ipairs(items) do
		local codes = data_to_codes
		local lang = m_languages.makeObject(codes, data)
		sort(codes)
		
		for i, code in ipairs(codes) do
			codes = '<code class="language-code" id="' .. code .. '">' .. code .. '</code>'
		end
		
		-- finalizeData in ] moves
		-- parent from field 3 to field 5: ]
		
		local names = lang:getAllNames()
		remove(names, 1) -- Remove the canonical name.
		
		insert(rows,
			' \n' ..
			'| ' .. concat(codes, ", ") .. '\n' ..
			'| ]\n' ..
			'| ' .. concat(names, ", ") .. '\n' ..
			'| ' .. make_parent_link(lang:getParentCode())
		)
	end

	return
		"{| class=\"wikitable sortable mw-datatable\"\n" ..
		"! Codes\n" ..
		"! Canonical name\n" ..
		"! Other names\n" ..
		"! Parent\n" ..
		"|-" .. concat(rows, "\n|-") .. "\n|}" ..
		require("Module:TemplateStyles")("Module:list of languages/styles.css")
end

return export