打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:字表调用

来自潮语辞书
沙茶ちゃん留言 | 贡献2025年7月10日 (四) 06:10的版本

此模块的文档可以在模块:字表调用/doc创建

local p = {}
local mw = mw

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 "错误:缺少字。"
    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[mode] or "—"  -- "潮拼" 或 "IPA"
        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