Module:zhx-pulleyblank-pron

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 ' ' .. text .. ' ' end

function export.retrieve_cmnearpron(text, reconstruction, no_intro, index) if type(text) == "table" then text = text.args[1] end text = require("Module:links").remove_links(text) local retrieve_result = {} local intro = no_intro and "" or "EM " 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[char_index] or "y" if reading_no ~= "y" then for number in mw.text.gsplit(reading_no, "+") do						insert(char_pronunciation, data_module[tonumber(number)][3]) end else for _, reading in ipairs(data_module) do						insert(char_pronunciation, reading[3]) 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), "$", "ᴰᴸ$ ") -- gsub(concat(retrieve_result), "ˊ", "ᴸᴸ ") -- gsub(concat(retrieve_result), "ˇ", "ᴿ ") -- gsub(concat(retrieve_result), "ˋ", "ᴰ ") gsub(		concat(retrieve_result),		"[ˇˊˋ]",		function (accent)			local data = ({ ["ˊ"] = { symbol = "ᴸᴸ", title = "Light level tone" }, ["ˇ"] = { symbol = "ᴿ", title = "Rising tone" }, ["ˋ"] = { symbol = "ᴰ", title = "Departing tone" }, })[accent]			return '' .. data.symbol .. ' '		end))) end

function export.retrieve_ltclatpron(text, reconstruction, no_intro, index) if type(text) == "table" then text = text.args[1] end text = require("Module:links").remove_links(text) local retrieve_result = {} local intro = no_intro and "" or "LMC " 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[char_index] or "y" if reading_no ~= "y" then for number in mw.text.gsplit(reading_no, "+") do						insert(char_pronunciation, data_module[tonumber(number)][4]) end else for _, reading in ipairs(data_module) do						insert(char_pronunciation, reading[4]) 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), "ˊ", "X") or	-- gsub(concat(retrieve_result), "ˋ", "H") gsub(gsub(concat(retrieve_result), "ˊ", "X"), "ˋ", "H"))) end

function export.retrieve_ltcearpron(text, reconstruction, no_intro, index) if type(text) == "table" then text = text.args[1] end text = require("Module:links").remove_links(text) local retrieve_result = {} local intro = no_intro and "" or "EMC " 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[char_index] or "y" if reading_no ~= "y" then for number in mw.text.gsplit(reading_no, "+") do						insert(char_pronunciation, data_module[tonumber(number)][5]) end else for _, reading in ipairs(data_module) do						insert(char_pronunciation, reading[5]) 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), "'", "X") or	-- gsub(concat(retrieve_result), "ʰ", "H") gsub(gsub(concat(retrieve_result), "'", "X"), "ʰ$", "H"))) end

function export.cmnearlink(frame) args = frame:getParent.args text, meaning, lit = args[1], args[2] or args['gloss'] or nil, args['lit'] or nil return require("Module:zh/link").link(frame, nil, { "*" .. text, tr = export.retrieve_cmnearpron(text, args["tr"] or false, args["id"] 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[1], args[2] or args['gloss'] or nil, args['lit'] or nil return require("Module:zh/link").link(frame, nil, { "*" .. text, tr = export.retrieve_ltclatpron(text, args["tr"] or false, args["id"] 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[1], args[2] or args['gloss'] or nil, args['lit'] or nil return require("Module:zh/link").link(frame, nil, { "*" .. text, tr = export.retrieve_ltcearpron(text, args["tr"] or false, args["id"] or false, false, true),		gloss = meaning, lit = lit }, mw.title.getCurrentTitle.subpageText) end

return export