模块:读音显示
来自潮语辞书
更多操作
此模块的文档可以在模块:读音显示/doc创建
local p = {}
local mw = mw
local function replace_named_placeholders(tpl, replacements)
return (tpl:gsub("%%(%w+)%%", replacements))
end
function p.render(frame)
local char = frame.args[1] or "三"
local display_mode = frame.args[2] or "IPA" -- 可选值:"IPA" 或 "潮拼"
local function get_reading(region)
return frame:callParserFunction{
name = "#invoke",
args = { "字表调用", "getReading", char, region, display_mode }
}
end
local regions = {
{ name = "三饶", reading = get_reading("三饶") },
{ name = "凤凰", reading = get_reading("凤凰") },
{ name = "新丰", reading = "查无" },
{ name = "新塘", reading = "查无" },
{ name = "汤溪", reading = get_reading("汤溪") },
{ name = "浮山", reading = "查无" },
{ name = "浮滨", reading = "查无" },
{ name = "东山", reading = "查无" },
}
local list_items = {}
for _, region in ipairs(regions) do
table.insert(list_items,
string.format('<li><span class="place">%s</span><span class="pronunciation">%s</span></li>',
region.name, region.reading)
)
end
local html_template = [[
<div class="entry-section regional-pronunciation-section">
<h2>各地方音</h2>
<div class="region-group" style="position:relative;">
<button class="toggle-pronunciation-btn" type="button"
data-char="%char%" data-mode="%mode%">切换为 %toggle_text%</button>
<div class="shanggu-serif"><big>饶平三饶片</big></div>
<ul class="dialect-list">
%region_list%
</ul>
</div>
</div>
]]
local replacements = {
char = char,
mode = display_mode == "IPA" and "chao" or "ipa",
toggle_text = display_mode == "IPA" and "潮拼" or "IPA",
region_list = table.concat(list_items, "\n")
}
return mw.text.unstrip(replace_named_placeholders(html_template, replacements))
end
return p