模組:Category tree/rhymes
外观
local labels = {}
local raw_categories = {}
local handlers = {}
local raw_handlers = {}
-----------------------------------------------------------------------------
-- --
-- LABELS --
-- --
-----------------------------------------------------------------------------
labels["韻部"] = {
description = "按韻部分類的{{{langname}}}詞語索引列表。",
umbrella_parents = "分类",
parents = {{name = "{{{langcat}}}", raw = true}},
}
labels["無韻部"] = {
description = "與其他詞不押韻的{{{langname}}}詞語列表。",
umbrella_parents = "按語言分類的韻部子分類",
parents = {"韻部"},
}
-----------------------------------------------------------------------------
-- --
-- RAW CATEGORIES --
-- --
-----------------------------------------------------------------------------
raw_categories["韻部子分類"] = {
description = "包含韻部相關主題的元分類。",
additional = "{{{umbrella_meta_msg}}}",
parents = {
"綜合元分類",
{name = "韻部", is_label = true, sort = " "},
},
}
raw_categories["韻部"] = {
description = "按語言分類的韻部元分類。",
additional = "{{{umbrella_meta_msg}}}",
parents = {
"綜合元分類",
{name = "韻部", is_label = true, sort = " "},
},
}
-----------------------------------------------------------------------------
-- --
-- HANDLERS --
-- --
-----------------------------------------------------------------------------
table.insert(handlers, function(data)
-- 匹配 "韻部/a-" 形式的標籤
local rhyme_beginning = data.label:match("^韻部/(.-)%-$")
if rhyme_beginning then
return {
description = ("以{{IPAchar|/%s/}}開頭的{{{langname}}}韻部索引。"):format(rhyme_beginning),
additional = "本分類中的條目不是詞典條目,而是以特定方式押韻的{{{langname}}}詞語索引。",
parents = {
{name = "韻部", sort = rhyme_beginning},
},
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 = "按韻部分類的" .. lang:makeCategoryLink() .. "詞語列表。",
additional = "此為元分類。本分類不包含詞典條目,而是以可能的韻部作為子分類。",
parents = {
"{{{langcat}}}",
{name = "韻部", sort = lang:getCanonicalName()}, -- sort using English name or localized name? Using canonical as per enwikt
},
breadcrumb = "韻部",
toctemplateprefix = "rhymetop"
}
end
local function linkRhymeIfExists(lang, rhyme)
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 = "押 " .. linkRhymeIfExists(lang, rhyme) .. " 韻的" .. lang:makeCategoryLink() .. "詞語列表。",
parents = {
{name = "Rhymes:" .. lang:getCanonicalName(), sort = rhyme},
},
breadcrumb = '<span class="IPA">-' .. rhyme .. '</span>',
displaytitle = 'Rhymes:' .. lang:getCanonicalName() .. '/<span class="IPA">' .. rhyme .. '</span>'
}
end
local function rhymeSyllableCountCategory(lang, rhyme, syllableCount)
return {
lang = lang:getCode(),
description = "押 " .. linkRhymeIfExists(lang, rhyme) .. " 韻的" .. syllableCount .. "音節" .. lang:makeCategoryLink() .. "詞語列表。",
parents = {
{name = "Rhymes:" .. lang:getCanonicalName() .. "/" .. rhyme, sort = syllableCount},
},
breadcrumb = tostring(syllableCount) .. "音節",
displaytitle = 'Rhymes:' .. lang:getCanonicalName() .. '/<span class="IPA">' .. rhyme .. '</span>/' .. tostring(syllableCount) .. "音節"
}
end
local langname = data.category:match("^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
-- 中文版邏輯:檢查 "N音節"
local syllablesregex = tokens[3]:match("(%d+)音節")
if syllablesregex then
local syllables = tonumber(syllablesregex)
if syllables then
return rhymeSyllableCountCategory(lang, rhyme, syllables)
end
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}