模組:Category tree/poscatboiler/data/scripts


此數據子模塊定義了維基詞典分類結構的一部分。

關於poscatboiler系統的介紹以及如何添加或更改分類,請參見Module:category tree/poscatboiler/data/documentation


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:category tree/poscatboiler/data/scripts/blocks"
local scripts_module = "Module:scripts"
local string_utilities_module = "Module:string utilities"

local m_str_utils = require(string_utilities_module)

local add_indefinite_article = m_str_utils.add_indefinite_article
local get_script_by_category_name = require(scripts_module).getByCategoryName
local pattern_escape = m_str_utils.pattern_escape

-----------------------------------------------------------------------------
--																								 --
--										 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_topright' and
'root_additional' variable values initialized below). These are replaced by the equivalent text.

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

local script_labels = {}

script_labels["字元"] = {
	description = "{{{scprosename}}}中的所有字元及其可能的變體,例如帶有變音符號的版本以及在任何語言中被識別為單一字元的組合。",
	umbrella_parents = {"分類"},
	umbrella_breadcrumb = "各文字字元",
	catfix = "mul",
}

script_labels["附錄"] = {
	description = "有關{{{sccat}}}的附錄。",
	umbrella_parents = {"Category:附錄"},
}

script_labels["語言"] = {
	description = "使用{{{sccat}}}的语言。",
	umbrella_parents = {"所有語言"},
}

script_labels["模板"] = {
	description = "包含所有的{{{sccat}}}定義模板。",
	umbrella_parents = {"模板"},
}

script_labels["模塊"] = {
	description = "有關{{{sccat}}}字元的模塊。",
	umbrella_parents = {"模塊"},
}

script_labels["資料模塊"] = {
	description = "包含與{{{scprosename}}}相關的資料的模塊。",
	umbrella_parents = {"資料模塊"},
}



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


raw_categories["所有文字"] = {
	description = "此分類包含維基字典上每種文字(書寫系統)的分類。",
	additional = "完整列表請見[[Wiktionary:文字列表]]。",
	parents = {"分類"},
}

-- Types of writing systems listed in [[Module:writing systems/data]].
raw_categories["各類文字"] = {
	description = "依照文字表示詞語的方式對文字進行分類。",
	parents = {{ name = "所有文字", sort = " " }},
	breadcrumb = "各類文字",
}

raw_categories["輔音音素文字"] = { -- Abjads
	description = "基本符號表示輔音的一類文字。其中有一些是不純的輔音音素文字,含有表示元音的字母。",
	parents = {"各類文字"},
}

raw_categories["元音附標文字"] = { -- Abugidas
	description = "符號表示輔音和元音組合的一類文字。表示同一輔音與不同元音組合的符號,其形態大致相似。",
	parents = {"各類文字"},
}

raw_categories["全音素文字"] = { -- Alphabetic writing systems
	description = "符號表示單個語音的一類文字。",
	parents = {"各類文字"},
}

raw_categories["語素文字"] = { -- Logographic writing systems
	description = "符號表示單個詞語的一類文字。",
	parents = {"各類文字"},
}

raw_categories["象形文字"] = { -- Pictographic writing systems
	description = "符號通過模仿所指實物的形狀來表示詞語的一類文字。",
	parents = {"各類文字"},
}

raw_categories["半音節文字"] = { -- Semisyllabaries
	description = "結合了全音素文字和音節文字特點的一類文字。", 
	parents = {"各類文字"},
}

raw_categories["音節文字"] = { -- Syllabaries
	description = "符號表示輔音和元音組合的一類文字。表示同一輔音與不同元音組合的符號,其形態大多差異較大。",
	parents = {"各類文字"},
}

for script_label, obj in pairs(script_labels) do
	raw_categories["各文字" .. mw.getContentLanguage():ucfirst(script_label)] = {
		description = "帶有各種特定文字的" .. script_label .. "的分類。",
		breadcrumb = obj.umbrella_breadcrumb or "各文字",
		parents = obj.umbrella_parents,
	}
end



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



-- Intro text for "root" categories such as [[Category:Arabic script]]. Template substitutions are as described above.
local root_topright = [=[<div style="clear: right; border: solid #aaa 1px; margin: 1 1 1 1; background: #f9f9f9; width: 250px; padding: 5px; text-align: left; float: right">
<div style="text-align: center; margin-bottom: 10px; margin-top: 5px">'''{{{scdisp}}}'''</div>

{| style="font-size: 90%; background: #f9f9f9"
| style="vertical-align: middle; height: 35px;" | [[File:Wikipedia-logo.png|35px|none|維基百科]] || 維基百科上有關{{{scprosename}}}的條目
|-
| colspan="2" style="padding-left: 50px; border-bottom: 1px solid lightgray;" | '''[[w:{{{Wikipedia}}}|{{{Wikipedia}}}]]'''
|-
| style="vertical-align: middle; height: 35px;" | [[File:Crystal kfind.png|35px|none|注意事項]] || {{{scdisp}}}的注意事項
|-
| colspan="2" style="padding-left: 50px; border-bottom: 1px solid lightgray;" | '''[[Wiktionary:{{{scdisp}}}]]'''
|-
| style="vertical-align: middle; height: 35px;" | [[File:Book notice.png|35px|none|相關資訊]] || {{{scdisp}}}的相關資訊
|-
| colspan="2" style="padding-left: 50px; border-bottom: 1px solid lightgray;" | '''[[Appendix:{{{sccat}}}]]'''
|-
| style="vertical-align: Middle; height: 35px;" | [[File:Abc box.svg|35px|none|代碼]] || {{{scdisp}}}的代碼
|-
| colspan="2" style="padding-left: 50px; border-bottom: 1px solid lightgray;" | '''{{{code}}}'''
|}
</div>]=]

-- Short description for "root" categories such as [[Category:Arabic script]]. Template substitutions are as described above.
local root_description = "本分類為'''{{{scprosename}}}'''的主分類。"

-- Additional description text for "root" categories such as [[Category:Arabic script]]. Template substitutions are as described above.
local root_additional = [=[可在[[Appendix:{{{sccat}}}]]找到{{{scprosename}}}的相关信息。

在维基词典中,{{{scprosename}}}用[[Wiktionary:文字|代码]]{{{codes}}}来表示。]=]


-- Replace template notation {{{}}} with variables.
local function substitute_template_refs(text, sc)
	local displayForm = sc:getDisplayForm()
	local scname = sc:getCanonicalName()
	local codes = {}
	
	for code, data in pairs(mw.loadData("Module:scripts/data")) do
		if data[1] == 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 = sc:getCategoryName(),
		scdisp = displayForm,
		scprosename = (displayForm:find("碼") or displayForm:find("旗語")) and displayForm or displayForm,
		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\n{{{scname}}}是一種")
		table.insert(ret, add_indefinite_article(system:getDisplayForm("singular")))
		table.insert(ret, "。")
	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


-- Handler for 'SCRIPT script' e.g. [[Category:Arabic script]] as well as [[Category:Morse code]] and
-- [[Category:Flag semaphore]].
table.insert(raw_handlers, function(data)
	local sc = get_script_by_category_name(data.category)
	mw.log('Category name:', data.category)
	mw.log('Script object:', sc)
	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, "所有文字")

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

	return {
		canonical_name = sc:getCategoryName(),
		topright = substitute_template_refs(root_topright, sc),
		description = substitute_template_refs(root_description, sc),
		additional = get_root_additional(root_additional, sc),
		parents = parents,
		breadcrumb = sc:getCanonicalName(),
		extra_children = children,
		can_be_empty = true,
	}
end)


-- Handler for 'SCRIPT script LABELS' e.g. [[Category:Arabic script templates]] as well as [[Category:Morse code LABELS]] and
-- [[Category:Flag semaphore LABELS]].
table.insert(raw_handlers, function(data)
	local sc, scname, label
	for lab in pairs(script_labels) do
		scname, label = data.category:match("^(.+)(" .. pattern_escape(lab) .. ")$")
		sc = get_script_by_category_name(scname)
		if sc then
			break
		end
	end
	if not sc then
		return nil
	end
	
	local label_obj = script_labels[label]

	-- Compute parents.
	local parents = {
		{name = scname, sort = label},
		-- umbrella category
		"各文字" .. mw.getContentLanguage():ucfirst(label),
	}

	return {
		canonical_name = sc:getCategoryName() .. label,
		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}