Pumunta sa nilalaman

Module:category tree/rhymes

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.


local labels = {}
local raw_categories = {}
local handlers = {}
local raw_handlers = {}



-----------------------------------------------------------------------------
--                                                                         --
--                                  LABELS                                 --
--                                                                         --
-----------------------------------------------------------------------------


labels["na tugma"] = { --TLCHANGE
	description = "List of indexes of {{{langname}}} words by their rhymes.",
	umbrella_parents = "Pangkalahatan", --TLCHANGE "Fundamental"
	parents = {{name = "{{{langcat}}}", raw = true}},
	english_name = "rhymes", --TLCHANGE
}

labels["refractory rhymes"] = {
	description = "Lists of {{{langname}}} words that don't rhyme with other words.",
	umbrella_parents = "Rhymes subcategories by language",
	parents = {"na tugma"}, --TLCHANGE {"rhymes"},
}



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


raw_categories["Rhymes subcategories by language"] = {
	description = "Umbrella categories covering topics related to rhymes.",
	additional = "{{{umbrella_meta_msg}}}",
	parents = {
		"Kataas-taasang kategorya", --TLCHANGE "Umbrella metacategories",
		{name = "na tugma", is_label = true, sort = " "}, --TLCHANGE "rhymes"
	},
}


raw_categories["Tugma"] = { --TLCHANGE
	description = "Umbrella categories covering rhymes by language.",
	additional = "{{{umbrella_meta_msg}}}",
	parents = {
		"Kataas-taasang kategorya", --TLCHANGE "Umbrella metacategories",
		{name = "na tugma", is_label = true, sort = " "}, --TLCHANGE "rhymes"
	},
	english_name = "Rhymes", --TLCHANGE
}


-----------------------------------------------------------------------------
--                                                                         --
--                                 HANDLERS                                --
--                                                                         --
-----------------------------------------------------------------------------


table.insert(handlers, function(data)
	local rhyme_beginning = data.label:match("^rhymes/(.-)%-$")
	if rhyme_beginning then
		return {
			description = ("{{{langname}}} rhyme indexes beginning with {{IPAchar|/%s/}}."):format(rhyme_beginning),
			additional = "The entries in this category are not dictionary entries, but rather indexes of {{{langname}}} terms that rhyme in specific ways.",
			parents = {
				{name = "na tugma", sort = rhyme_beginning}, --TLCHANGE "rhymes"
			},
			breadcrumb = {name = ("{{IPAchar|/%s-/}}"):format(rhyme_beginning), nocap = true},
			umbrella = false,
		}
	end
end)


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


table.insert(raw_handlers, function(data)
	local function rhymeTopCategory(lang)
		return {
			lang = lang:getCode(),
			description = "Lists of " .. lang:makeCategoryLink() .. " words by their rhymes.",
			additional = "This is an umbrella category. It contains no dictionary entries, but rather possible rhymes as subcategories.",
			parents = {
				"{{{langcat}}}",
				{name = "Tugma", sort = langname}, --TLCHANGE "Rhymes"
			},
			breadcrumb = "Tugma", --TLCHANGE "Rhymes",
			toctemplateprefix = "rhymetop",
			english_name = "Rhymes:" .. (lang:getData().english_name or lang:getCanonicalName()) --TLCHANGE
		}
	end
	
	local function linkRhymeIfExists(lang, rhyme) -- {{change new|Though this could be ported to Wiktionary}}
		if mw.title.new('Rhymes:' .. lang:getCanonicalName() .. "/" .. rhyme).exists then
			return "'''[[Rhymes:" .. lang:getCanonicalName() .. "/" .. rhyme ..'|<span class="IPA">-' .. rhyme .. "</span>]]'''"
		end
		return '<span class="IPA">-' .. rhyme .. '</span>'
	end
	
	local function rhymeCategory(lang, rhyme)
		return {
			lang = lang:getCode(),
			description = "List of " .. lang:makeCategoryLink() .. ' words with the rhyme ' .. linkRhymeIfExists(lang, rhyme) .. '.',
			parents = {
				{name = "Tugma:" .. lang:getCanonicalName(), sort = rhyme}, --TLCHANGE "Rhymes:"
			},
			breadcrumb = '<span class="IPA">-' .. rhyme .. '</span>',
			displaytitle = 'Tugma:' .. lang:getCanonicalName() .. '/<span class="IPA">' .. rhyme .. '</span>', --TLCHANGE 'Rhymes:'
			english_name = 'Rhymes:' .. (lang:getData().english_name or lang:getCanonicalName()) .. '/<span class="IPA">' .. rhyme .. '</span>', --TLCHANGE
		}
	end
	
	local function rhymeSyllableCountCategory(lang, rhyme, syllableCount)
		return {
			lang = lang:getCode(),
			description = "List of " .. syllableCount .. "-syllable " .. lang:makeCategoryLink() .. ' words with the rhyme ' .. linkRhymeIfExists(lang, rhyme) .. '.',
			parents = {
				{name = "Tugma:" .. lang:getCanonicalName() .. "/" .. rhyme, sort = syllableCount}, --TLCHANGE "Rhymes:"
			},
			breadcrumb = tostring(syllableCount) .. " syllables",
			--TLCHANGE displaytitle = 'Rhymes:' .. lang:getCanonicalName() .. '/<span class="IPA">' .. rhyme .. '</span>/' .. tostring(syllableCount) .. " syllable" .. (syllableCount > 1 and "s" or "")
			displaytitle = 'Tugma:' .. lang:getCanonicalName() .. '/<span class="IPA">' .. rhyme .. '</span>/' .. tostring(syllableCount) .. " pantig",
			english_name =  'Rhymes:' .. (lang:getData().english_name or lang:getCanonicalName()) .. '/<span class="IPA">' .. rhyme .. '</span>/' .. tostring(syllableCount) .. " syllable" .. (syllableCount > 1 and "s" or "") --TLCHANGE
		}
	end
	
	local langname = data.category:match("^Tugma:([^/]+)") --TLCHANGE "^Rhymes:([^/]+)"
	if langname then
		local lang = require("Module:languages").getByCanonicalName(langname)
		if lang then
			local tokens = mw.text.split(data.category, "/")
			if #tokens > 1 then
				local rhyme = tokens[2]
				if #tokens == 3 then
					-- rhyme + syllable count category
					local syllables = nil
					--TLCHANGE
					--[[
					if tokens[3] == "1 syllable" then
						syllables = 1
					else
					]]
						local syllablesregex = tokens[3]:match("(%d+) pantig") --TLCHANGE "(%d+) syllables"
						if syllablesregex then
							syllables = tonumber(syllablesregex)
							if syllables < 2 then
								syllables = nil
							end
						end
					--TLCHANGE end
					if syllables then
						return rhymeSyllableCountCategory(lang, rhyme, syllables)
					end
				elseif #tokens == 2 then
					-- rhyme category
					return rhymeCategory(lang, rhyme)
				end
			else
				-- rhyme language top category
				return rhymeTopCategory(lang)
			end
		end
	end
end)




return {LABELS = labels, RAW_CATEGORIES = raw_categories, HANDLERS = handlers, RAW_HANDLERS = raw_handlers}