Module:zhx-pulleyblank-pron

विक्षनरी से

"इस मॉड्यूल हेतु प्रलेख Module:zhx-pulleyblank-pron/doc पर बनाया जा सकता है"

local export = {}

local m_cmn_pron = require("Module:cmn-pron")

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[1] 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 { mw.ustring.codepoint(text, 1, -1) } do
			local char_pronunciation = {}
			local ch = mw.ustring.char(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
						table.insert(char_pronunciation, data_module[tonumber(number)][3])
					end
				else
					for _, reading in ipairs(data_module) do
						table.insert(char_pronunciation, reading[3])
					end
				end
			else
				return nil
			end
			table.insert(retrieve_result, table.concat(char_pronunciation, mw.ustring.len(text) == 1 and ", *" or "/"))
		end
	end
	return intro .. (reconstruction or "*" .. (table.concat(retrieve_result, " ") and
	-- Substitution of tone marks for Early Mandarin
	-- mw.ustring.gsub(table.concat(retrieve_result), "$", "<span style=\"border-bottom: 1px dotted #000; cursor:help\" title=\"Dark level tone\">ᴰᴸ$</span>")
	-- mw.ustring.gsub(table.concat(retrieve_result), "ˊ", "<span style=\"border-bottom: 1px dotted #000; cursor:help\" title=\"Light Level\">ᴸᴸ</span>")
	-- mw.ustring.gsub(table.concat(retrieve_result), "ˇ", "<span style=\"border-bottom: 1px dotted #000; cursor:help\" title=\"Rising tone\">ᴿ</span>")
	-- mw.ustring.gsub(table.concat(retrieve_result), "ˋ", "<span style=\"border-bottom: 1px dotted #000; cursor:help\" title=\"Departing tone\">ᴰ</span>")
	mw.ustring.gsub(
		table.concat(retrieve_result),
		"[ˇˊˋ]",
		function (accent)
			local data = ({
				["ˊ"] = { symbol = "ᴸᴸ", title = "Light level tone" },
				["ˇ"] = { symbol = "ᴿ", title = "Rising tone" },
				["ˋ"] = { symbol = "ᴰ", title = "Departing tone" },
			})[accent]
			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[1] 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 { mw.ustring.codepoint(text, 1, -1) } do
			local char_pronunciation = {}
			local ch = mw.ustring.char(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
						table.insert(char_pronunciation, data_module[tonumber(number)][4])
					end
				else
					for _, reading in ipairs(data_module) do
						table.insert(char_pronunciation, reading[4])
					end
				end
			else
				return nil
			end
			table.insert(retrieve_result, table.concat(char_pronunciation, mw.ustring.len(text) == 1 and ", *" or "/"))
		end
	end
	return intro .. (reconstruction or "*" .. (table.concat(retrieve_result, " ") and
	-- Substitution of tone marks for Late Middle Chinese
	-- mw.ustring.gsub(table.concat(retrieve_result), "ˊ", "<sup>X</sup>") or
	-- mw.ustring.gsub(table.concat(retrieve_result), "ˋ", "<sup>H</sup>")
	mw.ustring.gsub(mw.ustring.gsub(table.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[1] 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 { mw.ustring.codepoint(text, 1, -1) } do
			local char_pronunciation = {}
			local ch = mw.ustring.char(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
						table.insert(char_pronunciation, data_module[tonumber(number)][5])
					end
				else
					for _, reading in ipairs(data_module) do
						table.insert(char_pronunciation, reading[5])
					end
				end
			else
				return nil
			end
			table.insert(retrieve_result, table.concat(char_pronunciation, mw.ustring.len(text) == 1 and ", *" or "/"))
		end
	end
	return intro .. (reconstruction or "*" .. (table.concat(retrieve_result, " ") and
	-- Substitution of tone marks for Early Middle Chinese
	-- mw.ustring.gsub(table.concat(retrieve_result), "'", "<sup>X</sup>") or
	-- mw.ustring.gsub(table.concat(retrieve_result), "ʰ", "<sup>H</sup>")
	mw.ustring.gsub(mw.ustring.gsub(table.concat(retrieve_result), "'", "<sup>X</sup>"), "ʰ$", "<sup>H</sup>")))
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