Jump to content

Module:zh-glyph/display-phonetic

From Wiktionary, the free dictionary
local export = {}
local m_phonetic = mw.loadData("Module:zh-glyph/phonetic")
local m_och = require("Module:och-pron").retrieve_pron

function export.show(frame)
	local phonekeys = {}
	for k in pairs(m_phonetic) do table.insert(phonekeys, k) end
	table.sort(phonekeys)
	local result = { "The table below lists all the phonetic series of [[Old Chinese]] recognised by [[Wiktionary:About Chinese/references|Zhengzhang (2003)]].\n==List==" }
	if mw.ustring.match(mw.title.getCurrentTitle().text, "2$") then
		i, j = 529, 1056
		other = "← [[Wiktionary:About Chinese/phonetic series|Previous page]]"
	else
		i, j = 1, 528
		other = "→ [[Wiktionary:About Chinese/phonetic series 2|Next page]]"
	end
	table.insert(result, "\n'''''<center>" .. other .. "</center>'''''")
	table.insert(result, "\n{| class=\"Hani\" style=\"font-size:150%; border:1px solid #aaa\" cellpadding=\"10\"")
	k = 1
	for _, base in ipairs(phonekeys) do
		if k >= i and k <= j then
			local och = mw.text.split(m_och(base, nil, true) or "", ",")[1]
			table.insert(result, "\n|-\n!width=17% style=\"background-color:#D1E8F0;\"|[[" .. base .. "]]" .. (och ~= "" and "<span class=\"IPA\" style=\"font-size:60%\"> (" .. och .. ")</span>" or "") .. "\n|style=\"background-color:#FAF9E8;\"|")
			for derivation in mw.text.gsplit(m_phonetic[base], "") do
				table.insert(result, " [[" .. derivation .. "]]")
			end
		end
		k = k + 1
	end
	table.insert(result, "\n|}\n'''''<center>" .. other .. "</center>'''''")
	return table.concat(result)
end

return export