Module:list of scripts

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

This module generates the list of scripts in Wiktionary:List of scripts.


local export = {}
local filters = {}

local m_scripts = require("Module:scripts")
local m_scripts_data = require("Module:scripts/data")

local concat = table.concat
local insert = table.insert
local remove = table.remove
local split = require("Module:string utilities").split

local m_table               = require("Module:table")
local language_code_to_name = require("Module:languages/code to canonical name")

-- fa-Arab -> Arab-fa
local function rearrange_lang_and_script(script_code)
	local lang, script = script_code:match("^(+)%-(%w+)$")
	if lang then script_code = script .. '-' .. lang end
	return script_code
end

-- Determines the order in which the scripts are shown in the resulting table.
local function compare_codes(apple, orange)
	-- "None" before all other scripts
	if apple == "None" then
		return true
	elseif orange == "None" then
		return false
	end
	
	-- Sort language-code-prefixed script codes immediately after unmodified ones:
	-- fa-Arab after Arab.
	return rearrange_lang_and_script(apple) < rearrange_lang_and_script(orange)
end

local function map_to_limit(func, t, limit)
	local new_t = {}
	for i = 1, limit do
		new_t = func(t, i)
	end
	return new_t
end

local function get_canonical_name(code)
	return language_code_to_name or "???"
end

local function sort_by_canonical_name(code1, code2)
	return get_canonical_name(code1) < get_canonical_name(code2)
end

local function sort_and_return(t, comp)
	table.sort(t, comp)
	return t
end

local function print_langs(langs, total)
	local limit = 20
	local suffix = ""
	if total > limit then
		suffix = ", ..."
	else
		limit = total
	end
	return concat(
		map_to_limit(
			get_canonical_name,
			sort_and_return(
				langs,
				sort_by_canonical_name),
			limit),
		", ") .. suffix
end

function export.show(frame)
	local args        = frame.args
	local filter      = filters]
	local m_languages = require("Module:languages/data/all")

	local script_to_langs = setmetatable(
		{},
		{
			__index = function(self, key) -- Initialize fields in table with 0.
				local val = {}
				self = val
				return val
			end
		})
	
	local m_scripts_size = m_table.size(m_scripts_data)
	for code, data in pairs(m_languages) do
		local checkData = type(data) == "table" and data or type(data) == "string" and split(data, ",") or {"None"}
		if m_table.size(checkData) ~= m_scripts_size then
			for _, sc in ipairs(checkData) do
				insert(script_to_langs, code)
			end
		end
	end
	
	local rows = {}
	for code, data in m_table.sortedPairs(m_scripts_data, compare_codes) do
		if (not filter) or filter(code, data, args) then
			local sc = m_scripts.makeObject(code, data)
			local names = sc:getAllNames()
			local canonicalName = remove(names, 1)
			local catname = sc:getCategoryName()
			
			local namecol = ""
			if code == "None" then
				namecol = canonicalName
			else
				namecol = "]"
			end
			
			local lang_count = #script_to_langs

			insert(rows, string.format([=[
	id="%s"
| <code>%s</code>
| %s
| %s
| %s
| %s
]=],
				code, code,
				namecol,
				#names > 0 and concat(names, ", ") or "&nbsp;",
				data.characters and "Yes" or "",
				lang_count > 0 and
					(' title="%s" | ]'):format(
						print_langs(script_to_langs, lang_count),
						catname,
						lang_count)
					or ("%i"):format(lang_count)))
		end
	end
	
	return [[
{| class="wikitable sortable"
! Code
! Canonical name
! Other names
! Autodetection
! Languages
|-]] .. concat(rows, "\n|-") .. [[

|}]]
end

return export