模块:字表调用:修订间差异
来自潮语辞书
更多操作
小 沙茶ちゃん移动页面模块:字表调用IPA至模块:字表调用 |
小无编辑摘要 |
||
第1行: | 第1行: | ||
local p = {} | local p = {} | ||
local mw = mw | |||
-- 可选:未来支持更多地区片名,这里集中管理命名规则 | |||
local prefix = "调查字表/饶平-三饶片-" | |||
function p.getReading(frame) | function p.getReading(frame) | ||
local char = frame.args[1] | local char = frame.args[1] | ||
local region = frame.args[2] | local region = frame.args[2] | ||
local mode = frame.args[3] or "IPA" -- 可选参数,默认取 IPA,也可设为“潮拼” | |||
if not char or char == "" then | if not char or char == "" then | ||
第12行: | 第17行: | ||
end | end | ||
local ok, mod = pcall(require, "Module: | local module_path = prefix .. region | ||
local ok, mod = pcall(require, "Module:" .. module_path) | |||
if not ok or not mod or not mod.data then | if not ok or not mod or not mod.data then | ||
return "查无此地区数据。" | return "查无此地区数据。" | ||
第24行: | 第30行: | ||
local result = {} | local result = {} | ||
for _, entry in ipairs(readings) do | for _, entry in ipairs(readings) do | ||
local | local sound = entry[mode] or "" | ||
local zt = entry["字态"] or "" | local zt = entry["字态"] or "" | ||
local note = entry["注释"] or "" | local note = entry["注释"] or "" | ||
第30行: | 第36行: | ||
if is_gray then | if is_gray then | ||
sound = '<span style="color:gray">' .. sound .. '</span>' | |||
end | end | ||
if zt ~= "" then | if zt ~= "" then | ||
sound = sound .. '<span style="color:#fff;">[' .. zt .. ']</span>' | |||
end | end | ||
if note ~= "" then | if note ~= "" then | ||
sound = sound .. ' <sub>' .. mw.text.nowiki(note) .. '</sub>' | |||
end | end | ||
table.insert(result, '<div>' .. | table.insert(result, '<div>' .. sound .. '</div>') | ||
end | end | ||
2025年7月9日 (三) 17:38的版本
此模块的文档可以在模块:字表调用/doc创建
local p = {}
local mw = mw
-- 可选:未来支持更多地区片名,这里集中管理命名规则
local prefix = "调查字表/饶平-三饶片-"
function p.getReading(frame)
local char = frame.args[1]
local region = frame.args[2]
local mode = frame.args[3] or "IPA" -- 可选参数,默认取 IPA,也可设为“潮拼”
if not char or char == "" then
return "错误:需要指定查询的字。"
end
if not region or region == "" then
return "错误:需要指定地区。"
end
local module_path = prefix .. region
local ok, mod = pcall(require, "Module:" .. module_path)
if not ok or not mod or not mod.data then
return "查无此地区数据。"
end
local readings = mod.data[char]
if not readings then
return "查无此字在" .. region .. "的读音。"
end
local result = {}
for _, entry in ipairs(readings) do
local sound = entry[mode] or ""
local zt = entry["字态"] or ""
local note = entry["注释"] or ""
local is_gray = entry["灰色"]
if is_gray then
sound = '<span style="color:gray">' .. sound .. '</span>'
end
if zt ~= "" then
sound = sound .. '<span style="color:#fff;">[' .. zt .. ']</span>'
end
if note ~= "" then
sound = sound .. ' <sub>' .. mw.text.nowiki(note) .. '</sub>'
end
table.insert(result, '<div>' .. sound .. '</div>')
end
return table.concat(result, "\n")
end
return p