local m_str_utils = require("Module:string utilities")
local codepoint = m_str_utils.codepoint
local concat = table.concat
local gsub = m_str_utils.gsub
local insert = table.insert
local len = m_str_utils.len
local u = m_str_utils.char
local m_cmn_pron = require("Module:cmn-pron")
local export = {}
local function zh_fmt(text)
return '<span class="Hani" lang="zh">' .. text .. '</span>'
end
function export.retrieve_cmnearpron(text, reconstruction, no_intro, index)
if type(text) == "table" then text = text.args end
text = require("Module:links").remove_links(text)
local retrieve_result = {}
local intro = no_intro and "" or "<span style=\"border-bottom: 0.1px dotted #000; cursor:help\" title=\"Early Mandarin\">EM</span> "
if not reconstruction then
if index and index ~= "y" then
index_set = mw.text.split(index, ",")
end
for char_index, cp in ipairs { codepoint(text, 1, -1) } do
local char_pronunciation = {}
local ch = u(cp)
local success, data_module = pcall(mw.loadData, "Module:zh/data/pulleyblank" .. "/" .. ch)
if success then
local reading_no = index_set and index_set or "y"
if reading_no ~= "y" then
for number in mw.text.gsplit(reading_no, "+") do
insert(char_pronunciation, data_module)
end
else
for _, reading in ipairs(data_module) do
insert(char_pronunciation, reading)
end
end
else
return nil
end
insert(retrieve_result, concat(char_pronunciation, len(text) == 1 and ", *" or "/"))
end
end
return intro .. (reconstruction or "*" .. (concat(retrieve_result, " ") and
-- Substitution of tone marks for Early Mandarin
-- gsub(concat(retrieve_result), "$", "<span style=\"border-bottom: 1px dotted #000; cursor:help\" title=\"Dark level tone\">ᴰᴸ$</span>")
-- gsub(concat(retrieve_result), "ˊ", "<span style=\"border-bottom: 1px dotted #000; cursor:help\" title=\"Light Level\">ᴸᴸ</span>")
-- gsub(concat(retrieve_result), "ˇ", "<span style=\"border-bottom: 1px dotted #000; cursor:help\" title=\"Rising tone\">ᴿ</span>")
-- gsub(concat(retrieve_result), "ˋ", "<span style=\"border-bottom: 1px dotted #000; cursor:help\" title=\"Departing tone\">ᴰ</span>")
gsub(
concat(retrieve_result),
"",
function (accent)
local data = ({
= { symbol = "ᴸᴸ", title = "Light level tone" },
= { symbol = "ᴿ", title = "Rising tone" },
= { symbol = "ᴰ", title = "Departing tone" },
})
return '<span style="border-bottom: 1px dotted #000; cursor: help;" title="'
.. data.title .. '">' .. data.symbol .. '</span>'
end)))
end
function export.retrieve_ltclatpron(text, reconstruction, no_intro, index)
if type(text) == "table" then text = text.args end
text = require("Module:links").remove_links(text)
local retrieve_result = {}
local intro = no_intro and "" or "<span style=\"border-bottom: 1px dotted #000; cursor:help\" title=\"Late Middle Chinese\">LMC</span> "
if not reconstruction then
if index and index ~= "y" then
index_set = mw.text.split(index, ",")
end
for char_index, cp in ipairs { codepoint(text, 1, -1) } do
local char_pronunciation = {}
local ch = u(cp)
local success, data_module = pcall(mw.loadData, "Module:zh/data/pulleyblank" .. "/" .. ch)
if success then
local reading_no = index_set and index_set or "y"
if reading_no ~= "y" then
for number in mw.text.gsplit(reading_no, "+") do
insert(char_pronunciation, data_module)
end
else
for _, reading in ipairs(data_module) do
insert(char_pronunciation, reading)
end
end
else
return nil
end
insert(retrieve_result, concat(char_pronunciation, len(text) == 1 and ", *" or "/"))
end
end
return intro .. (reconstruction or "*" .. (concat(retrieve_result, " ") and
-- Substitution of tone marks for Late Middle Chinese
-- gsub(concat(retrieve_result), "ˊ", "<sup>X</sup>") or
-- gsub(concat(retrieve_result), "ˋ", "<sup>H</sup>")
gsub(gsub(concat(retrieve_result), "ˊ", "<sup>X</sup>"), "ˋ", "<sup>H</sup>")))
end
function export.retrieve_ltcearpron(text, reconstruction, no_intro, index)
if type(text) == "table" then text = text.args end
text = require("Module:links").remove_links(text)
local retrieve_result = {}
local intro = no_intro and "" or "<span style=\"border-bottom: 1px dotted #000; cursor:help\" title=\"Early Middle Chinese\">EMC</span> "
if not reconstruction then
if index and index ~= "y" then
index_set = mw.text.split(index, ",")
end
for char_index, cp in ipairs { codepoint(text, 1, -1) } do
local char_pronunciation = {}
local ch = u(cp)
local success, data_module = pcall(mw.loadData, "Module:zh/data/pulleyblank" .. "/" .. ch)
if success then
local reading_no = index_set and index_set or "y"
if reading_no ~= "y" then
for number in mw.text.gsplit(reading_no, "+") do
insert(char_pronunciation, data_module)
end
else
for _, reading in ipairs(data_module) do
insert(char_pronunciation, reading)
end
end
else
return nil
end
insert(retrieve_result, concat(char_pronunciation, len(text) == 1 and ", *" or "/"))
end
end
return intro .. (reconstruction or "*" .. (concat(retrieve_result, " ") and
-- Substitution of tone marks for Early Middle Chinese
-- gsub(concat(retrieve_result), "'", "<sup>X</sup>") or
-- gsub(concat(retrieve_result), "ʰ", "<sup>H</sup>")
gsub(gsub(concat(retrieve_result), "'", "<sup>X</sup>"), "ʰ$", "<sup>H</sup>")))
end
function export.cmnearlink(frame)
args = frame:getParent().args
text, meaning, lit = args, args or args or nil, args or nil
return require("Module:zh/link").link(frame, nil, { "*" .. text, tr = export.retrieve_cmnearpron(text, args or false, args or false, false, true),
gloss = meaning, lit = lit }, mw.title.getCurrentTitle().subpageText)
end
function export.ltclatlink(frame)
args = frame:getParent().args
text, meaning, lit = args, args or args or nil, args or nil
return require("Module:zh/link").link(frame, nil, { "*" .. text, tr = export.retrieve_ltclatpron(text, args or false, args or false, false, true),
gloss = meaning, lit = lit }, mw.title.getCurrentTitle().subpageText)
end
function export.ltcearlink(frame)
args = frame:getParent().args
text, meaning, lit = args, args or args or nil, args or nil
return require("Module:zh/link").link(frame, nil, { "*" .. text, tr = export.retrieve_ltcearpron(text, args or false, args or false, false, true),
gloss = meaning, lit = lit }, mw.title.getCurrentTitle().subpageText)
end
return export