Module:User:Benwing2/category tree/poscatboiler/data/scripts

local raw_categories = {} local raw_handlers = {}

-- A list of Unicode blocks to which the characters of the script or scripts belong is created by this module -- and displayed in script category pages. local blocks_submodule = "Module:User:Benwing2/category tree/poscatboiler/data/scripts/blocks"

- --                                                                        -- --                               SCRIPT LABELS                             -- --                                                                        -- -

--[=[ The following values are recognized for each script label:

'description' A plain English description for the label. Special template substitutions are recognized; see below. 'umbrella_parents' A table listing one or more parent categories of the umbrella category 'LABELS by script' for this label. The format is as for regular raw categories (see Module:category tree/poscatboiler/data/documentation). 'umbrella_breadcrumb' The breadcrumb to use in the umbrella category 'LABELS by script'. Defaults to "by script". 'catfix' Same as the 'catfix' parameter for regular raw categories (see Module:category tree/poscatboiler/data/documentation). This specifies a language code to use to ensure that pages in the category are displayed in the right font and linked appropriately. If this is set, the 'catfix_sc' parameter will effectively be set with the script code in question.

Special template-like parameters can be used inside the 'description' field (as well as in the 'root_description', 'root_intro' and 'root_additional' variable values initialized below). These are replaced by the equivalent text.

multiple aliases (e.g. 'tt-Arab', 'ur-Arab', 'ku-Arab', etc.). ]=]
 * Script code.
 * A comma-separated list of all the alias codes for this script. This applies especially to Arabic, which has
 * The value "s" if lists more than one code, otherwise an empty string.
 * The name of the script that the category belongs to.
 * The name of the script's main category, which adds "script" to the regular name.
 * Same as for Morse code, otherwise adds "the" before.
 * The Wikipedia article for the script (if it is present in the language's data file), or else.

local script_labels = {}

script_labels["characters"] = { description = "All characters from, and their possible variations, such as versions with diacritics and combinations recognized as single characters in any language.", umbrella_parents = {"Fundamental"}, umbrella_breadcrumb = "Characters by script", catfix = "mul", }

script_labels["appendices"] = { description = "Appendices about .", umbrella_parents = {"Category:Appendices"}, }

script_labels["languages"] = { description = "Languages that use .", umbrella_parents = {"All languages"}, }

script_labels["templates"] = { description = "Templates with predefined contents for .", umbrella_parents = {"Templates"}, }

script_labels["modules"] = { description = "Modules with scripts for .", umbrella_parents = {"Modules"}, }

- --                                                                        -- --                              RAW CATEGORIES                             -- --                                                                        -- -

raw_categories["All scripts"] = { description = "This category contains the categories for every script (writing system) on Wiktionary.", additional = "See List of scripts for a full list.", parents = {"Fundamental"}, }

-- Types of writing systems listed in Module:writing systems/data. raw_categories["Scripts by type"] = { description = "Scripts classified by how they represent words.", parents = , }

raw_categories["Alphabetic writing systems"] = { description = "Scripts whose symbols represent individual speech sounds.", parents = {"Scripts by type"}, }

raw_categories["Abjads"] = { description = "Scripts whose basic symbols represent consonants. Some of these are impure abjads, which have letters for some vowels.", parents = {"Scripts by type"}, }

raw_categories["Abugidas"] = { description = "Scripts whose symbols represent consonant and vowel combinations. Symbols representing the same consonant combined with different vowels are for the most part similar in form.", parents = {"Scripts by type"}, }

raw_categories["Logographic writing systems"] = { description = "Scripts whose symbols represent individual words.", parents = {"Scripts by type"}, }

raw_categories["Pictographic writing systems"] = { description = "Scripts whose symbols represent individual words by using symbols that resemble the physical objects to which those words refer.", parents = {"Scripts by type"}, }

raw_categories["Syllabaries"] = { description = "Scripts whose symbols represent consonant and vowel combinations. Symbols representing the same consonant combined with different vowels are for the most part different in form.", parents = {"Scripts by type"}, }

for script_label, obj in pairs(script_labels) do raw_categories[mw.getContentLanguage:ucfirst(script_label) .. " by script"] = { description = "Categories with " .. script_label .. " of various specific scripts.", breadcrumb = obj.umbrella_breadcrumb or "by script", parents = obj.umbrella_parents, } end

- --                                                                        -- --                                RAW HANDLERS                             -- --                                                                        -- -

-- Intro text for "root" categories such as. Template substitutions are as described above. local root_intro = [=[ 

]=]

-- Short description for "root" categories such as. Template substitutions are as described above. local root_description = "This is the main category of the ."

-- Additional description text for "root" categories such as. Template substitutions are as described above. local root_additional = [=[Information about may be available at Appendix:.

In various places at Wiktionary, is represented by the code .]=]

-- Replace template notation { – } with variables. local function substitute_template_refs(text, sc) local categoryName = sc:getCategoryName local scname = sc:getCanonicalName local codes = {} for code, data in pairs(mw.loadData("Module:scripts/data")) do		if data.canonicalName == scname then table.insert(codes, "" .. code .. "") end end if codes[2] then table.sort(			codes,			-- Four-letter codes have length 10, because they are bolded: Latn.			function(code1, code2)				if #code1 == 10 then					if #code2 == 10 then						return code1 < code2					else						return true					end				else					if #code2 == 10 then						return false -- four-letter codes before other codes					else						return code1 < code2					end				end			end) end local content = { code = sc:getCode, codesplural = codes[2] and "s" or "", codes = table.concat(codes, ", "), scname = scname, sccat = categoryName, scprosename = categoryName:find("code") and categoryName or "the " .. categoryName, Wikipedia = sc:getWikipediaArticle, }	text = string.gsub(		text,		"}",		function (parameter)			return content[parameter] or error("No value for script category parameter '" .. parameter .. "'.")		end) return text end

local function get_root_additional(additional, sc) local ret = { additional } local systems = sc:getSystems for _, system in ipairs(systems) do		table.insert(ret, "\n\nThe script is ") if mw.ustring.sub(system:getCanonicalName, 1, 1) == "a" then table.insert(ret, "an ") else table.insert(ret, "a ") end local singular = system:getCategoryName singular = mw.getContentLanguage:lcfirst(singular) singular = mw.ustring.gsub(singular, "ies$", "y") singular = mw.ustring.gsub(singular, "s$", "") table.insert(ret, singular .. ".") end local blocks = require(blocks_submodule) .print_blocks_by_canonical_name(sc:getCanonicalName) if blocks then table.insert(ret, "\n") table.insert(ret, blocks) end

return substitute_template_refs(table.concat(ret), sc) end

local function get_script_obj(script) local scriptname = script:gsub(" script$", "") return require("Module:scripts").getByCanonicalName(scriptname) or -- vs. name of script = "undetermined" require("Module:scripts").getByCanonicalName(mw.ustring.lower(scriptname)) end

local scripts_without_script_in_category = { -- FIXME, consider checking all scripts for names without 'script' in them. ["Morse code"] = true, ["Flag semaphore"] = true, }

-- Handler for 'SCRIPT script' e.g. as well as  and -- . table.insert(raw_handlers, function(data)	if not data.category:match("^(.+ script)$") and not scripts_without_script_in_category[data.category] then		return nil	end	local sc = get_script_obj(data.category)	if not sc then		return nil	end	-- Compute parents.	local parents = {}	local systems = sc:getSystems	for _, system in ipairs(systems) do		table.insert(parents, system:getCategoryName)	end	table.insert(parents, "All scripts")

-- Compute (extra) children. local children = {} for script_label, _ in pairs(script_labels) do table.insert(children, data.category .. " " .. script_label) end

return { intro = substitute_template_refs(root_intro, sc), description = substitute_template_refs(root_description, sc), additional = get_root_additional(root_additional, sc), parents = parents, breadcrumb = sc:getCategoryName, extra_children = children, can_be_empty = true, } end)

-- Handler for 'SCRIPT script LABELS' e.g. as well as  and -- . table.insert(raw_handlers, function(data)	local script, label	for lab, _ in pairs(script_labels) do		-- FIXME, if we add script labels with a hyphen in them we'll have to escape the hyphen		-- in the following patterns.		script, label = data.category:match("^(.+ script) (" .. lab .. ")$")		if script then			break		end		-- Check for e.g. 'Morse code characters' or 'Flag semaphore templates'.		script, label = data.category:match("^(.+) (" .. lab .. ")$")		if script then			if scripts_without_script_in_category[script] then				break			else				script = nil			end		end	end	if not script then		return nil	end

local sc = get_script_obj(script) if not sc then return nil end local label_obj = script_labels[label] -- Compute description. local desc = substitute_template_refs(label_obj.description, sc)

-- Compute parents. local parents = { {name = script, sort = label}, -- umbrella category mw.getContentLanguage:ucfirst(label) .. " by script", }

return { description = substitute_template_refs(label_obj.description, sc), parents = parents, breadcrumb = label, catfix = label_obj.catfix, catfix_sc = label_obj.catfix and sc:getCode, } end)

return {RAW_CATEGORIES = raw_categories, RAW_HANDLERS = raw_handlers}