Pergi ke kandungan

Modul:category tree/poscatboiler/data/scripts

Daripada Wikikamus

Submodul data ini mentakrifkan sebahagian daripada struktur kategori Wikikamus.

Untuk pengenalan kepada sistem poscatboiler dan penerangan tentang cara menambah atau mengubah suai kategori, lihat Modul:category tree/poscatboiler/data/doc.


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"



-----------------------------------------------------------------------------
--                                                                         --
--                               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["aksara"] = {
	description = "Semua aksara daripada {{{scprosename}}}, dan kesemua kelainan aksara yang mungkin, seperti versi berdiakritik serta gabungan aksara yang diiktiraf sebagai aksara tunggal dalam mana-mana bahasa.",
	umbrella_parents = {"Asas"},
	umbrella_breadcrumb = "Aksara mengikut tulisan",
	catfix = "mul",
}

script_labels["lampiran"] = {
	description = "Lampiran berkenaan {{{scprosename}}}.",
	umbrella_parents = {"Kategori:Lampiran"},
}

script_labels["bahasa-bahasa"] = {
	description = "bahasa-bahasa yang menggunakan {{{scprosename}}}.",
	umbrella_parents = {"Semua bahasa"},
}

script_labels["templat"] = {
	description = "Templat dengan kandungan ditakrifkan terlebih dahulu untuk {{{scprosename}}}.",
	umbrella_parents = {"Templat"},
}

script_labels["modul"] = {
	description = "Modul dengan tulisan untuk {{{scprosename}}}.",
	umbrella_parents = {"Modul"},
}

script_labels["modul data"] = {
	description = "Modul yang mengandungi data berkaitan {{{scprosename}}}.",
	umbrella_parents = {"Modul data"},
}



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


raw_categories["Semua tulisan"] = {
	description = "Kategori ini mengandungi kategori untuk setiap jenis tulisan (sistem tulisan) yang ada di Wikikamus.",
	additional = "Sila lihat [[Wikikamus:Senarai tulisan]] untuk senarai lengkap mengenai tulisan.",
	parents = {"Asas"},
}

-- Types of writing systems listed in [[Module:writing systems/data]].
raw_categories["Tulisan mengikut jenis"] = {
	description = "Tulisan mengikut klasifikasi bagaimana tulisan tersebut melambang perkataan.",
	parents = {{ name = "Semua tulisan", sort = " " }},
	breadcrumb = "mengikut jenis",
}

raw_categories["Sistem tulisan alfabet"] = {
	description = "Tulisan dengan simbolnya mewakili bunyi pertuturan individu.",
	parents = {"Tulisan mengikut jenis"},
}

raw_categories["Abjad"] = {
	description = "Tulisan dengan simbol asasnya mewakili bunyi konsonan. Sebahagian daripada aksara tersebut merupakan abjad yang tidak tulen, yang mempunyai huruf untuk beberapa vokal.",
	parents = {"Tulisan mengikut jenis"},
}

raw_categories["Abugida"] = {
	description = "Tulisan dengan simbol asasnya mewakili gabungan konsonan dan vokal. Simbol yang mewakili konsonan yang sama digabungkan dengan vokal yang berbeza kebanyakannya sama dari segi bentuk.",
	parents = {"Tulisan mengikut jenis"},
}

raw_categories["Sistem tulisan logogram"] = {
	description = "Tulisan dengan simbol asasnya mewakili perkataan individu.",
	parents = {"Tulisan mengikut jenis"},
}

raw_categories["Sistem tulisan piktogram"] = {
	description = "Tulisan dengan simbol asasnya mewakili perkataan individu dengan menggunakan simbol yang menyerupai objek fizikal yang dirujuk oleh perkataan tersebut.",
	parents = {"Tulisan mengikut jenis"},
}

raw_categories["Sukukataan separa"] = {
	description = "Tulisan yang merupakan gabungan huruf alfabet dan huruf sukukataan.",
	parents = {"Tulisan mengikut jenis"},
}

raw_categories["Sukukataan"] = {
	description = "Tulisan dengan simbolnya mewakili gabungan konsonan dan vokal. Simbol yang mewakili konsonan yang sama digabungkan dengan vokal yang berbeza kebanyakannya berbeza dari segi bentuk.",
	parents = {"Tulisan mengikut jenis"},
}

for script_label, obj in pairs(script_labels) do
	raw_categories[mw.getContentLanguage():ucfirst(script_label) .. " mengikut tulisan"] = {
		description = "Kategori dengan pelbagai tulisan khusus untuk " .. script_label .. ".",
		breadcrumb = obj.umbrella_breadcrumb or "mengikut tulisan",
		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|Wikipedia]] || ''Rencana Wikipedia berkenaan {{{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|Pertimbangan]] || Pertimbangan berkaitan {{{scdisp}}}
|-
| colspan="2" style="padding-left: 50px; border-bottom: 1px solid lightgray;" | '''[[Wikikamus:Berkenaan {{{scdisp}}}]]'''
|-
| style="vertical-align: middle; height: 35px;" | [[File:Book notice.png|35px|none|Maklumat]] || Maklumat {{{scdisp}}}
|-
| colspan="2" style="padding-left: 50px; border-bottom: 1px solid lightgray;" | '''[[Lampiran:{{{sccat}}}]]'''
|-
| style="vertical-align: Middle; height: 35px;" | [[File:Abc box.svg|35px|none|Kod]] || kod {{{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 = "Kategori ini merupakan kategori utama '''{{{scprosename}}}'''."

-- Additional description text for "root" categories such as [[Category:Arabic script]]. Template substitutions are as described above.
local root_additional = [=[Maklumat berkaitan {{{scprosename}}} mungkin wujud di [[Lampiran:{{{sccat}}}]].

Di pelbagai laman Wikikamus, {{{scprosename}}} dilambang dengan [[Wikikamus:Tulisan|kod {{{codesplural}}}]] {{{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 "" or "",
		codes = table.concat(codes, ", "),
		scname = scname,
		sccat = sc:getCategoryName(),
		scdisp = displayForm,
		scprosename = (displayForm:find("code") or displayForm:find("semaphore")) 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\nTulisan {{{scname}}} merupakan ")
		if mw.ustring.sub(system:getCanonicalName(), 1, 1) == "suatu " then
			table.insert(ret, "suatu ")
		else
			table.insert(ret, "suatu ")
		end
		
		local singular = system:getCategoryName()
		singular = mw.getContentLanguage():lcfirst(singular)
		singular = mw.ustring.gsub(singular, "", "")
		singular = mw.ustring.gsub(singular, "", "")
		
		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("^Tulisan ", "")
	return require("Module:scripts").getByCanonicalName(scriptname) or
		-- [[Category:Undetermined script]] vs. name of script = "undetermined" 
		require("Module:scripts").getByCanonicalName(mw.ustring.lower(scriptname))
end


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


-- 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)
	if not data.category:match("^[Tt]ulisan (.+)$") 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, "Semua tulisan")

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

	return {
		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 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("^(" .. lab .. ") tulisan (.+)$")
		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) .. " mengikut tulisan",
	}

	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}