模块:字表调用:修订间差异
来自潮语辞书
更多操作
小无编辑摘要 |
小无编辑摘要 |
||
第1行: | 第1行: | ||
local p = {} | local p = {} | ||
local mw = mw | local mw = mw | ||
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] | ||
if not char or char == "" then | if not char or char == "" then | ||
return " | return "错误:缺少字。" | ||
end | end | ||
if not region or region == "" then | if not region or region == "" then | ||
return " | return "错误:缺少地区。" | ||
end | end | ||
local module_path = | local module_path = "调查字表/饶平-三饶片-" .. region | ||
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 | ||
第25行: | 第21行: | ||
local readings = mod.data[char] | local readings = mod.data[char] | ||
if not readings then | if not readings then | ||
return " | return "查无“" .. char .. "”在" .. region .. "的读音。" | ||
end | end | ||
local result = {} | local result = {} | ||
for _, entry in ipairs(readings) do | for _, entry in ipairs(readings) do | ||
local | local s = entry["音读"] or "" | ||
local zt = entry["字态"] or "" | local zt = entry["字态"] or "" | ||
local note = entry["注释"] or "" | local note = entry["注释"] or "" | ||
local | local gray = entry["灰色"] | ||
if | if gray then | ||
s = '<span style="color:gray">' .. s .. '</span>' | |||
end | end | ||
if zt ~= "" then | if zt ~= "" then | ||
s = s .. ' <span style="color:#fff;">[' .. zt .. ']</span>' | |||
end | end | ||
if note ~= "" then | if note ~= "" then | ||
s = s .. ' <sub>' .. mw.text.nowiki(note) .. '</sub>' | |||
end | end | ||
table.insert(result, '<div>' .. | table.insert(result, '<div>' .. s .. '</div>') | ||
end | end | ||
2025年7月9日 (三) 17:48的版本
此模块的文档可以在模块:字表调用/doc创建
local p = {}
local mw = mw
function p.getReading(frame)
local char = frame.args[1]
local region = frame.args[2]
if not char or char == "" then
return "错误:缺少字。"
end
if not region or region == "" then
return "错误:缺少地区。"
end
local module_path = "调查字表/饶平-三饶片-" .. 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 "查无“" .. char .. "”在" .. region .. "的读音。"
end
local result = {}
for _, entry in ipairs(readings) do
local s = entry["音读"] 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