Module:zh-pron

Mula Wiktionary

Ang dokumentasyon ng ng modyul na ito ay maaaring likhain sa Module:zh-pron/doc

local gsub = mw.ustring.gsub

local export = {}

local langname = {
	["cdo"] = "Min Dong",
	["cmn"] = "Mandarin",
	["cjy"] = "Jin",
	["gan"] = "Gan",
	["hak"] = "Hakka",
	["hsn"] = "Xiang",
	["nan"] = "Min Nan",
	["wuu"] = "Wu",
	["yue"] = "Kantones",
}

local langname_abbr = {
	["m"] = "Mandarin",
	["m-s"] = "Sichuanes",
	["c"] = "Kantones",
	["c-t"] = "Taishanes",
	["g"] = "Gan",
	["h"] = "Hakka",
	["j"] = "Jin",
	["md"] = "Min Dong",
	["mn"] = "Min Nan",
	["mn-t"] = "Min Nan",
	["w"] = "Wu",
	["x"] = "Xiang",
}

local pos_aliases_cat = {
	["n"] = "nouns", ["noun"] = "nouns", 
	["pn"] = "proper nouns", ["propn"] = "proper nouns", ["proper"] = "proper nouns", ["proper noun"] = "proper nouns", 
	["pron"] = "pronouns", ["pronoun"] = "pronouns", 
	["v"] = "verbs", ["verb"] = "verbs", 
	["a"] = "adjectives", ["adj"] = "adjectives", ["adjective"] = "adjectives", 
	["adv"] = "adverbs", ["adverb"] = "adverbs", 
	["prep"] = "prepositions", ["pre"] = "prepositions", 
	["postp"] = "postpositions", ["post"] = "postpositions", 
	["con"] = "conjunctions", ["conj"] = "conjunctions", ["conjunction"] = "conjunctions", 
	["part"] = "particles", ["particle"] = "particles", 
	["pref"] = "prefixes", ["prefix"] = "prefixes", 
	["suf"] = "suffixes", ["suffix"] = "suffixes", 
	["interfix"] = "interfixes", 
	["prov"] = "proverbs", ["proverb"] = "proverbs", 
	["id"] = "idioms", ["idiom"] = "idioms", 
	["ch"] = "chengyu", ["cy"] = "chengyu", ["chengyu"] = "chengyu", 
	["ph"] = "phrases", ["phrase"] = "phrases", 
	["intj"] = "interjections", ["interj"] = "interjections", ["interjection"] = "interjections", 
	["cl"] = "classifiers", ["cls"] = "classifiers", ["classifier"] = "classifiers", 
	["num"] = "numerals", ["numeral"] = "numerals", 
	["abb"] = "abbreviations", ["abbreviation"] = "abbreviations", 
	["det"] = "determiners", ["deter"] = "determiners", ["determiner"] = "determiners", 
}

function makeNote(text)
	if mw.ustring.match(text, ": ") then
		text = "\n*" .. gsub(gsub(text, "\n", ".\n*"), "([:;]) ", "%1\n**")
	elseif mw.ustring.match(text, "; ") then
		text = "\n*" .. gsub(text, '; ', ";\n*")
	end
	text = gsub(text, '“([^”]+)”', function (a) return '“' .. gsub(a, ";\n%*+", "; ") .. '”' end)
	return "\n<div style=\"border: 1px solid green; padding: 4px; margin: 8px; background: #F7F4ED; font-size: 85%\">'''Tanda''': " .. text .. ".</div>"
end

function export.make(frame)
	local args = frame:getParent().args
	local pagename = mw.title.getCurrentTitle().text
	local m_rom = args["m"] or ""
	local m_s_rom = args["m-s"] or ""
	local c_rom = args["c"] or ""
	local c_t_rom = args["c-t"] or ""
	local g_rom = args["g"] or ""
	local h_rom = args["h"] or ""
	local j_rom = args["j"] or ""
	local md_rom = args["md"] or ""
	local mn_rom = args["mn"] or ""
	local mn_t_rom = args["mn-t"] or ""
	local w_rom = args["w"] or ""
	local x_rom = args["x"] or ""
	local m_audio = args["ma"] or ""
	local m_audio2 = args["ma2"] or ""
	local m_s_audio = args["m-sa"] or ""
	local c_audio = args["ca"] or ""
	local c_t_audio = args["c-ta"] or ""
	local g_audio = args["ga"] or ""
	local h_audio = args["ha"] or ""
	local j_audio = args["ja"] or ""
	local md_audio = args["mda"] or ""
	local mn_audio = args["mna"] or ""
	local mn_t_audio = args["mn-ta"] or ""
	local w_audio = args["wa"] or ""
	local x_audio = args["xa"] or ""
	local dial = args["dial"] or ""
	local mc = (args["mc"] and args["mc"] ~= "") and args["mc"] or false
	local oc = (args["oc"] and args["oc"] ~= "") and args["oc"] or false
	local only_cat = args["only_cat"] or ""

	text = {}
	if only_cat ~= "yes" then
		textShow = {'<div class="toccolours mw-collapsible mw-collapsed" style="width:500px; font-size:100%">'}
		textHide = {}
		if m_rom .. m_s_rom ~= "" then
			table.insert(textShow, '\n* [[w:Mandarin Chinese|Mandarin]]')
		end
		if m_rom .. m_audio ~= "" then
			local m_pron = require("Module:cmn-pron")
			if m_rom ~= "" then
				table.insert(textShow, '\n' .. m_pron.str_analysis(m_rom,'head',m_s_rom..m_s_audio))
			end
			m_args = {}
			m_args[1] = m_pron.str_analysis(m_rom,'')
			m_args_names = {
				'1n','1na','1nb','1nc','1nd','py','cap','tl','tl2','tl3','a','audio','er','ertl','ertl2','ertl3','era','eraudio',
				'2n','2na','2nb','2nc','2nd','2py','2cap','2tl','2tl2','2tl3','2a','2audio','2er','2ertl','2ertl2','2ertl3','2era','2eraudio',
				'3n','3na','3nb','3nc','3nd','3py','3cap','3tl','3tl2','3tl3','3a','3audio','3er','3ertl','3ertl2','3ertl3','3era','3eraudio',
				'4n','4na','4nb','4nc','4nd','4py','4cap','4tl','4tl2','4tl3','4a','4audio','4er','4ertl','4ertl2','4ertl3','4era','4eraudio',
			}
			for _,name in ipairs(m_args_names) do
				m_args[name] = m_pron.str_analysis(m_rom,name)
			end
			m_args[2] = m_pron.str_analysis(m_rom,'2')
			m_args[3] = m_pron.str_analysis(m_rom,'3')
			m_args[4] = m_pron.str_analysis(m_rom,'4')
			m_args['a'] = m_audio
			m_args['a2'] = m_audio2
			local debug = ""
			for code,name in pairs(m_args) do
				debug = debug .. code .. ":" .. name .. ","
			end
			table.insert(textHide, m_pron.make_args(m_args))
			if args["m_note"] then table.insert(textHide, makeNote(args["m_note"])) end
		end
		if m_s_rom .. m_s_audio ~= "" then
			local m_s_pron = require("Module:cmn-pron-Sichuan")
			local m_s_processed = gsub(gsub(gsub(m_s_rom, '/', ' / '), '([%d-])([%a])', '%1 %2'), '([%d-]+)', '<sup>%1</sup>')
			if m_s_rom ~= "" then
				table.insert(textShow, '\n*: <small>(<i>[[w:Sichuanese dialect|Chengdu]], [[w:Sichuanese Pinyin|SP]]</i>)</small>: <font face="Consolas">')
				table.insert(textShow, m_s_processed)
				table.insert(textShow, '</font>')
			end
			if m_rom .. m_audio == "" then
				table.insert(textHide, '\n* [[w:Mandarin Chinese|Mandarin]]')
			else
				table.insert(textHide, '\n* ')
			end
			table.insert(textHide, '\n** <small>(<i>[[w:Chengdu|Chengdu]]</i>)</small>')
			table.insert(textHide, '\n*** <small><i>[[w:Sichuanese Pinyin|Sichuanes na Pinyin]]</i></small>: <font face="Consolas">')
			table.insert(textHide, m_s_processed)
			table.insert(textHide, '</font>')
			local xinwenz = m_s_pron.convert(m_s_rom, 'SWZ')
			if xinwenz then
				table.insert(textHide, '\n*** <small><i>[[w:zh:四川话拉丁化新文字|Scuanxua Ladinxua Xin Wenz]]</i></small>: <font face="Consolas">')
				table.insert(textHide, m_s_pron.convert(m_s_rom, 'SWZ'))
				table.insert(textHide, '</font>')
			end
			table.insert(textHide, '\n*** <small>[[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:zh:成都话|key]])</sup></small>: <span class="IPA">')
			table.insert(textHide, m_s_pron.convert(m_s_rom, 'IPA'))
			table.insert(textHide, '</span>')
			add_audio(textHide, m_s_audio, 'cmn-sichuan')
			if args["m-s_note"] then table.insert(textHide, makeNote(args["m-s_note"])) end
		end
		if c_rom .. c_audio .. c_t_rom .. c_t_audio ~= "" then
			local c_pron = require("Module:yue-pron")
			if c_rom .. c_t_rom ~= "" then
				table.insert(textShow, '\n* [[w:Cantonese|Kantones]]')
				table.insert(textHide, '\n* [[w:Cantonese|Kantones]]')
				if c_rom ~= "" then
					c_rom = c_rom:gsub("%*","-")
					local c_processed = c_rom:gsub(',([^ ])',', %1')
					if mw.ustring.len(mw.title.getCurrentTitle().text) == 1 then
						c_processed = c_processed:gsub('([^, ]+)','[[%1]]')
						c_processed = c_processed:gsub('%[%[%[%[','[[')
						c_processed = c_processed:gsub('%]%]%]%]',']]')
						c_processed = gsub(c_processed, '%[%[([^%]]+)%]%]', function(a)
							return '[[' .. a .. '|' .. gsub(a, '([1-9-]+)', '<sup>%1</sup>') .. ']]' end)
					else
						c_processed = gsub(c_processed, '([1-9-]+)', '<sup>%1</sup>')
					end
					if c_t_rom == "" then
						table.insert(textShow, ' <small>(<i>')
					else
						table.insert(textShow, '\n*: <small>(<i>[[w:Guangzhou Cantonese|Guangzhou]], ')
					end
					table.insert(textShow, '[[w:Jyutping|Jyutping]]</i>)</small>: <font face="Consolas">' .. c_processed .. '</font>')
					c_rom = c_rom:gsub('[%[%]]','')
					local c_hom = mw.loadData("Module:yue-pron/hom")
					local c_hom_exists = false
					for _,c_first in ipairs(c_pron.jyutping_format(c_rom)) do
						if c_hom[c_first] then
							c_hom_exists = c_first
						end
					end
					table.insert(textHide, '\n** <small>(<i>[[w:Standard Cantonese|Batayang Kantones]], [[w:Guangzhou Cantonese|Guangzhou]]</i>)</small>')
					if not c_hom_exists then
						table.insert(textHide, '<sup><small><abbr title="Magdagdag ng homoponyang Kantones (pindutin lamang ito kung alam mo ang dapat gawain!)"><span class="plainlinks">[')
						table.insert(textHide, tostring(mw.uri.fullUrl("Module:yue-pron/hom",{["action"]="edit"})))
						table.insert(textHide, ' +]</span></abbr></small></sup>')
					end
					c_comma = gsub(c_rom,',([^ ])',', %1')
					table.insert(textHide, '\n*** <small><i>[[w:Jyutping|Jyutping]]</i></small>: <font face="Consolas">')
					table.insert(textHide, tostring(gsub(c_comma, '([1-9-]+)', '<sup>%1</sup>')))
					table.insert(textHide, '</font>')
					table.insert(textHide, '\n*** <small><i>[[w:Yale romanization of Cantonese|Yale]]</i></small>: <font face="Consolas">')
					table.insert(textHide, c_pron.jyutping_to_yale(c_rom))
					table.insert(textHide, '</font>')
					table.insert(textHide, '\n*** <small><i>[[w:Cantonese Pinyin|Pinyin na Kantones]]</i></small>: <font face="Consolas">')
					table.insert(textHide, tostring(gsub(c_pron.jyutping_to_cantonese_pinyin(c_rom), '([1-9-]+)', '<sup>%1</sup>')))
					table.insert(textHide, '</font>')
					table.insert(textHide, '\n*** <small><i>[[w:Guangdong Romanization|Romanisasyong Guangdong]]</i></small>: <font face="Consolas">')
					table.insert(textHide, tostring(gsub(c_pron.jyutping_to_guangdong(c_rom), '([1-9-]+)', '<sup>%1</sup>')))
					table.insert(textHide, '</font>')
					table.insert(textHide, '\n*** <small>[[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:Cantonese phonology|key]])</sup></small>: <span class="IPA">/')
					table.insert(textHide, c_pron.jyutping_to_ipa(c_rom))
					table.insert(textHide, '/</span>')
					for _,c_first in ipairs(c_pron.jyutping_format(c_rom)) do
						if c_hom_exists == c_first then
							local hom_textHide = {'\n*** <small>Homoponya</small>: <table class="wikitable mw-collapsible mw-collapsed" style="width:15em;margin:0;'}
							local hom_text = {}
							table.insert(hom_textHide, 'position:left; text-align:center"><tr><th></th></tr><tr><td><sup><div style="float: right; clear: right;">')
							table.insert(hom_textHide, '<span class="plainlinks">[')
							table.insert(hom_textHide, tostring(mw.uri.fullUrl("Module:yue-pron/hom",{["action"]="edit"})))
							table.insert(hom_textHide, ' edit]</span></div></sup><div style="visibility:hidden; float:left"><sup><span style="color:#FFF">edit</span></sup></div>')
							for _,hom in ipairs(c_hom[c_first]) do
								table.insert(hom_text, mw.getCurrentFrame():expandTemplate{ title = "Template:zh-l", args = { hom, tr = "-" } })
							end
							table.insert(hom_textHide, table.concat(hom_text, "<br>"))
							table.insert(hom_textHide, '</td></tr></table>')
							table.insert(textHide, table.concat(hom_textHide))
							table.insert(textHide, '[[Kategorya:Mga terminong kantones na may homoponya]]')
						end
					end
					add_audio(textHide, c_audio, 'yue')
					if args["c_note"] then table.insert(textHide, makeNote(args["c_note"])) end
				end
				if c_t_rom ~= "" then
					local c_t_processed = c_t_rom:gsub(',([^ ])',', %1')
					c_t_processed = gsub(c_t_processed, '([1-9%*]%-?[1-9%*]?)', '<sup>%1</sup>')
					table.insert(textShow, ((c_rom ~= "") and '\n*:' or '') .. ' <small>(<i>[[w:Taishanese|Taishan]], [[Wiktionary:About Chinese/Cantonese/Taishanese|Wiktionary]]</i>)</small>: <font face="Consolas">')
					table.insert(textShow, c_t_processed .. '</font>')
					c_t_rom = c_t_rom:gsub('[%[%]]','')
					c_t_comma = gsub(c_t_rom,',([^ ])',', %1')
					table.insert(textHide, '\n** <small>(<i>[[w:Taishanese|Taishanes]], [[w:Taicheng Subdistrict|Taicheng]]</i>)</small>')
					table.insert(textHide, '\n*** <small><i>[[Wiktionary:About Chinese/Cantonese/Taishanese|Wiktionary]]</i></small>: <font face="Consolas">')
					table.insert(textHide, tostring(gsub(c_t_comma, '([1-9%*]%-?[1-9%*]?)', '<sup>%1</sup>')))
					table.insert(textHide, '</font>')
					table.insert(textHide, '\n*** <small>[[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:Taishanese|key]])</sup></small>: <span class="IPA">')
					table.insert(textHide, c_pron.hoisanva_to_ipa(c_t_rom))
					table.insert(textHide, '</span>')
					add_audio(textHide, c_t_audio, 'yue-taishan')
					if args["c-t_note"] then table.insert(textHide, makeNote(args["c-t_note"])) end
				end
			end
		end
		if g_rom .. g_audio ~= "" then
			local g_pron = require("Module:gan-pron")
			if g_rom ~= "" then
				table.insert(textShow, '\n* [[w:Gan Chinese|Gan]] <small>(<i>[[Wiktionary:About Chinese/Gan|Wiktionary]]</i>)</small>: <font face="Consolas">')
				table.insert(textShow, g_pron.rom(g_rom))
				table.insert(textShow, '</font>')
			end
			table.insert(textHide, '\n* [[w:Gan Chinese|Gan]]')
			table.insert(textHide, '\n** <small>(<i>[[w:Nanchang dialect|Nanchang]]</i>)</small>')
			table.insert(textHide, '\n*** <small><i>[[Wiktionary:About Chinese/Gan|Wiktionary]]</i></small>: <font face="Consolas">')
			table.insert(textHide, g_pron.rom(g_rom))
			table.insert(textHide, '</font>')
			table.insert(textHide, '\n*** <small>[[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:Nanchang dialect|key]])</sup></small>: <span class="IPA">/')
			table.insert(textHide, g_pron.ipa(g_rom))
			table.insert(textHide, '/</span>')
			add_audio(textHide, g_audio, 'gan')
			if args["g_note"] then table.insert(textHide, makeNote(args["g_note"])) end
		end
		if (mw.ustring.match(h_rom, 'pfs=.') or mw.ustring.match(h_rom, 'gd=.') or "") .. h_audio ~= "" then
			local h_pron = require("Module:hak-pron")
			if (mw.ustring.match(h_rom, "pfs=.") or "") .. (mw.ustring.match(h_rom, 'gd=.') or "") ~= "" then
				table.insert(textShow, '\n* [[w:Hakka Chinese|Hakka]]')
				table.insert(textShow, h_pron.rom_display(h_rom,'yes'))
			end
			table.insert(textHide, '\n* [[Wiktionary:About Chinese/Hakka|Hakka]]')
			if h_rom ~= '' then table.insert(textHide, h_pron.rom_display(h_rom,'')) end
			if h_audio ~= '' then add_audio(textHide,h_audio,'hak') end
			if args["h_note"] then table.insert(textHide, makeNote(args["h_note"])) end
		end
		if j_rom .. j_audio ~= "" then
			local j_pron = require("Module:cjy-pron")
			if j_rom ~= "" then
				table.insert(textShow, '\n* [[w:Jin Chinese|Jin]] <small>(<i>[[Wiktionary:About Chinese/Jin|Wiktionary]]</i>)</small>: <font face="Consolas">')
				table.insert(textShow, j_pron.rom(j_rom))
				table.insert(textShow, '</font>')
			end
			table.insert(textHide, '\n* [[w:Jin Chinese|Jin]]')
			table.insert(textHide, '\n** <small>(<i>[[w:Taiyuan|Taiyuan]]</i>)<sup>[[:w:zh:太原話|+]]</sup></small>')
			if j_rom ~= '' then
				table.insert(textHide, '\n*** <small><i>[[Wiktionary:About Chinese/Jin|Wiktionary]]</i></small>: <font face="Consolas">')
				table.insert(textHide, j_pron.rom(j_rom))
				table.insert(textHide, '</font>')
			end
			local no_sandhi = false
			local roms = mw.text.split(j_rom, '/')
			for i = 1, table.getn(roms) do
				if mw.ustring.find(roms[i], ' [^ ]+ ') then
					no_sandhi = true
					break
				end
			end
			table.insert(textHide, '\n*** <small>[[Wiktionary:International Phonetic Alphabet|IPA]] (<i>old-style' .. (no_sandhi and ', no sandhi' or '') .. '</i>)</small>: <span class="IPA">/')
			table.insert(textHide, j_pron.ipa(j_rom, no_sandhi and "no_sandhi" or ""))
			table.insert(textHide, '/</span>')
			add_audio(textHide, j_audio, 'cjy')
			if args["j_note"] then table.insert(textHide, makeNote(args["j_note"])) end
		end
		if md_rom .. md_audio ~= "" then
			local md_pron = require("Module:cdo-pron")
			if md_rom ~= "" then
				table.insert(textShow, '\n* [[w:Min Dong|Min Dong]] <small>(<i>[[Wiktionary:About Chinese/Min Dong|BUC]]</i>)</small>: <font face="Consolas">')
				table.insert(textShow, md_pron.rom(md_rom))
				table.insert(textShow, '</font>')
			end
			table.insert(textHide, '\n* [[w:Min Dong|Min Dong]]')
			table.insert(textHide, '\n** <small>(<i>[[w:Fuzhou dialect|Fuzhou]]</i>)</small>')
			if md_rom ~= '' then
				table.insert(textHide, '\n*** <small><i>[[Wiktionary:About Chinese/Min Dong|Bàng-uâ-cê]]</i></small>: <font face="Consolas">')
				table.insert(textHide, md_pron.rom(md_rom))
				table.insert(textHide, '</font>')
				if not mw.ustring.match(md_rom, '([^/]*)-([^/]*)-([^/]*)-([^/]*)-([^/]*)') then
					table.insert(textHide, '\n*** <small>[[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:Fuzhou dialect|key]])</sup></small>: <span class="IPA">/')
					table.insert(textHide, md_pron.ipa(md_rom))
					table.insert(textHide, '/</span>')
				else
					table.insert(textHide, '\n*** <small>[[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:Fuzhou dialect|key]])</sup> (<i>no sandhi</i>)</small>: <span class="IPA">/')
					table.insert(textHide, md_pron.ipa(md_rom, "no_sandhi"))
					table.insert(textHide, '/</span>')
				end
			end
			add_audio(textHide, md_audio, 'cdo')
			if args["md_note"] then table.insert(textHide, makeNote(args["md_note"])) end
		end
		if mn_rom .. mn_audio .. mn_t_rom .. mn_t_audio ~= "" then
			local mn_pron = require("Module:nan-pron")
			if mn_rom .. mn_t_rom ~= "" then
				table.insert(textShow, '\n* [[w:Min Nan|Min Nan]]')
				if mn_rom ~= "" then
					table.insert(textShow, ((mn_t_rom == "") and " <small>(<i>" or "\n*: <small>(<i>[[w:Hokkien|Hokkien]], ") .. '[[w:Pe̍h-ōe-jī|POJ]]</i>)</small>: <font face="Consolas">')
					table.insert(textShow, mn_pron.poj_display(mn_pron.poj_check_invalid(mn_rom)))
					table.insert(textShow, '</font>')
				end
				if mn_t_rom ~= "" then
					table.insert(textShow, ((mn_rom ~= "") and '\n*:' or '') .. ' <small>(<i>[[w:Teochew dialect|Teochew]], [[w:Peng\'im|Peng\'im]]</i>)</small>: <font face="Consolas">')
					table.insert(textShow, mn_pron.pengim_display(mn_t_rom))
					table.insert(textShow, '</font>')
				end
			end
			table.insert(textHide, '\n* [[w:Min Nan|Min Nan]]')
			if mn_rom .. mn_audio ~= "" then
				table.insert(textHide, mn_pron.generate_all(mn_rom))
				add_audio(textHide, mn_audio, 'nan')
				if args["mn_note"] then table.insert(textHide, makeNote(args["mn_note"])) end
			end
			if mn_t_rom .. mn_t_audio ~= "" then
				table.insert(textHide, '\n** <small>(<i>[[w:Teochew dialect|Teochew]]</i>)</small>')
				table.insert(textHide, '\n*** <small><i>[[w:Peng\'im|Peng\'im]]</i></small>: <font face="Consolas">')
				table.insert(textHide, mn_pron.pengim_display(mn_t_rom))
				table.insert(textHide, '</font>')
				table.insert(textHide, '\n*** <small><i>[[w:Pe̍h-ōe-jī|Pe̍h-ōe-jī]]-like</i></small>: <font face="Consolas">')
				table.insert(textHide,  mn_pron.pengim_to_pojlike_conv(mn_t_rom))
				table.insert(textHide, '</font>')
				table.insert(textHide, '\n*** <small>[[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:zh:潮州話#語音|key]])</sup></small>: <span class="IPA">')
				table.insert(textHide,  mn_pron.pengim_to_ipa_conv(mn_t_rom))
				table.insert(textHide, '</span>')
				add_audio(textHide, mn_t_audio, 'nan-teochew')
				if args["mn-t_note"] then table.insert(textHide, makeNote(args["mn-t_note"])) end
			end
		end
		if w_rom .. w_audio ~= "" then
			local w_pron = require("Module:wuu-pron")
			if w_rom ~= "" then
				table.insert(textShow, '\n* [[w:Wu Chinese|Wu]] <small>(<i>[[Wiktionary:About Chinese/Wu|Wiktionary]]</i>)</small>: <font face="Consolas">')
				table.insert(textShow, w_pron.rom(w_rom))
				table.insert(textShow, '</font>')
			end
			table.insert(textHide, '\n* [[w:Wu Chinese|Wu]]')
			table.insert(textHide, '\n** <small>(<i>[[w:Shanghainese|Shanghaines]]</i>)</small>')
			table.insert(textHide, '\n*** <small><i>[[Wiktionary:About Chinese/Wu|Wiktionary]]</i></small>: <font face="Consolas">')
			table.insert(textHide, w_pron.rom(w_rom))
			table.insert(textHide, '</font>')
			table.insert(textHide, '\n*** <small>[[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:Shanghainese|key]])</sup></small>: <span class="IPA">/')
			table.insert(textHide, w_pron.ipa_conv(w_rom))
			table.insert(textHide, '/</span>')
			add_audio(textHide, w_audio, 'wuu')
			if args["w_note"] then table.insert(textHide, makeNote(args["w_note"])) end
		end
		if x_rom .. x_audio ~= "" then
			local x_pron = require("Module:hsn-pron")
			if x_rom ~= "" then
				table.insert(textShow, '\n* [[w:Xiang Chinese|Xiang]] <small>(<i>[[Wiktionary:About Chinese/Xiang|Wiktionary]]</i>)</small>: <font face="Consolas">')
				table.insert(textShow, x_pron.rom(x_rom))
				table.insert(textShow, '</font>')
			end
			table.insert(textHide, '\n* [[w:Xiang Chinese|Xiang]]')
			table.insert(textHide, '\n** <small>(<i>[[w:Changsha dialect|Changsha]]</i>)</small>')
			if x_rom ~= '' then
				x_diff = x_pron.stylediff(x_rom)
				table.insert(textHide, '\n*** <small><i>[[Wiktionary:About Chinese/Xiang|Wiktionary]]</i></small>: <font face="Consolas">')
				table.insert(textHide, x_pron.rom(x_rom))
				table.insert(textHide, '</font>')
				table.insert(textHide, '\n*** <small>[[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:Changsha dialect|key]])</sup>')
				table.insert(textHide, x_diff and ' (<i>old-style</i>)' or '')
				table.insert(textHide, '</small>: <span class="IPA">/')
				table.insert(textHide, x_pron.ipa(x_rom))
				table.insert(textHide, '/</span>')
				if x_diff then
					table.insert(textHide, '\n*** <small>[[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:Changsha dialect|key]])</sup> (<i>new-style</i>)</small>: <span class="IPA">/')
					table.insert(textHide, x_pron.ipa(x_rom, 'new'))
					table.insert(textHide, '/</span>')
				end
			end
			add_audio(textHide, x_audio, 'hsn')
			if args["x_note"] then table.insert(textHide, makeNote(args["x_note"])) end
		end
		text = {table.concat(textShow), '\n<div class="mw-collapsible-content">\n----\n', table.concat(textHide), '</div>'}
		if c_rom == "" then table.insert(text, "[[Category:Kenny's testing category 2]]") end
		
		if dial ~= "n" and mw.ustring.len(mw.title.getCurrentTitle().text) == 1 then
			local success, m_dial = pcall(mw.loadData, "Module:zh/data/dial-pron/" .. pagename)
			if success then
				local dialPron = {}
				reading_count = 0
				local temporary = {}
				if mw.ustring.match(dial, "^[0-9\,]+$") then
					for element in mw.text.gsplit(dial, ",") do
						table.insert(dialPron, m_dial[tonumber(element)])
						reading_count = reading_count + 1
					end
				else
					for _, element in ipairs(m_dial) do
						table.insert(dialPron, element)
						reading_count = reading_count + 1
					end
				end
				for _, set in ipairs(dialPron) do
					for _, object in ipairs(set[2]) do
						table.insert(temporary, object)
					end
				end
				rand = mw.ustring.gsub("-" .. table.concat(temporary), "[^A-Za-z0-9]", mw.ustring.codepoint('%1'))
				table.insert(text, '\n----\n<div style="background-color:#FAFFFA">\n* <div title="expand" ' ..
					'class="mw-customtoggle-dial' .. rand .. '"><span style="color:#3366bb">Dialectal data' ..
					'</span><span style="float:right; border:1px solid #ccc; border-radius:1px; ' ..
					'padding:0 0; font-size:90%">▼</span></div>')
				
				table.insert(text, '\n{| class="wikitable mw-collapsible mw-collapsed" ' ..
					'id="mw-customcollapsible-dial' .. rand .. '" style="width:100%; margin:0; ' ..
					'text-align:center; border-collapse: collapse; border-style: hidden;"')
				
				local locStart = '\n|-\n!'
				local readingStart = table.concat({'\n!style="background:#E8ECFA; width:9em"|',
				'<div style="float: right; clear: right; font-size:60%"><span class="plainlinks">[', tostring(mw.uri.fullUrl("Module:zh/data/dial-pron/" .. pagename, {["action"]="edit"})), ' edit]</span></div></sup><span lang="zh" class="Hani">'})
				local locEnd = '<span class="IPA">'
				local headclr = 'style="background:#E8ECFA"|'
				local mclr = 'style="background:#FAF5F0"|'
				local jclr = 'style="background:#F0F5FA"|'
				local wclr = 'style="background:#F4F0FA"|'
				local huclr = 'style="background:#FAF9F0"|'
				local xclr = 'style="background:#F0F2FA"|'
				local gclr = 'style="background:#F0FAF3"|'
				local haclr = 'style="background:#FAF0F6"|'
				local cclr = 'style="background:#F0F5FA"|'
				local minclr = 'style="background:#F7FAF0"|'
				local clrList = {
					mclr, mclr, mclr, mclr, mclr, mclr, mclr, mclr, mclr, mclr,
					mclr, mclr, mclr, mclr, mclr, mclr, mclr, jclr, jclr, jclr,
					wclr, wclr, wclr, wclr, huclr, huclr, xclr, xclr, gclr, haclr,
					haclr, cclr, cclr, cclr, minclr, minclr, minclr, minclr, minclr
				}
				local locList = {
					table.concat({headclr, "Variety\n!", headclr, "Location"}),
					table.concat({"rowspan=17 ", mclr,  "Mandarin\n!", mclr, "[[w:Beijing dialect|Beijing]]\n|", mclr}),
					table.concat({mclr, "[[w:Harbin dialect|Harbin]]\n|", mclr}),
					table.concat({mclr, "[[w:Tianjin dialect|Tianjin]]\n|", mclr}),
					table.concat({mclr, "[[w:Jinan dialect|Jinan]]\n|", mclr}),
					table.concat({mclr, "[[w:Qingdao dialect|Qingdao]]\n|", mclr}),
					table.concat({mclr, "[[w:zh:鄭州話|Zhengzhou]]\n|", mclr}),
					table.concat({mclr, "[[w:Xi'an dialect|Xi'an]]\n|", mclr}),
					table.concat({mclr, "[[w:Xining|Xining]]\n|", mclr}),
					table.concat({mclr, "[[w:Yinchuan|Yinchuan]]\n|", mclr}),
					table.concat({mclr, "[[w:zh:蘭州話|Lanzhou]]\n|", mclr}),
					table.concat({mclr, "[[w:zh:烏魯木齊話|Ürümqi]]\n|", mclr}),
					table.concat({mclr, "[[w:zh:武漢話|Wuhan]]\n|", mclr}),
					table.concat({mclr, "[[w:Chengdu dialect|Chengdu]]\n|", mclr}),
					table.concat({mclr, "[[w:zh:貴陽話|Guiyang]]\n|", mclr}),
					table.concat({mclr, "[[w:Kunming dialect|Kunming]]\n|", mclr}),
					table.concat({mclr, "[[w:Nanjing dialect|Nanjing]]\n|", mclr}),
					table.concat({mclr, "[[w:zh:合肥話|Hefei]]\n|", mclr}),
					table.concat({"rowspan=3 ", jclr, "Jin\n!", jclr, "[[w:zh:太原話|Taiyuan]]\n|", jclr}),
					table.concat({jclr, "[[w:Pingyao|Pingyao]]\n|", jclr}),
					table.concat({jclr, "[[w:Hohhot dialect|Hohhot]]\n|", jclr}),
					table.concat({"rowspan=4 ", wclr, "Wu\n!", wclr, "[[w:Shanghai dialect|Shanghai]]\n|", wclr}),
					table.concat({wclr, "[[w:Suzhou dialect|Suzhou]]\n|", wclr}),
					table.concat({wclr, "[[w:Hangzhou dialect|Hangzhou]]\n|" , wclr}),
					table.concat({wclr, "[[w:Wenzhou dialect|Wenzhou]]\n|", wclr}),
					table.concat({"rowspan=2 ", huclr, "Hui\n!", huclr, "[[w:Shexian|Shexian]]\n|", huclr}),
					table.concat({huclr, "[[w:zh:屯溪話|Tunxi]]\n|", huclr}),
					table.concat({"rowspan=2 ", xclr, "Xiang\n!", xclr, "[[w:Changsha dialect|Changsha]]\n|", xclr}),
					table.concat({xclr, "[[w:zh:湘潭話|Xiangtan]]\n|", xclr}),
					table.concat({gclr, "Gan\n!", gclr, "[[w:Nanchang dialect|Nanchang]]\n|", gclr}),
					table.concat({"rowspan=2 ", haclr, "Hakka\n!", haclr, "[[w:Meixian dialect|Meixian]]\n|", haclr}),
					table.concat({haclr, "[[w:Taoyuan, Taiwan|Taoyuan]]\n|", haclr}),
					table.concat({"rowspan=3 ", cclr, "Cantonese\n!", cclr, "[[w:Guangzhou dialect|Guangzhou]]\n|", cclr}),
					table.concat({cclr, "[[w:Nanning|Nanning]]\n|", cclr}),
					table.concat({cclr, "[[w:Hong Kong dialect|Hong Kong]]\n|", cclr}),
					table.concat({"rowspan=5 ", minclr, "Min\n!", minclr, "[[w:Xiamen dialect|Xiamen]] (Min Nan)\n|", minclr}),
					table.concat({minclr, "[[w:Fuzhou dialect|Fuzhou]] (Min Dong)\n|", minclr}),
					table.concat({minclr, "[[w:Jian'ou dialect|Jian'ou]] (Min Bei)\n|", minclr}),
					table.concat({minclr, "[[w:Shantou dialect|Shantou]] (Min Nan)\n|", minclr}),
					table.concat({minclr, "[[w:Haikou dialect|Haikou]] (Min Nan)\n|", minclr})}
				
				function ipa_correct(ipa, location)
					if location == 22 then return (gsub(ipa, "13", "23")) else return ipa end
				end
				
				function fmtDial(text, location)
					local fmttedPron = {}
					if text == "" then return "" end
					for pronunciation in mw.text.gsplit(text, "|") do
						ipa = mw.ustring.match(pronunciation, "^[^\(\)一-龯㐀-䶵~,]+")
						ipa = gsub(ipa, "([ptk])([0-5])", "%1̚%2")
						environ = mw.ustring.match(pronunciation, "[\(\)一-龯㐀-䶵~,]*$") or false
						table.insert(fmttedPron, "<span class=\"IPA\"><small>/" ..
							tostring(ipa_format(ipa_correct(ipa, location))) .. "/</small></span>" .. (environ
							and " <small><span class=\"Hani\" lang=\"zh\">"..environ.."</small></span>" or nil))
					end
					return table.concat(fmttedPron, "<br>")
				end
					
				for locationNo = 1, 40 do
					for readingNo = 1, #dialPron do
						if readingNo == 1 then
							table.insert(text, locStart)
							table.insert(text, locList[locationNo])
						end
						if locationNo == 1 then
							situation = dialPron[readingNo][1]
							table.insert(text, readingStart)
							table.insert(text, pagename)
							table.insert(text, (pagename ~= situation and " (" ..
								gsub(situation, pagename, "<b>" .. pagename .. "</b>") .. ")" or ""))
							table.insert(text, "</span>")
						else
							table.insert(text, (readingNo == 1 and "" or "\n|" .. clrList[locationNo-1]))
							table.insert(text, locEnd)
							table.insert(text, fmtDial(dialPron[readingNo][2][locationNo-1], locationNo))
							table.insert(text, "</span>")
						end
					end
				end
				table.insert(text, "\n|}</div>")
			end
		end
		if mc then
			m_ltc_pron = require("Module:ltc-pron")
			mc_preview = m_ltc_pron.retrieve_pron(pagename, false, mc, true)
			if not mc_preview then
				mc = false
			end
		end
		if oc then
			m_och_pron = require("Module:och-pron")
			oc_preview = m_och_pron.generate_show(pagename, oc)
			if not oc_preview then
				oc = false
			end
		end
		if mc or oc then
			table.insert(text, '\n----\n<div style="background-color:#f7fbff">')
			if mc then
				table.insert(text, m_ltc_pron.ipa(mc, mc_preview))
			end
			if oc then
				table.insert(text, m_och_pron.ipa(oc, oc_preview))
			end
			table.insert(text, "</div>")
		end
		table.insert(text, "</div>")
	end
	conv_text = {}
	if mw.title.getCurrentTitle().nsText == "" then
		local catText = args["cat"]
		local cat = {}
		local cat_start = '[[Category:'
		local cat_end = ']]'
		rom = m_rom ~= "" and m_rom or mw.title.getCurrentTitle().text
		if mw.ustring.match(rom, '[一-龯㐀-䶵]') then
			local m_cmn_pron = mw.loadData("Module:zh/data/cmn-pron")
			rom = gsub(rom, '.', m_cmn_pron.py)
		end
		local m_pron = require("Module:cmn-pron")
		rom = m_pron.py_transform(rom, true, true)
		if w_rom ~= '' then
			w_rom = gsub(w_rom, '%d', '')
		end
		
		local function add_cat(cat_table, name, cat, rom)
			local this_cat = {}
			table.insert(this_cat, cat_start)
			table.insert(this_cat, name)
			table.insert(this_cat, cat)
			table.insert(this_cat, "|")
			table.insert(this_cat, rom)
			table.insert(this_cat, cat_end)
			table.insert(cat_table, table.concat(this_cat))
		end
		
		if catText and catText ~= '' and mw.title.getCurrentTitle().nsText == '' or mw.title.getCurrentTitle().nsText == 'User' then
			cat = mw.text.split(catText, ',', true)
			if (pos_aliases_cat[cat[1]] or "") == 'chengyu' then
				table.insert(cat, 2, 'idioms')
			end
			table.insert(cat, 1, "lemmas")
			for i = 1, #cat do
				cat[i] = gsub(cat[i], '^ +', '')
				if mw.ustring.match(cat[i], ':') then
					local lang_name, category = langname_abbr[mw.text.split(cat[i], ':', true)[1]], (pos_aliases_cat[mw.text.split(cat[i], ':', true)[2]] or cat[i])
					add_cat(conv_text, 'Chinese ', category, rom)
					table.insert(conv_text, cat_start)
					table.insert(conv_text, lang_name)
					table.insert(conv_text, ' ')
					table.insert(conv_text, category)
					table.insert(conv_text, '|')
					table.insert(conv_text, (lang_name == 'Cantonese' and c_rom or
							(lang_name == 'Min Nan' and (mn_rom ~= '' and mn_rom) or (mn_t_rom ~= '' and mn_t_rom) or rom)) .. cat_end)
				else
					cat[i] = pos_aliases_cat[cat[i]] or cat[i]
					add_cat(conv_text, 'Chinese ', cat[i], rom)
					if m_rom ~= '' then add_cat(conv_text, 'Mandarin ', cat[i], m_rom) end
					if m_s_rom ~= '' or m_s_audio ~= '' then add_cat(conv_text, 'Mandarin ', cat[i], m_s_rom) end
					if c_rom ~= '' then add_cat(conv_text, 'Cantonese ', cat[i], c_rom:gsub('[%[%]]','')) end
					if g_rom ~= '' or g_audio ~= '' then add_cat(conv_text, 'Gan ', cat[i], g_rom:gsub("'", "")) end
					if mw.ustring.match(h_rom, 'pfs=.') or mw.ustring.match(h_rom, 'gd=.') or h_audio ~= '' then add_cat(conv_text, 'Hakka ', cat[i], mw.ustring.gsub(mw.ustring.gsub(h_rom, 'pfs=', ''), 'gd=', '')) end
					if j_rom ~= '' or j_audio ~= '' then add_cat(conv_text, 'Jin ', cat[i], j_rom) end
					if md_rom ~= '' or md_audio ~= '' then add_cat(conv_text, 'Min Dong ', cat[i], md_rom) end
					if mn_rom ~= '' or mn_audio ~= '' then add_cat(conv_text, 'Min Nan ', cat[i], mn_rom) end
					if mn_t_rom ~= '' or mn_t_audio ~= '' then add_cat(conv_text, 'Min Nan ', cat[i], mn_t_rom) end
					if w_rom ~= '' or w_audio ~= '' then add_cat(conv_text, 'Wu ', cat[i], w_rom) end
					if x_rom ~= '' or x_audio ~= '' then add_cat(conv_text, 'Xiang ', cat[i], x_rom) end
				end
			end
		end
		table.insert(conv_text, cat_start)
		table.insert(conv_text, 'Chinese terms with IPA pronunciation|')
		table.insert(conv_text, rom)
		table.insert(conv_text, cat_end)
		if mw.ustring.len(mw.title.getCurrentTitle().text) == 1 then
			table.insert(conv_text, cat_start)
			table.insert(conv_text, 'Chinese hanzi|')
			table.insert(conv_text, rom)
			table.insert(conv_text, cat_end)
		end
	end
	
	if mw.title.getCurrentTitle().nsText ~= '' then
		return (gsub(table.concat(text) .. table.concat(conv_text), "%[%[Category:[^%]]+%]%]", ""))
	else
		return (table.concat(text) .. table.concat(conv_text))
	end
end

function ipa_format(text)
	local numbers = { [1]='¹',[2]='²',[3]='³',[4]='⁴',[5]='⁵',[0]='⁰',['-']='⁻',['/']='/, /' }
	return gsub(text,'[0-5%-/]',numbers)
end

function add_audio(text, audio, lang)
	-- This function has side effects
	if audio ~= "" then
		if audio == "y" then audio = lang .. '-' .. mw.title.getCurrentTitle().baseText .. '.ogg' end
		table.insert(text, '\n*** [[File:')
		table.insert(text, audio)
		table.insert(text, ']]')
		table.insert(text, '[[Category:')
		table.insert(text, langname[lang:sub(1, 3)])
		table.insert(text, ' terms with audio links]]')
	end
end

return export