模块:字表调用:修订间差异
来自潮语辞书
更多操作
小无编辑摘要 |
无编辑摘要 标签:已被回退 |
||
第4行: | 第4行: | ||
-- 地区名到模块路径的映射表 | -- 地区名到模块路径的映射表 | ||
local region_map = { | local region_map = { | ||
-- 省略,保持你原来的完整表格…… | |||
} | |||
-- 返回带标记的错误,方便后续模块分类处理 | |||
local function makeError(msg, region, char) | |||
return string.format('<span class="error" data-region="%s" data-char="%s">%s</span>', region or "", char or "", msg) | |||
end | |||
function p.getReading(frame) | function p.getReading(frame) | ||
第191行: | 第18行: | ||
if not char or char == "" then | if not char or char == "" then | ||
return " | return makeError("缺少字", region, char) | ||
end | end | ||
if not region or region == "" then | if not region or region == "" then | ||
return " | return makeError("缺少地区", region, char) | ||
end | end | ||
local module_path = region_map[region] | local module_path = region_map[region] | ||
if not module_path then | if not module_path then | ||
return " | return makeError("查无此地区数据", region, char) | ||
end | end | ||
local ok, mod = pcall(require, "Module:调查字表/" .. module_path) | 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 makeError("查无此地区数据", region, char) | ||
end | end | ||
local readings = mod.data[char] | local readings = mod.data[char] | ||
if not readings then | if not readings then | ||
return "查无“" .. char .. "”在" .. region .. " | return makeError("查无“" .. char .. "”在" .. region .. "的读音", region, char) | ||
end | end | ||
2025年8月23日 (六) 17:37的版本
此模块的文档可以在模块:字表调用/doc创建
local p = {}
local mw = mw
-- 地区名到模块路径的映射表
local region_map = {
-- 省略,保持你原来的完整表格……
}
-- 返回带标记的错误,方便后续模块分类处理
local function makeError(msg, region, char)
return string.format('<span class="error" data-region="%s" data-char="%s">%s</span>', region or "", char or "", msg)
end
function p.getReading(frame)
local char = frame.args[1]
local region = frame.args[2]
local mode = frame.args[3] or "潮拼"
if not char or char == "" then
return makeError("缺少字", region, char)
end
if not region or region == "" then
return makeError("缺少地区", region, char)
end
local module_path = region_map[region]
if not module_path then
return makeError("查无此地区数据", region, char)
end
local ok, mod = pcall(require, "Module:调查字表/" .. module_path)
if not ok or not mod or not mod.data then
return makeError("查无此地区数据", region, char)
end
local readings = mod.data[char]
if not readings then
return makeError("查无“" .. char .. "”在" .. region .. "的读音", region, char)
end
local result = {}
for _, entry in ipairs(readings) do
local s = entry[mode] or "—"
local zt = entry["字态"] or ""
local note = entry["注释"] or ""
local gray = entry["灰色"]
if gray then
s = '<span style="color:gray">' .. s .. '</span>'
end
if zt ~= "" then
s = s .. ' <span style="color:#fff;">[' .. zt .. ']</span>'
end
if note ~= "" then
s = s .. ' <sub>' .. mw.text.nowiki(note) .. '</sub>'
end
table.insert(result, '<div>' .. s .. '</div>')
end
return table.concat(result, "\n")
end
return p