モジュール:hanzidic
表示
このモジュールについての説明文ページを モジュール:hanzidic/doc に作成できます
local p = {}
local function is_set(v)
return v and mw.text.trim(v) ~= ""
end
local function listify(raw, parser)
local out = {}
for part in mw.text.gsplit(raw, "/", true) do
table.insert(out, parser(part))
end
return table.concat(out, "<br />")
end
local function parse_kangxi(v)
local n = tonumber(v)
if not n then return "(掲載なし)" end
local x = math.floor(n * 1000 + 0.5)
if x % 10 ~= 0 then return "(掲載なし)" end
local page = math.floor(x / 1000)
local char = math.floor(x / 10) % 100
return page .. "ページ, " .. char .. "文字目"
end
local function parse_cihai(v)
local n = tonumber(v)
if not n then return "(掲載なし)" end
local x = math.floor(n * 10000 + 0.5)
local page = math.floor(x / 10000)
local line = math.floor(x / 1000) % 10
local char = math.floor(x / 10) % 100
return page .. "ページ, " .. line .. "行, " .. char .. "文字目"
end
local function parse_cb(v)
local n = tonumber(v)
if not n then return "(掲載なし)" end
local x = math.floor(n * 10000 + 0.5)
local page = math.floor(x / 10000)
local char = math.floor(x / 100) % 100
return page .. "ページ, " .. char .. "文字目"
end
local function parse_hdz(v)
local vol, page, char2, flag = v:match("^(%d)(%d%d%d%d)%.(%d%d)(%d)$")
if not vol then
return "(掲載なし)"
end
if flag ~= "0" then
return "(掲載なし)"
end
vol = tonumber(vol)
page = tonumber(page)
char2 = tonumber(char2)
return vol .. "巻"
.. (vol >= 8 and "(補巻)" or "")
.. "、" .. page .. "ページ、" .. char2 .. "文字目"
end
local function parse_zhuang(v)
if type(v) ~= "string" then
return "(掲載なし)"
end
local page, yyzz = v:match("^(%d+)%.?(%d%d%d%d)$")
if not page or not yyzz then
return "(掲載なし)"
end
page = tonumber(page)
local char = tonumber(yyzz:sub(1, 2))
local inner = tonumber(yyzz:sub(3, 4))
if not page or not char or not inner then
return "(掲載なし)"
end
local ret = page .. "ページ, " .. char .. "文字目"
if inner ~= 0 then
ret = ret .. ", 括弧内" .. inner .. "文字目"
end
return ret
end
function p.render(frame)
local a = frame.args
local out = {}
table.insert(out, '{| class="wikitable"')
table.insert(out, '|+ 字典掲載')
local function row(title, content)
table.insert(out, "|-\n! " .. title .. "\n| " .. content)
end
if is_set(a["康煕"] or a["康熙"]) then
row("[[w:康熙字典|康熙字典]]",
listify(a["康煕"] or a["康熙"], parse_kangxi))
end
if is_set(a["gy"]) then
row("[[w:広韻|宋本広韻]] (1008)",
listify(a["gy"], parse_kangxi))
end
if is_set(a["vt"]) then
row("[[:w:zh:異體字字典|教育部異体字字典]] (2024)",
listify(a["vt"], function(v)
return "[https://dict.variants.moe.edu.tw/dictView.jsp?educode="
.. v .. " " .. v .. "]"
end))
end
if is_set(a["諸橋"]) then
row("諸橋[[w:大漢和辞典|大漢和辞典]] (修訂第2版)",
listify(a["諸橋"], function(v) return v end))
end
if is_set(a["新潮漢字"]) then
row("新潮日本語漢字辞典 (2008)",
listify(a["新潮漢字"], function(v) return v end))
end
if is_set(a["大字源"]) then
row("角川大字源 (1992)",
listify(a["大字源"], function(v) return v end))
end
if is_set(a["新字源"]) then
row("[[w:新字源|角川新字源]] (2017)",
listify(a["新字源"], function(v) return v end))
end
if is_set(a["新大字典"]) then
row("講談社新大字典 (1993)",
listify(a["新大字典"], function(v) return v end))
end
if is_set(a["大漢語林"]) then
row("[[w:漢語林|大漢語林]] (1992)",
listify(a["大漢語林"], function(v) return v end))
end
if is_set(a["dj"]) then
row("三星漢韓大辞典 (1988)",
listify(a["dj"], parse_kangxi))
end
if is_set(a["ch"]) then
row("[[w:辞海|辞海]] (1983)",
listify(a["ch"], parse_cihai))
end
if is_set(a["hdz"]) then
row("[[w:漢語大字典|漢語大字典]] (1986–1989)",
listify(a["hdz"], parse_hdz))
end
if is_set(a["漢字海"]) then
row("漢字海 (2018)",
listify(a["漢字海"], function(v) return v end))
end
if is_set(a["gz"]) then
row("古壮字字典 (1989)",
listify(a["gz"], parse_zhuang))
end
if is_set(a["cowles"]) then
row("廣州話袖珍字典 (1986)",
listify(a["cowles"], function(v) return v end))
end
if is_set(a["cb"]) then
row("The Representation of Cantonese with Chinese Characters (2002)",
listify(a["cb"], parse_cb))
end
if is_set(a["nelson"]) then
row("最新漢英辞典 (1974)",
listify(a["nelson"], function(v) return v end))
end
if is_set(a["matthews"]) then
row("Matthews' Chinese-English Dictionary (1975)",
listify(a["matthews"], function(v) return v end))
end
if is_set(a["mw"]) then
row("The Student's Cantonese-English Dictionary (1947)",
listify(a["mw"], function(v) return v end))
end
if is_set(a["他"]) then
table.insert(out, "|-\n| colspan=2 | " .. a["他"])
end
table.insert(out, "|}")
return table.concat(out, "\n")
end
return p