模块:读音显示
来自潮语辞书
更多操作
此模块的文档可以在模块:读音显示/doc创建
local p = {}
local mw = mw
function p.render(frame)
local char = frame.args[1]
if not char or char == "" then
return "错误:缺少字。"
end
local mode = frame.args[2] or "潮拼"
local region_order = {
"饶平-三饶片","饶平-黄冈片","饶平-南澳片",
"海阳-府城片","海阳-潮安片",
"澄海-澄城片","澄海-东里片",
"汕头-埠区片",
"潮阳-外山片","潮阳-内山片","潮阳-榕腔片",
"揭阳-榕城片","揭阳-棉湖片",
"惠来-惠城片","惠来-葵潭片","惠来-靖海片",
"普宁-洪阳片","普宁-流沙片",
"丰顺片","域外方音"
}
local region_groups = {
-- 保持你原来的完整映射……
}
-- 存放缺失数据,按分组分类
local missing = {}
local function renderRegions(regions, group_name)
local items = {}
for _, region in ipairs(regions) do
local reading = frame:callParserFunction{
name = "#invoke",
args = { "字表调用", "getReading", char, region, mode }
}
if reading:find('class="error"') then
-- 收集错误信息
table.insert(missing, string.format("%s(%s)", group_name, region))
table.insert(items,
string.format('<li><span class="place">%s</span><span class="missing">[无数据]</span></li>', region)
)
else
table.insert(items,
string.format('<li><span class="place">%s</span><span class="pronunciation">%s</span></li>', region, reading)
)
end
end
return table.concat(items, "\n")
end
local class = (mode == "IPA") and "pronunciation-ipa" or "pronunciation-chao"
local html = { string.format('<div class="entry-section regional-pronunciation-section %s">', class) }
table.insert(html, "<h2>各地方音</h2>")
for _, group_name in ipairs(region_order) do
local regions = region_groups[group_name]
if regions then
table.insert(html, '<div class="region-group">')
table.insert(html, string.format('<div class="shanggu-serif"><big>%s</big></div>', group_name))
table.insert(html, '<ul class="dialect-list">')
table.insert(html, renderRegions(regions, group_name))
table.insert(html, "</ul></div>")
end
end
-- 统一显示缺失归类
if #missing > 0 then
table.insert(html, '<div class="missing-data"><b>以下地区暂无数据:</b> ' .. table.concat(missing, ", ") .. "</div>")
end
table.insert(html, "</div>")
return table.concat(html, "\n")
end
return p