Pumunta sa nilalaman

Module:category tree/fam/jpx

Mula Wiksiyonaryo

This data submodule defines part of Wiktionary's category structure.

For an introduction to the category tree system and a description of how to add or modify categories, see Module:category tree/documentation.


----------------------
-- Original authors at [[en:Module:category tree/lang/jpx]].
-- Adapted to Tagalog Wiktionary by [[User:Yivan000]]
----------------------

local labels = {}
local handlers = {}

local m_str_utils = require("Module:string utilities")

local concat = table.concat
local full_link = require("Module:links").full_link
local insert = table.insert
local Hani_sort = require("Module:Hani-sortkey").makeSortKey
local match = m_str_utils.match
local sort = table.sort
local tag_text = require("Module:script_utilities").tag_text
local ucfirst = m_str_utils.ucfirst

local Hira = require("Module:scripts").getByCode("Hira")
local Jpan = require("Module:scripts").getByCode("Jpan")
local kana_to_romaji = require("Module:Hrkt-translit").tr
local m_numeric = require("Module:ConvertNumeric")

local kana_capture = "([-" .. require("Module:ja/data/range").kana .. "・]+)"
local yomi_data = require("Module:kanjitab/data")

labels["na adnominal"] = { --TLCHANGE "adnominals"
	description = "{{{langname}}} adnominals, or {{ja-r|連%体%詞|れん%たい%し}}, which modify nouns, and do not conjugate or [[predicate#Verb|predicate]].",
	parents = {{name = "{{{langcat}}}", raw = true}},
	english_name = "adnominals" --TLCHANGE
}

labels["na hiragana"] = { --TLCHANGE "hiragana"
	description = "{{{langname}}} terms with hiragana {{mdash}} {{ja-r|平%仮%名|ひら%が%な}} {{mdash}} forms, sorted by conventional hiragana sequence. The hiragana form is a [[phonetic]] representation of that word. " ..
	"Wiktionary represents {{{langname}}}-language segments in three ways: in normal form (with [[kanji]], if appropriate), in [[hiragana]] " ..
	"form (this differs from kanji form only when the segment contains kanji), and in [[romaji]] form.",
	additional = "''See also'' [[:Category:{{{langname}}} na katakana]]",
	toc_template = "Hira-categoryTOC",
	toc_template_full = "Hira-categoryTOC/full",
	parents = {
		{name = "{{{langcat}}}", raw = true},
		"Category:Katitikang Hiragana na karakter", --TLCHANGE Hiragana script characters
	},
	english_name = "hiragana" --TLCHANGE
}

labels["na makasaysayang hiragana"] = { --TLCHANGE "historical hiragana"
	description = "{{{langname}}} historical [[hiragana]].",
	additional = "''See also'' [[:Category:{{{langname}}} na makasaysayang katakana]].",
	toc_template = "Hira-categoryTOC",
	toc_template_full = "Hira-categoryTOC/full",
	parents = {
		"na hiragana", --TLCHANGE "hiragana",
		{name = "{{{langcat}}}", raw = true},
		"Category:Katitikang Hiragana na karakter", --TLCHANGE Hiragana script characters
	},
	english_name = "historical hiragana" --TLCHANGE
}

labels["na katakana"] = { --TLCHANGE "katakana"
	description = "{{{langname}}} terms with katakana {{mdash}} {{ja-r|片%仮%名|かた%か%な}} {{mdash}} forms, sorted by conventional katakana sequence. Katakana is used primarily for transliterations of foreign words, including old Chinese hanzi not used in [[shinjitai]].",
	additional = "''See also'' [[:Category:{{{langname}}} na hiragana]]",
	toc_template = "Kana-categoryTOC",
	toc_template_full = "Kana-categoryTOC/full",
	parents = {
		{name = "{{{langcat}}}", raw = true},
		"Category:Katitikang Katakana na karakter", --TLCHANGE Katakana script characters
	},
	english_name = "katakana" --TLCHANGE
}

labels["na makasaysayang katakana"] = { --TLCHANGE "historical katakana"
	description = "{{{langname}}} historical [[katakana]].",
	additional = "''See also'' [[:Category:{{{langname}}} na makasaysayang hiragana]].",
	toc_template = "Kana-categoryTOC",
	toc_template_full = "Kana-categoryTOC/full",
	parents = {
		"na katakana", --TLCHANGE
		{name = "{{{langcat}}}", raw = true},
		"Category:Katitikang Katakana na karakter", --TLCHANGE Katakana script characters
	},
	english_name = "historical katakana" --TLCHANGE
}

labels["na salitang binaybay nang halo-halong kana"] = { --TLCHANGE "terms spelled with mixed kana"
	description = "{{{langname}}} terms which combine [[hiragana]] and [[katakana]] characters, potentially with [[kanji]] too.",
	parents = {
		{name = "{{{langcat}}}", raw = true},
		"na hiragana", --TLCHANGE
		"na katakana", --TLCHANGE
	},
	english_name = "terms spelled with mixed kana" --TLCHANGE
}

labels["na kanji"] = { --TLCHANGE "kanji"
	topright = "{{wp|Kanji}}",
	description = "{{{langname}}} symbols of the Han logographic script, which can represent sounds or convey meanings directly.",
	toc_template = "Hani-categoryTOC",
	umbrella = "na titik-Han", --TLCHANGE "Han characters",
	parents = "na logograma", --TLCHANGE "logograms",
	english_name = "kanji" --TLCHANGE
}

labels["na kanji ayon sa pagbabasa"] = { --TLCHANGE 
	description = "{{{langname}}} kanji categorized by reading.",
	parents = {{name = "na kanji", sort = "pagbabasa"}}, --TLCHANGE "kanji"
	english_name = "kanji by reading" --TLCHANGE
}

labels["na makurakotoba"] = { --TLCHANGE
	topright = "{{wp|Makurakotoba}}",
	description = "{{{langname}}} idioms used in poetry to introduce specific words.",
	parents = {"na sawikain"}, --TLCHANGE {"idioms"},
	english_name = "makurakotoba" --TLCHANGE
}

labels["na salita ayon sa pagbasa ng kanji"] = { --TLCHANGE "terms by kanji readings"
	description = "{{{langname}}} categories grouped with regard to the readings of the kanji with which they are spelled.",
	parents = {{name = "{{{langcat}}}", raw = true}},
	english_name = "terms by kanji readings" --TLCHANGE
}

labels["na salita ayon sa hulwaran ng pagbasa"] = { --TLCHANGE terms by reading pattern
	description = "{{{langname}}} categories with terms grouped by their reading patterns.",
	parents = {{name = "{{{langcat}}}", raw = true}},
	english_name = "terms by reading pattern" --TLCHANGE
}

labels["na salita ayon sa bilang ng kanji"] = { --TLCHANGE "terms by number of kanji"
	description = "{{{langname}}} terms categorized by number of kanji.",
	parents = {"na salita ayon sa katangiang ortograpiko"}, --TLCHANGE {"terms by orthographic property"},
	breadcrumb = "bilang ng kanji", --TLCHANGE
	english_name = "terms by number of kanji" --TLCHANGE
}

local function handle_onyomi_list(category, category_type, cat_yomi_type)
	local onyomi, seen = {}, {}
	for _, yomi in pairs(yomi_data) do
		if not seen[yomi] and yomi.onyomi then
			local yomi_catname = yomi[category_type]
			if yomi_catname ~= false then
				local yomi_type = yomi.type
				if yomi_type ~= "on'yomi" and yomi_type ~= cat_yomi_type then
					insert(onyomi, "[[:Category:{{{langname}}} " .. category:gsub("{{{yomi_catname}}}", yomi_catname) .. "]]")
				end
			end
		end
		seen[yomi] = true
	end
	sort(onyomi)
	return onyomi
end

local function add_yomi_category(category, category_type, parent, description)
	for _, yomi in pairs(yomi_data) do
		local yomi_catname = yomi[category_type]
		if yomi_catname ~= false then
			local yomi_type = yomi.type
			local yomi_desc = yomi.link or yomi_catname
			if yomi.description then
				yomi_desc = yomi_desc .. "; " .. yomi.description
			end
			local label = {
				description = description .. " " .. yomi_desc .. ".",
				breadcrumb = yomi_type,
				parents = {{name = parent, sort = yomi_catname}},
			}
			if yomi.onyomi then
				local onyomi = handle_onyomi_list(category, category_type, yomi_type)
				
				label.additional = "Categories of terms with " ..
					(yomi_type == "on'yomi" and "more" or "other") ..
					" specific types of on'yomi readings can be found in the following categories:\n* " .. concat(onyomi, "\n* ")
				
				if yomi_type ~= "on'yomi" then
					insert(label.parents, 1, {
						name = (category:gsub("{{{yomi_catname}}}", yomi_data.on[category_type])),
						sort = yomi_catname
					})
				end
			end
			labels[category:gsub("{{{yomi_catname}}}", yomi_catname)] = label
		end
	end
end

add_yomi_category(
	"na salitang binabasa nang pa-{{{yomi_catname}}}", --TLCHANGE "terms read with {{{yomi_catname}}}",
	"reading_category",
	"na salita ayon sa hulwaran ng pagbasa", --TLCHANGE "terms by reading pattern"
	"{{{langname}}} terms read with"
)

add_yomi_category(
	"na salitang binaybay ng kanji na binabasa nang pa-{{{yomi_catname}}}", --TLCHANGE "terms spelled with kanji with {{{yomi_catname}}} readings",
	"kanji_category",
	"terms by kanji reading type",
	"{{{langname}}} categories with terms that are spelled with one or more kanji read with"
)

labels["na salitang may nawawalang yomi"] = { --TLCHANGE "terms with missing yomi"
	description = "{{{langname}}} terms where at least one [[Appendix:Japanese glossary#yomi|yomi]] is missing from {{tl|{{{langcode}}}-kanjitab}}.",
	hidden = true,
	can_be_empty = true,
	parents = {"na entradang pinapanatili"}, --TLCHANGE "entry maintenance"
	english_name = "terms with missing yomi" --TLCHANGE
}

labels["terms with IPA pronunciation with pitch accent"] = {
	description = "{{{langname}}} terms with pronunciations that have {{w|Japanese pitch accent|pitch accent}} specified.",
	additional = "Pitch accent can be specified in {{tl|{{{langcode}}}-pron}} with the {{code|=acc=}} parameter.",
	can_be_empty = true,
	parents = {"entry maintenance", "pitch accent"},
}

labels["terms with IPA pronunciation missing pitch accent"] = {
	description = "{{{langname}}} terms with pronunciations that do not have a {{w|Japanese pitch accent|pitch accent}} specified.",
	additional = "Pitch accent can be specified in {{tl|{{{langcode}}}-pron}} with the {{code|=acc=}} parameter.",
	hidden = true,
	can_be_empty = true,
	parents = {"na entradang pinapanatili"}, --TLCHANGE "entry maintenance"
}

labels["pitch accent"] = {
	description = "{{{langname}}} terms regarding {{w|Japanese pitch accent|pitch accent}} pronunciation.",
	can_be_empty = true,
	parents = {{name = "{{{langcat}}}", raw = true}},
}

labels["terms with Heiban pitch accent (Tōkyō)"] = {
	description = "{{{langname}}} terms with pronunciations that are (Tōkyō) [[平板型|Heiban]] {{w|Japanese pitch accent|pitch accent}}.",
	can_be_empty = true,
	parents = {"pitch accent"}
}

labels["terms with Atamadaka pitch accent (Tōkyō)"] = {
	description = "{{{langname}}} terms with pronunciations that are (Tōkyō) [[頭高型|Atamadaka]] {{w|Japanese pitch accent|pitch accent}}.",
	can_be_empty = true,
	parents = {"pitch accent"}
}

labels["terms with Nakadaka pitch accent (Tōkyō)"] = {
	description = "{{{langname}}} terms with pronunciations that are (Tōkyō) [[中高型|Nakadaka]] {{w|Japanese pitch accent|pitch accent}}.",
	can_be_empty = true,
	parents = {"pitch accent"}
}

labels["terms with Odaka pitch accent (Tōkyō)"] = {
	description = "{{{langname}}} terms with pronunciations that are (Tōkyō) [[尾高型|Odaka]] {{w|Japanese pitch accent|pitch accent}}.",
	can_be_empty = true,
	parents = {"pitch accent"}
}

labels["pitch accent deaccenting before の"] = {
	description = "{{{langname}}} terms with {{w|Japanese pitch accent|pitch accent}} pronunciations that have exceptional deaccenting or lack thereof before の ({{ja-deaccenting-before-no}}).",
	can_be_empty = true,
	parents = {"pitch accent"}
}

labels["terms with Odaka pitch accent not deaccented before の (Tōkyō)"] = {
	description = "{{{langname}}} terms with pronunciations that are (Tōkyō) [[尾高型|Odaka]] {{w|Japanese pitch accent|pitch accent}} and do not become deaccented before の ({{ja-deaccenting-before-no}}).",
	can_be_empty = true,
	parents = {"pitch accent deaccenting before の"}
}

labels["terms with Nakadaka pitch accent deaccented before の (Tōkyō)"] = {
	description = "{{{langname}}} terms with pronunciations that are (Tōkyō) [[中高型|Nakadaka]] {{w|Japanese pitch accent|pitch accent}} and become deaccented before の ({{ja-deaccenting-before-no}}).",
	can_be_empty = true,
	parents = {"pitch accent deaccenting before の"}
}

labels["terms by kanji reading type"] = {
	description = "{{{langname}}} categories with terms grouped with regard to the types of readings of the kanji with which " ..
	"they are spelled; broadly, those of Chinese origin, {{ja-r|音|おん}} readings, and those of non-Chinese origin, {{ja-r|訓|くん}} readings.",
	parents = {{name = "{{{langcat}}}", raw = true}},
}

labels["na salitang binaybay nang may ateji"] = { --TLCHANGE "terms spelled with ateji"
	topright = "{{wp|Ateji}}",
	description = "{{{langname}}} terms containing one or more [[Appendix:Japanese glossary#ateji|ateji]] {{mdash}} {{ja-r|当て字|あてじ}} {{mdash}} which are [[kanji]] used to represent sounds rather than meanings (though meaning may have some influence on which kanji are chosen).",
	parents = {{name = "{{{langcat}}}", raw = true}},
	english_name = "terms spelled with ateji" --TLCHANGE
}

labels["na salitang binaybay nang may daiyōji"] = { --TLCHANGE "terms spelled with daiyōji"
	description = "Japanese terms spelled using [[Appendix:Japanese glossary#daiyouji|daiyōji]], categorized using {{temp|ja-daiyouji}}.",
	parents = {"na salita ayon sa etimolohiya"}, --TLCHANGE: "terms by etymology"
	english_name = "terms spelled with daiyōji" --TLCHANGE
}

labels["na salitang binaybay nang may jukujikun"] = { --TLCHANGE "terms spelled with jukujikun"
	description = "{{{langname}}} terms containing one or more [[Appendix:Japanese glossary#jukujikun|jukujikun]] {{mdash}} {{ja-r|熟%字%訓|じゅく%じ%くん}} {{mdash}} which are [[kanji]] used to represent meanings rather than sounds.",
	parents = {{name = "{{{langcat}}}", raw = true}},
}

local function add_grade_categories(grade, desc, wp, only_one, parent, sort, grade_english) --TLCHANGE add "grade_english" param
	local grade_kanji = "kanjing " .. grade  --TLCHANGE " kanji"
	local topright = wp and ("{{wp|%s}}"):format(ucfirst(grade_kanji)) or nil
	
	labels["na " ..grade_kanji] = { --TLCHANGE 	labels[grade_kanji] = {
		topright = topright,
		description = "{{{langname}}} kanji " .. desc,
		toc_template = "Hani-categoryTOC",
		parents = {{
			name = parent and ("na kanjing "..parent) or "na kanji",  --TLCHANGE parent and (parent .. " kanji") or "kanji",
			sort = sort or grade
		}},
		english_name = (grade_english or grade) .. " kanji" --TLCHANGE
	}
	
	labels["na salitang binaybay ng " .. grade_kanji] = { --TLCHANGE "terms spelled with "
		topright = topright,
		description = "{{{langname}}} terms spelled with " .. (only_one and "at least one " or "") .. "kanji " .. desc,
		breadcrumb = grade, --TLCHANGE add breadcrumb
		parents = {{
			--TLCHANGE name = parent and ("terms spelled with " .. parent .. " kanji") or "terms by orthographic property",
			name = parent and ("na salitang binaybay ng kanjing " .. parent) or "na salita ayon sa katangiang ortograpiko", 
			sort = sort or grade
		}},
		english_name = "terms spelled with " .. grade:gsub("^pang%-", ""):gsub("baitang", "grade") .. " kanji" --TLCHANGE
	}
end

for i = 1, 6 do
	local ord = m_numeric.ones_position_ord[i]
	add_grade_categories(
		"pang-baitang "  .. tostring(i), --TLCHANGE ord .. " grade",
		"taught in the " .. ord .. " grade of elementary school, as designated by the the official list of {{ja-r|教%育 漢%字|きょう%いく かん%じ|education kanji}}.",
		false,
		false,
		"kyōiku",
		i,
		ord .. " grade" --TLCHANGE grade_english param
	)
end

add_grade_categories(
	"kyōiku",
	"on the official list of {{ja-r|教%育 漢%字|きょう%いく かん%じ|education kanji}}.",
	true,
	false,
	"jōyō"
)

add_grade_categories(
	"pang-sekundarya", --TLCHANGE "secondary school"
	"on the official list of {{ja-r|常%用 漢%字|じょう%よう かん%じ|regular-use characters}} that are generally taught in secondary school.",
	false,
	false,
	"jōyō",
	nil,
	"secondary school" --TLCHANGE grade_english param
)

add_grade_categories(
	"jōyō",
	"on the official list of {{ja-r|常%用 漢%字|じょう%よう かん%じ|regular-use characters}}.",
	true,
	false
)

add_grade_categories(
	"tōyō",
	"on the official list of {{ja-r|当%用 漢%字|とう%よう かん%じ|general-use characters}}, which was used from 1946{{ndash}}1981 until the publication of the list of {{ja-r|常%用 漢%字|じょう%よう かん%じ|regular-use characters}}.",
	true,
	false
)

add_grade_categories(
	"pang-jinmeiyō", --TLCHANGE "jinmeiyō"
	"on the official list of {{ja-r|人%名%用 漢%字|じん%めい%-よう かん%じ|kanji for use in personal names}}.",
	true,
	true,
	nil,
	nil,
	"jinmeiyō" --TLCHANGE grade_english param
)

add_grade_categories(
	"pang-hyōgai", --TLCHANGE "hyōgai"
	"not included on the official list of {{ja-r|常%用 漢%字|じょう%よう かん%じ|regular-use characters}} or {{ja-r|人%名%用 漢%字|じん%めい%-よう かん%じ|kanji for use in personal names}}, known as {{ja-r|表%外 漢%字|ひょう%がい かん%じ}} or {{ja-r|表%外%字|ひょう%がい%じ|unlisted characters}}.",
	true,
	true,
	nil,
	nil,
	"hyōgai" --TLCHANGE grade_english param
)

labels["na salitang maraming pagbabasa"] = { --TLCHANGE "terms with multiple readings"
	description = "{{{langname}}} terms with multiple pronunciations (hence multiple [[kana]] spellings).",
	parents = {{name = "{{{langcat}}}", raw = true}},
	english_name = "terms with multiple readings" --TLCHANGE
}

labels["na pagbasa ng kanji ayon sa bilang ng mora"] = { --TLCHANGE "kanji readings by number of morae"
	description = "{{{langname}}} categories grouped with regard to the number of morae in their kanji readings.",
	parents = {{name = "{{{langcat}}}", raw = true}},
	english_name = "kanji readings by number of morae" --TLCHANGE
}

labels["single-kanji terms"] = {
	description = "{{{langname}}} terms written as a single kanji.",
	parents = {
		"na salita ayon sa katangiang ortograpiko", --TLCHANGE {"terms by orthographic property"},
		{name = "na salitang may 1 kanji", sort = " "}, --TLCHANGE "terms with 1 kanji"
	},
}

labels["kanji with kun readings missing okurigana designation"] = {
	breadcrumb = "Kanji missing okurigana designation",
	description = "{{{langname}}} kanji entries in which one or more kun readings entered into {{tl|{{{langcode}}}-readings}} is missing a hyphen denoting okurigana.",
	toc_template = "Hani-categoryTOC",
	hidden = true,
	can_be_empty = true,
	parents = {"na entradang pinapanatili"}, --TLCHANGE "entry maintenance"
}

labels["terms by the individual characters in their historical spellings"] = {
	breadcrumb = "Historical",
	description = "{{{langname}}} terms categorized by whether their spellings in the {{w|historical kana orthography}} included certain individual characters.",
	parents = {{name = "terms by their individual characters", sort = " "}},
}

labels["verbs without transitivity"] = {
	description = "{{{langname}}} verbs missing the {{code|=tr=}} parameter from their headword templates.",
	hidden = true,
	can_be_empty = true,
	parents = {"na entradang pinapanatili"}, --TLCHANGE "entry maintenance"
}

labels["yojijukugo"] = {
	topright = "{{wp|Yojijukugo}}",
	description = "{{{langname}}} four-[[kanji]] compound terms, {{ja-r|四%字 熟%語|よ%じ じゅく%ご}}, with idiomatic meanings; typically derived from Classical Chinese, Buddhist scripture or traditional Japanese proverbs.",
	additional = "Compare Chinese {{w|chengyu}} and Korean {{w|sajaseong-eo}}.",
	umbrella = "four-character idioms",
	parents = {"na sawikain"}, --TLCHANGE {"idioms"},
}

-- FIXME: Only works for 0 through 19.
local word_to_number = {}
for k, v in pairs(m_numeric.ones_position) do
	word_to_number[v] = k
end

local periods = { --TLCHANGE use values as the english name
	makasaysayang = "historical", -- TLCHANGE historical = true,
	makasaysayan = "historical", -- TLCHANGE add
	sinaunang = "ancient", --TLCHANGE ancient = true,
	sinauna = "ancient", --TLCHANGE add
}

local function get_period_text_and_reading_type_link(period, reading_type)
	if period and not periods[period] then
		return nil
	end
	local period_text = period and period .. " " or nil

	-- Allow periods (historical or ancient) by themselves; they will parse as reading types.
	if not period and periods[reading_type] then
		return nil, reading_type, periods[reading_type] --TLCHANGE add third result for the english name
	end

	local reading_type_link = "[[Appendix:Japanese glossary#" .. reading_type .. "|" .. reading_type .. "]]"
	return period_text, reading_type_link, (period and periods[period] or "") --TLCHANGE add third return result for the english name
end

local function get_sc(str)
	return match(str:gsub("[%s%p]+", ""), "[^" .. Hira:getCharacters() .. "]") and Jpan or Hira
end
		
local function get_tagged_reading(reading, lang)
	return tag_text(reading, lang, get_sc(reading))
end

local function get_reading_link(reading, lang, period, link)
	local hist = periods[period]
	reading = reading:gsub("[%.%-%s]+", "")
	return full_link({
		lang = lang,
		sc = get_sc(reading),
		term = link or reading:gsub("・", ""),
		-- If we have okurigana, demarcate furigana.
		alt = reading:gsub("^(.-)・", "<span style=\"border-top:1px solid;position:relative;padding:1px;\">%1<span style=\"position:absolute;top:0;bottom:67%%;right:0%%;border-right:1px solid;\"></span></span>"),
		tr = kana_to_romaji((reading:gsub("・", ".")), lang:getCode(), nil, {keep_dot = true, hist = hist})
			:gsub("^(.-)%.", "<u>%1</u>"),
		pos = reading:find("・", 1, true) and get_tagged_reading((reading:gsub("^.-・", "~")), lang) or nil
	}, "term")
end

local function is_on_subtype(reading_type)
	return reading_type:find(".on$")
end

insert(handlers, function(data)
	local n =data.label:match("^na salitang may ([1-9]%d*) kanji$") --TLCHANGE "^terms with ([1-9]%d*) kanji$"
	if not n then
		return
	end
	local sortkey = require("Module:category tree").numeral_sortkey(n, 2097152)
	return {
		breadcrumb = n,
		description = ("{{{langname}}} terms containing exactly %d kanji."):format(n),
		-- TODO: implement this using the same mechanism used to implement parents (i.e. avoiding the need for raw categories).
--		umbrella = {
--			breadcrumb = ("%d kanji"):format(n),
--			parents = {{name = "terms by number of kanji subcategories by language", sort = sortkey}},
--		},
		parents = {{name = ("na salita ayon sa bilang ng kanji"), sort = sortkey}}, --TLCHANGE
		english_name = ("terms with %d kanji"):format(n) --TLCHANGE
	}
end)


insert(handlers, function(data)
	local label_pref, kana = data.label:match("^(terms historically spelled with )" .. kana_capture .. "$")
	
	if not kana then
		return
	end
	
	local lang = data.lang
	
	return {
		description = "{{{langname}}} terms spelled with " .. get_reading_link(kana, lang, "historical") .. " in the {{w|historical kana orthography}}.",
		displaytitle = "{{{langname}}} " .. label_pref .. get_tagged_reading(kana, lang),
		breadcrumb = "historical",
		parents = {
			{name = "na salitang binaybay ng " .. kana, sort = " "}, --TLCHANGE "terms spelled with"
			{name = "terms by the individual characters in their historical spellings", sort = lang:makeSortKey(kana)}
		},
		umbrella = false,
	}
end)


insert(handlers, function(data)
	--TLCHANGE `count` is originally an english number word (eg. "two"), but now it's a number (eg. 2)
	local count, plural = data.label:match("^na pagbasa ng kanji na may (.+) mora$") --TLCHANGE "^kanji readings with (.+) mora(e?)$"
	
	-- Make sure 'one' goes with singular and other numbers with plural.
	--TLCHANGE if not count or (count == "one") ~= (plural == "") then
	if not count or (count == "0") ~= (plural == "") then
		return
	end
	
	--[=[ TLCHANGE
	local num = word_to_number[count]
	if not num then
		return nil
	end ]=]
	
	return {
		--TLCHANGE description = "{{{langname}}} kanji readings containing " .. count .. " mora" .. plural .. ".",
		description = "{{{langname}}} kanji readings containing " .. count .. " mora.",
		breadcrumb = num,
		parents = {{name = "na pagbasa ng kanji ayon sa bilang ng mora", sort = num}}, --TLCHANGE "kanji readings by number of morae"
		umbrella = false,
		english_name = "kanji readings with " .. count .. (count=="0" and " mora" or " morae") --TLCHANGE
	}
end)


insert(handlers, function(data)
	local label_pref, period, reading_type, reading = match(data.label, "^(na kanjing may pagbabasang ([a-z]-) ?([%a']+) na )" .. kana_capture .. "$") --TLCHANGE "^(kanji with ([a-z]-) ?([%a']+) reading )" .. kana_capture .. "$"
	
	if not period then
		return
	end
	
	period = period ~= "" and period or nil
	local period_text, reading_type_link, period_english_name = get_period_text_and_reading_type_link(period, reading_type) --TLCHANGE add period_english_name
	
	if not reading_type_link then
		return
	end
	
	local lang = data.lang
	
	-- Compute parents.
	local parents, breadcrumb = {}
	if reading:find("・", 1, true) then
		local okurigana = reading:match("・(.*)")
		insert(parents, {
			--TLCHANGE name = "kanji with " .. (period_text or "") .. reading_type .. " reading " .. reading:match("(.-)・"),
			name = "na kanjing may pagbabasang " .. (period_text or "") .. reading_type .. " na " .. reading:match("(.-)・"),
			-- Sort by okurigana, since all coordinate categories will have the same furigana.
			sort = (lang:makeSortKey(okurigana))
		})
		breadcrumb = "~" .. okurigana
	else
		insert(parents, {
			--TLCHANGE name = "kanji by " .. (period_text or "") .. reading_type .. " reading",
			name = "na kanjing may pagbabasang " .. (period_text or "") .. reading_type,
			sort = (lang:makeSortKey(reading))
		})
		breadcrumb = reading
	end
	if is_on_subtype(reading_type) then
		--TLCHANGE insert(parents, {name = "kanji with " .. (period_text or "") .. "on reading " .. reading, sort = reading_type})
		insert(parents, {name = "na kanjing may pagbabasang " .. (period_text or "") .. "on na " .. reading, sort = reading_type})
	elseif period_text then
		--TLCHANGE remove pang-angkop "-ng" from "makasaysayang" and "sinaunang"
		local remove_pang_angkop = {
			["makasaysayang "] = "makasaysayan",
			["sinaunang "] = "sinauna",
		}
		
		--TLCHANGE insert(parents, {name = "kanji with " .. period_text .. "reading " .. reading, sort = reading_type})
		insert(parents, {name = "na kanjing may pagbabasang " .. (remove_pang_angkop[period_text] or period_text) .. " na " .. reading, sort = reading_type})
	end
	if not period_text then
		--TLCHANGE insert(parents, {name = "kanji read as " .. reading, sort = reading_type})
		insert(parents, {name = "na kanjing binabasa nang " .. reading, sort = reading_type})
	end
	
	return {
		description = "{{{langname}}} [[kanji]] with the " .. (period_text or "") .. reading_type_link .. " reading " ..
			get_reading_link(reading, lang, period or reading_type) .. ".",
		displaytitle = "{{{langname}}} " .. label_pref .. get_tagged_reading(reading, lang),
		breadcrumb = get_tagged_reading(breadcrumb, lang),
		parents = parents,
		umbrella = false,
		english_name = "kanji with " .. period_english_name .. " " .. reading_type .. " reading " .. reading --TLCHANGE
	}
end)

insert(handlers, function(data)
	local period, reading_type = match(data.label, "^na kanjing may pagbabasang ([a-z]-) ?([%a']+)$") --TLCHANGE "^kanji by ([a-z]-) ?([%a']+) reading$
	
	if not period then
		return
	end
	
	period = period ~= "" and period or nil
	local period_text, reading_type_link, period_english_name = get_period_text_and_reading_type_link(period, reading_type) --TLCHANGE add period_english_name
	
	if not reading_type_link then
		return nil
	end

	-- Compute parents.
	local parents = {
		is_on_subtype(reading_type) and {name = "na kanjing may pagbabasang " .. (period_text or "") .. "on", sort = reading_type} or --TLCHANGE {name = "kanji by " .. (period_text or "") .. "on reading", sort = reading_type}
		period_text and {name = "na kanjing may pagbabasang " .. reading_type, sort = period} or --TLCHANGE {name = "kanji by " .. reading_type .. " reading", sort = period}
		{name = "na kanji ayon sa pagbabasa", sort = reading_type} --TLCHANGE "kanji by reading"
	}
	if period_text then
		--TLCHANGE remove pang-angkop "-ng" from "makasaysayang" and "sinaunang"
		local remove_pang_angkop = {
			["makasaysayang "] = "makasaysayan",
			["sinaunang "] = "sinauna",
		}
		--TLCHANGE insert(parents, {name = "kanji by " .. period_text .. "reading", sort = reading_type})
		insert(parents, {name = "na kanjing may pagbabasang " .. (remove_pang_angkop[period_text] or period_text), sort = reading_type})
	end

	-- Compute description.
	local description = "{{{langname}}} [[kanji]] categorized by " .. (period_text or "") .. reading_type_link .. " reading."
	return {
		description = description,
		breadcrumb = (period_text or "") .. reading_type,
		parents = parents,
		umbrella = false,
		english_name = "kanji by " .. --TLCHANGE
			(period_english_name == periods[reading_type] and "" or period_english_name) --TLCHANGE this is so that the output won't be "Japanese kanji by historical historical reading"
			.. " " .. (periods[reading_type] or reading_type) .. " reading", --TLCHANGE
	}
end)


insert(handlers, function(data)
	local label_pref, reading = match(data.label, "^(na kanjing binabasa nang )" .. kana_capture .. "$") --TLCHANGE "^(kanji read as )"
	
	if not reading then
		return
	end
	
	local args = require("Module:parameters").process(data.args, {
		["histconsol"] = true,
	})
	local lang = data.lang
	
	local parents, breadcrumb = {}
	if reading:find("・", 1, true) then
		local okurigana = reading:match("・(.*)")
		insert(parents, {
			name = "na kanjing binabasa nang " .. reading:match("(.-)・"), --TLCHANGE "kanji read as " .. reading:match("(.-)・"),
			-- Sort by okurigana, since all coordinate categories will have the same furigana.
			sort = (lang:makeSortKey(okurigana))
		})
		breadcrumb = "~" .. okurigana
	else
		insert(parents, {
			name = "na kanji ayon sa pagbabasa", --TLCHANGE "kanji by reading"
			sort = (lang:makeSortKey(reading))
		})
		breadcrumb = reading
	end
	
	local addl
	local period_text
	if args.histconsol then
		period_text = "historical"
		addl = ("This is a [[Wikipedia:Historical kana orthography|historical]] [[Wikipedia:Kanazukai|reading]], now " ..
		"consolidated with the [[Wikipedia:Modern kana usage|modern reading]] of " ..
		get_reading_link(args.histconsol, lang, nil, ("Category:Japanese kanji read as %s"):format(args.histconsol)) .. ".")
	end
	
	return {
		description = "{{{langname}}} [[kanji]] read as " .. get_reading_link(reading, lang, period_text) .. ".",
		additional = addl,
		displaytitle = "{{{langname}}} " .. label_pref .. get_tagged_reading(reading, lang),
		breadcrumb = get_tagged_reading(breadcrumb, lang),
		parents = parents,
		umbrella = false,
		english_name = "kanji read as " .. reading --TLCHANGE
	}, true
end)


insert(handlers, function(data)
	--TLCHANGE  	local label_pref, reading = match(data.label, "^(terms spelled with kanji read as )" .. kana_capture .. "$")
	local label_pref, reading = match(data.label, "^(na salitang binaybay ng kanji na binabasa nang )" .. kana_capture .. "$")
	
	if not reading then
		return
	end
	
	-- Compute parents.
	local lang = data.lang
	local sort_key = (lang:makeSortKey(reading))
	local mora_count = require("Module:ja").count_morae(reading)
	--TLCHANGE  comment out this, no need to be in spelled out number
	-- local mora_count_words = m_numeric.spell_number(tostring(mora_count))
	local parents = {
		{name = "na salita ayon sa pagbasa ng kanji", sort = sort_key}, --TLCHANGE "terms by kanji readings"
		--TLCHANGE 		{name = "kanji readings with " .. mora_count_words .. " mora" .. (mora_count > 1 and "e" or ""), sort = sort_key},
		{name = "na pagbasa ng kanji na may " .. tostring(mora_count) .. " mora", sort = sort_key},
		{name = "na kanjing binabasa nang " .. reading, sort = " "}, --TLCHANGE "kanji read as " .. reading
	}

	local tagged_reading = get_tagged_reading(reading, lang)
	return {
		description = "{{{langname}}} terms that contain kanji that exhibit a reading of " .. get_reading_link(reading, lang) ..
		" in those terms prior to any sound changes.",
		displaytitle = "{{{langname}}} " .. label_pref .. tagged_reading,
		breadcrumb = tagged_reading,
		parents = parents,
		umbrella = false,
		english_name = "terms spelled with kanji read as " .. reading, --TLCHANGE
	}
end)


insert(handlers, function(data)
	--TLCHANGE local kanji, reading = match(data.label, "^terms spelled with (.) read as " .. kana_capture .. "$") 
	local kanji, reading = match(data.label, "^na salitang binaybay ng (.) na binabasa nang " .. kana_capture .. "$") 
	
	if not kanji then
		return nil
	end
	
	local args = require("Module:parameters").process(data.args, {
		[1] = {list = true},
	})
	local lang = data.lang
	
	if #args[1] == 0 then
		error("For categories of the form \"" .. lang:getCanonicalName() ..
			" terms spelled with KANJI read as READING\", at least one reading type (e.g. <code>kun</code> or <code>on</code>) must be specified using <code>1=</code>, <code>2=</code>, <code>3=</code>, etc.")
	end
	local yomi_types, parents = {}, {}
	for _, yomi, category in ipairs(args[1]) do
		local yomi_data = yomi_data[yomi]
		if not yomi_data then
			error("The yomi type \"" .. yomi .. "\" is not recognized.")
		end
		category = yomi_data.kanji_category
		if not category then
			error("The yomi type \"" .. yomi .. "\" is not valid for this type of category.")
		end
		insert(yomi_types, yomi_data.link)
		insert(parents, {
			name = "na salitang binaybay ng kanji na binabasa nang " .. category, --TLCHANGE "terms spelled with kanji with " .. category .. " readings",
			sort = (lang:makeSortKey(reading))
		})
	end
	
	insert(parents, 1, {name = "na salitang binaybay ng " .. kanji, sort = (lang:makeSortKey(reading))}) --TLCHANGE "terms spelled with " .. kanji
	insert(parents, 2, {name = "na salitang binaybay ng kanji na binabasa nang " .. reading, sort = Hani_sort(kanji)}) --TLCHANGE "terms spelled with kanji read as " .. readin
	
	--TLCHANGE
	yomi_types = (#yomi_types > 1 and "one of " or "") .. "pagbabasang " ..
		require("Module:table").serialCommaJoin(yomi_types, {conj = "o"}) ..
		" nito"
	
	local tagged_kanji = get_tagged_reading(kanji, lang)
	local tagged_reading = get_tagged_reading(reading, lang)
	return {
		description = "{{{langname}}} na salitang binaybay nang may {{l|{{{langcode}}}|" .. kanji .. "}} na ang " ..
			yomi_types .. " ay " .. get_reading_link(reading, lang) .. ".",
		displaytitle = "{{{langname}}} na salitang binaybay ng " .. tagged_kanji .. " na binabasa nang " .. tagged_reading, --TLCHANGE
		breadcrumb = "Binabasa nang " .. tagged_reading, --TLCHANGE
		parents = parents,
		umbrella = false,
		english_name = "terms spelled with " .. tagged_kanji .. " read as " .. tagged_reading --TLCHANGE
	}, true
end)


insert(handlers, function(data)
	local affix, kanji, reading = data.label:match("^terms ([a-z]+fix)ed with (.+) read as "  .. kana_capture .. "$")
	
	if not affix or not kanji or not reading then
		return nil
	end
	
	local args = require("Module:parameters").process(data.args, {
		[1] = {list = true},
	})
	local lang = data.lang
	
	if #args[1] == 0 then
		error("For categories of the form \"" .. lang:getCanonicalName() ..
			" terms AFFIXed with KANJI read as READING\", at least one reading type (e.g. <code>kun</code> or <code>on</code>) must be specified using <code>1=</code>, <code>2=</code>, <code>3=</code>, etc.")
	end
	local yomi_types = {}
	for _, yomi, category in ipairs(args[1]) do
		local yomi_data = yomi_data[yomi]
		if not yomi_data then
			error("The yomi type \"" .. yomi .. "\" is not recognized.")
		end
		category = yomi_data.kanji_category
		if not category then
			error("The yomi type \"" .. yomi .. "\" is not valid for this type of category.")
		end
		insert(yomi_types, yomi_data.link)
	end
	
	yomi_types = (#yomi_types > 1 and "one of " or "") .. "its " ..
		require("Module:table").serialCommaJoin(yomi_types, {conj = "or"}) ..
		" reading" .. (#yomi_types > 1 and "s" or "")
	
	local description = "{{{langname}}} terms " .. affix .. "ed with {{l|{{{langcode}}}|" .. kanji .. "}} with " ..
			yomi_types .. " of " .. get_reading_link(reading, lang) .. "."
	local tl
	if affix == "suffix" then
		tl = "{{tl|ja-compound|<var>|...|</var>|" .. kanji .. "|-" .. reading .. "}}"
	elseif affix == "prefix" then
		tl = "{{tl|ja-compound|" .. kanji .. "|" .. reading .. "-|<var>|...|</var>}}"
	elseif affix == "infix" then
		tl = "{{tl|ja-compound|<var>|...|</var>|" .. kanji .. "|-" .. reading .. "-|<var>|...|</var>}}"
	end
	if tl then
		description = description .. "\n\n" .. "Terms are placed in this category using " .. tl .. "."
	end
	
	local parents = {}
	table.insert(parents, {name = "terms " .. affix .. "ed with " .. kanji, sort = (lang:makeSortKey(reading))})
	if mw.title.new("Category:" .. lang:getCanonicalName() .. " terms spelled with " .. kanji .. " read as " .. reading).exists then
		table.insert(parents, {name = "terms spelled with " .. kanji .. " read as " .. reading, sort = (lang:makeSortKey(reading)), args=data.args})
	end
	
	local tagged_kanji = get_tagged_reading(kanji, lang)
	local tagged_reading = get_tagged_reading(reading, lang)
	return {
		description = description,
		displaytitle = "{{{langname}}} terms " .. affix .. "ed with " .. tagged_kanji .. " read as " .. tagged_reading,
		breadcrumb = "read as " .. reading,
		parents = parents,
		umbrella = false,
	}, true
end)


insert(handlers, function(data)
	--TLCHANGE "^terms with (.) replaced by daiyōji (.)$"
	local kanji, daiyoji = match(data.label, "^na salitang may (.) na pinalitan ng daiyōji na (.)$")
	
	if not kanji then
		return nil
	end
	
	local args = require("Module:parameters").process(data.args, {
		["sort"] = true,
	})
	local lang = data.lang
	
	if not args.sort then
		error("For categories of the form \"" .. lang:getCanonicalName() ..
			" terms with KANJI replaced by daiyōji DAIYOJI\", the sort key must be specified using sort=")
	end

	local tagged_kanji = get_tagged_reading(kanji, lang)
	local tagged_daiyoji = get_tagged_reading(daiyoji, lang)
	return {
		description = "{{{langname}}} terms with {{l|{{{langcode}}}|" .. kanji .. "}} replaced by [[Appendix:Japanese glossary#daiyouji|daiyōji]] {{l|{{{langcode}}}|" .. daiyoji .. "}}.",
		displaytitle = "{{{langname}}} na salitang may " .. tagged_kanji .. " na pinalitan ng daiyōji na " .. tagged_daiyoji, --TLCHANGE
		breadcrumb = tagged_kanji .. " na pinalitan ng daiyōji na " .. tagged_daiyoji, --TLCHANGE tagged_kanji .. " replaced by daiyōji " .. tagged_daiyoji,
		parents = {{name = "na salitang binaybay nang may daiyōji", sort = args.sort}}, --TLCHANGE "terms spelled with daiyōji"
		umbrella = false,
		english_name = "terms with " .. tagged_kanji .. " replaced by daiyōji " .. tagged_daiyoji, --TLCHANGE
	}, true
end)

return {LABELS = labels, HANDLERS = handlers}