Module:zh-pron

Definition from Wiktionary, the free dictionary
Jump to: navigation, search

Used by Template:zh-pron


local m_zh = require("Module:zh")
local m_zh_data = mw.loadData("Module:zh/data")
local m_links = require("Module:links")
local lang= require("Module:languages").getByCode("zh")
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']='Cantonese'
}

local langname_abbr = {
	['md']='Min Dong',
	['m']='Mandarin',
	['j']='Jin',
	['g']='Gan',
	['h']='Hakka',
	['x']='Xiang',
	['mn']='Min Nan',
	['w']='Wu',
	['c']='Cantonese'
}



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', --things related to nouns
	['v']='verbs', ['verb']='verbs', ['a']='adjectives', ['adj']='adjectives', ['adjective']='adjectives', ['adv']='adverbs', ['adverb']='adverbs', --other main POSes
	['prep']='prepositions', ['pre']='prepositions', ['postp']='postpositions', ['post']='postpositions', ['con']='conjunctions', ['conj']='conjunctions', ['conjunction']='conjunctions', --sentence modifiers
	['part']='particles', ['particle']='particles', ['pref']='prefixes', ['prefix']='prefixes', ['suf']='suffixes', ['suffix']='suffixes', ['interfix']='interfixes', --word modifiers
	['prov']='proverbs', ['proverb']='proverbs', ['id']='idioms', ['idiom']='idioms', ['ch']='chengyu', ['cy']='chengyu', ['chengyu']='chengyu', ['ph']='phrases', ['phrase']='phrases', ['intj']='interjections', ['interj']='interjections', ['interjection']='interjections', --more than one word
	['cl']='classifiers', ['cls']='classifiers', ['classifier']='classifiers', ['num']='numerals', ['numeral']='numerals', ['abb']='abbreviations', ['abbreviation']='abbreviations', ['det']='determiners', ['deter']='determiners', ['determiner']='determiners', --other
};

function count(text)
	if text == "" then
		return 0
	end
	return 1
end

local m_pron = require("Module:cmn-pron")
local c_pron = require("Module:yue-pron")
local h_pron = require("Module:hak-pron")
local md_pron = require("Module:cdo-pron")
local mn_pron = require("Module:nan-pron")
local w_pron = require("Module:wuu-pron")

function makeNote(text)
	return "\n*** <span style=\"background: #FAF1DE\"><small>'''Note''': " .. text .. ".</small></span>"
end

function export.make_table(frame)
	local args = frame:getParent().args
	local m_rom = args["m"] or ""
	local c_rom = args["c"] 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 c_audio = args["ca"] 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 text = ''
	local count = count(m_rom..m_audio) + count(c_rom..c_audio) + count(md_rom..md_audio) + count(mn_rom..mn_audio) + count(mn_t_rom..mn_t_audio) + count(w_rom..w_audio) + count(g_rom..g_audio) + count(mw.ustring.gsub(h_rom,'pfs=','')..h_audio) + count(j_rom..j_audio) + count(x_rom..x_audio)
	c_rom = c_rom:gsub("%*","-")
	if g_rom ~= '' then g_rom = ipa_format(g_rom) end
	if j_rom ~= '' then j_rom = ipa_format(j_rom) end
	if x_rom ~= '' then x_rom = ipa_format(x_rom) end
	if count > 1 then
		text = text .. '<div class="toccolours mw-collapsible mw-collapsed" style="width:500px; font-size:100%">'
		if m_rom ~= "" then
			text = text .. '\n* [[w:Mandarin Chinese|Mandarin]]\n' .. m_pron.str_analysis(m_rom,'head')
		end
		if c_rom ~= "" then
			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
			text = text .. '\n* [[w:Cantonese|Cantonese]] (\'\'[[w:Jyutping|Jyutping]]\'\'): <font face="Consolas">' .. c_processed .. '</font>'
			c_rom = c_rom:gsub('[%[%]]','')
		end
		if g_rom ~= '' then
			text = text .. '\n* [[w:Gan Chinese|Gan]] (\'\'[[w:International Phonetic Alphabet|IPA]]\'\'): <span class="IPA">/' .. g_rom .. '/</span>'
		end
		if mw.ustring.find(h_rom,'^pfs=.') then
			text = text .. '\n* [[w:Hakka Chinese|Hakka]] (\'\'[[w:Pha̍k-fa-sṳ|Pha̍k-fa-sṳ]]\'\'): <font face="Consolas">' .. h_pron.rom_display(h_rom,'yes') .. '</font>'
		end
		if j_rom ~= '' then
			text = text .. '\n* [[w:Jin Chinese|Jin]] (\'\'[[w:International Phonetic Alphabet|IPA]]\'\'): <span class="IPA">/' .. j_rom .. '/</span>'
		end
		if md_rom ~= "" then
			text = text .. '\n* [[w:Min Dong|Min Dong]] (\'\'[[w:Bàng-uâ-cê|BUC]]\'\'): <font face="Consolas">' .. gsub(md_rom, "/", " / ") .. '</font>'
		end
		if mn_rom .. mn_t_rom ~= "" then
			text = text .. '\n* [[w:Min Nan|Min Nan]]'
			if mn_rom ~= "" then
				text = text .. '\n*: (\'\'[[w:Hokkien|Hokkien]], [[w:Pe̍h-ōe-jī|POJ]]\'\'): <font face="Consolas">' .. mn_pron.poj_display(mn_pron.poj_check_invalid(mn_rom)) .. '</font>'
			end
			if mn_t_rom ~= "" then
				text = text .. '\n*: (\'\'[[w:Teochew dialect|Teochew]], [[w:zh:潮州話拼音方案|Peng\'im]]\'\'): <font face="Consolas">' .. mn_pron.pengim_display(mn_t_rom) .. '</font>'
			end
		end
		if w_rom ~= "" then
			text = text .. '\n* [[w:Wu Chinese|Wu]] (\'\'[[Wiktionary:About Chinese/Wu|WT Romanisation]]\'\'): <font face="Consolas">' .. w_pron.rom(w_rom) .. '</font>'
		end
		if x_rom ~= '' then
			text = text .. '\n* [[w:Xiang Chinese|Xiang]] (\'\'[[w:International Phonetic Alphabet|IPA]]\'\'): <span class="IPA">/' .. x_rom .. '/</span>'
		end
		text = text .. '\n<div class="mw-collapsible-content">\n----'
	end
	text = text .. '\n'
	if m_rom .. m_audio ~= "" then
		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','3n','3na','3nb','3nc','3nd','3py','3cap','3tl','3tl2','3tl3','3a','3audio','4n','4na','4nb','4nc','4nd','4py','4cap','4tl','4tl2','4tl3','4a','4audio'}
		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
		text = text .. m_pron.make_args(m_args)
		if args["m_note"] then text = text .. makeNote(args["m_note"]) end
	end
	if c_rom .. c_audio ~= "" then
		text = text .. '\n* [[w:Cantonese|Cantonese]]'
		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
		text = text .. '\n** (\'\'[[w:Standard Cantonese|Standard Cantonese]], [[w:Guangzhou Cantonese|Guangzhou]]\'\')'
		if not c_hom_exists then
			text = text .. '<sup><small><abbr title="Add Cantonese homophones (click on this if and only if you know what you are doing!)"><span class="plainlinks">[' .. tostring(mw.uri.fullUrl("Module:yue-pron/hom",{["action"]="edit"})) .. ' +]</span></abbr></small></sup>'
		end
		c_comma = gsub(c_rom,',([^ ])',', %1')
		text = text .. '\n*** \'\'[[w:Jyutping|Jyutping]]\'\': <font face="Consolas">' .. gsub(c_comma, '([1-9-]*)', '<sup>%1</sup>') .. '</font>'
		text = text .. '\n*** \'\'[[w:Yale romanization of Cantonese|Yale]]\'\': <font face="Consolas">' .. c_pron.jyutping_to_yale(c_rom) .. '</font>'
		text = text .. '\n*** \'\'[[w:Cantonese Pinyin|Cantonese Pinyin]]\'\': <font face="Consolas">' .. gsub(c_pron.jyutping_to_cantonese_pinyin(c_rom), '([1-9-]*)', '<sup>%1</sup>') .. '</font>'
		text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:Cantonese phonology|key]])</sup>: <span class="IPA">/' .. c_pron.jyutping_to_ipa(c_rom) .. '/</span>'
		for _,c_first in ipairs(c_pron.jyutping_format(c_rom)) do
			if c_hom_exists == c_first then
				local hom_text = '\n*** Homophones: <table class="wikitable mw-collapsible mw-collapsed" style="width:15em;margin:0; position:left; text-align:center"><tr><th></th></tr><tr><td><sup><div style="float: right; clear: right;"><span class="plainlinks">[' .. tostring(mw.uri.fullUrl("Module:yue-pron/hom",{["action"]="edit"})) .. ' 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
					hom_text = hom_text .. "<span class=\"Hani\">[[" .. mw.ustring.gsub(hom,"/","]]/[[") .. "]]</span><br />"
				end
				hom_text = mw.ustring.gsub(hom_text,"<br />$","")
				hom_text = hom_text .. '</td></tr></table>'
				hom_text = m_links.language_link(hom_text, nil, lang, nil, false)
				text = text .. hom_text .. '[[Category:Cantonese terms with homophones]]'
			end
		end
		text = add_audio(text,c_audio,'yue')
		if args["c_note"] then text = text .. makeNote(args["c_note"]) end
	end
	if g_rom .. g_audio ~= "" then
		text = text .. '\n* [[w:Gan Chinese|Gan]]'
		text = text .. '\n** (\'\'[[w:Nanchang dialect|Nanchang]]\'\')'
		if g_rom ~= '' then text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:Nanchang dialect|key]])</sup>: <span class="IPA">/' .. g_rom .. '/</span>' end
		text = add_audio(text,g_audio,'gan')
	end
	if (mw.ustring.match(h_rom, '^pfs=.') or "") .. h_audio ~= "" then
		text = text .. '\n* [[Wiktionary:About Chinese/Hakka|Hakka]]'
		if h_rom ~= '' then text = text .. h_pron.rom_display(h_rom,'') end
		if h_audio ~= '' then text = add_audio(text,h_audio,'hak') end
		if args["h_note"] then text = text .. makeNote(args["h_note"]) end
	end
	if j_rom .. j_audio ~= "" then
		text = text .. '\n* [[w:Jin Chinese|Jin]]'
		text = text .. '\n** (\'\'[[w:Taiyuan|Taiyuan]]\'\')<sup>[[:w:zh:太原話|+]]</sup>'
		if j_rom ~= '' then text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:Taiyuan|key]])</sup>: <span class="IPA">/' .. j_rom .. '/</span>' end
		text = add_audio(text,j_audio,'cjy')
	end
	if md_rom .. md_audio ~= "" then
		text = text .. '\n* [[w:Min Dong|Min Dong]]'
		text = text .. '\n** (\'\'[[w:Fuzhou dialect|Fuzhou]]\'\')'
		if md_rom ~= '' then
			text = text .. '\n*** \'\'[[w:Bàng-uâ-cê|Bàng-uâ-cê]]\'\': <font face="Consolas">' .. gsub(md_rom, "/", " / ") .. '</font>'
			if not mw.ustring.match(md_rom, ' ') and not mw.ustring.match(md_rom, '([^/]*)-([^/]*)-([^/]*)') then
				text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:Fuzhou dialect|key]])</sup>: <span class="IPA">/'
				i = 0
				for word in mw.text.gsplit(md_rom, '/') do
					i = i + 1
					if i ~= 1 then
						text = text .. '/, /'
					end
					text = text .. md_pron.ipa(word)
				end
				text = text .. '/</span>'
			end
		end
		text = add_audio(text,md_audio,'cdo')
		if args["md_note"] then text = text .. makeNote(args["md_note"]) end
	end
	if mn_rom .. mn_audio .. mn_t_rom .. mn_t_audio ~= "" then
		text = text .. '\n* [[w:Min Nan|Min Nan]]'
		if mn_rom .. mn_audio ~= "" then
			text = text .. '\n** (\'\'[[w:Hokkien|Hokkien]]\'\')'
			mn_pron.poj_check_invalid(mn_rom)
			text = text .. '\n*** \'\'[[w:Pe̍h-ōe-jī|Pe̍h-ōe-jī]]\'\': <font face="Consolas">' .. mn_pron.poj_display(mn_rom) .. '</font>'
			mn_tailo = mn_pron.poj_to_tl_conv(mn_rom)
			mn_tailo = gsub(mn_tailo,'/([^ ])',' / %1')
			text = text .. '\n*** \'\'[[w:Tâi-lô|Tâi-lô]]\'\': <font face="Consolas">' .. mn_tailo .. '</font>'
			if not mw.ustring.find(mn_rom,'%-%-') and not mw.ustring.find(mn_rom,'[,.?!]') then
					mn_psdb = mn_pron.poj_to_psdb_conv(mn_rom)
					mn_psdb = gsub(mn_psdb,'/([^ ])',' / %1')
					text = text .. '\n*** \'\'[[w:Phofsit Daibuun|Phofsit Daibuun]]\'\': <font face="Consolas">' .. mn_psdb .. '</font>'
					text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|IPA]] (\'\'[[w:Taipei|Taipei]]\'\'): <span class="IPA">/' .. mn_pron.poj_to_ipa_conv(mn_rom,'Taipei') .. '/</span>'
					text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|IPA]] (\'\'[[w:Zhangzhou|Zhangzhou]]\'\'): <span class="IPA">/' .. mn_pron.poj_to_ipa_conv(mn_rom,'Zhangzhou') .. '/</span>'
			end
			text = add_audio(text,mn_audio,'nan')
			if args["mn_note"] then text = text .. makeNote(args["mn_note"]) end
		end
		if mn_t_rom .. mn_t_audio ~= "" then
			text = text .. '\n** (\'\'[[w:Teochew dialect|Teochew]]\'\')'
			text = text .. '\n*** \'\'[[w:zh:潮州話拼音方案|Peng\'im]]\'\': <font face="Consolas">' .. mn_pron.pengim_display(mn_t_rom) .. '</font>'
			text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:zh:潮州話#聲調|key]])</sup>: <span class="IPA">' .. mn_pron.pengim_to_ipa_conv(mn_t_rom) .. '</span>'
			text = add_audio(text,mn_t_audio,'nan')
			if args["mn-t_note"] then text = text .. makeNote(args["mn-t_note"]) end
		end
	end
	if w_rom .. w_audio ~= "" then
		text = text .. '\n* [[w:Wu Chinese|Wu]]'
		text = text .. '\n** (\'\'[[w:Shanghainese|Shanghainese]]\'\')'
		text = text .. '\n*** \'\'[[Wiktionary:About Chinese/Wu|WT Romanisation]]\'\': <font face="Consolas">' .. w_pron.rom(w_rom) .. '</font>'
		text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:Shanghainese|key]])</sup>: <span class="IPA">/' .. w_pron.ipa_conv(w_rom) .. '/</span>'
		if args["w_note"] then text = text .. makeNote(args["w_note"]) end
		text = add_audio(text,w_audio,'wuu')
	end
	if x_rom .. x_audio ~= "" then
		text = text .. '\n* [[w:Xiang Chinese|Xiang]]'
		text = text .. '\n** (\'\'[[w:Changsha dialect|Changsha]]\'\')'
		if x_rom ~= '' then text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:Changsha dialect|key]])</sup>: <span class="IPA">/' .. x_rom .. '/</span>' end
		text = add_audio(text,x_audio,'hsn')
	end
	if count > 1 then
		text = text .. '</div></div>'
	end
	if c_rom == "" then text = text .. "[[Category:Kenny's testing category 2]]" end
	
	if mw.title.getCurrentTitle().nsText ~= '' then
		text = mw.ustring.gsub(text, "%[%[Category:[^%]]+%]%]", "")
	end
	if dial ~= "n" and mw.ustring.len(mw.title.getCurrentTitle().text) == 1 then
		local m_dial = mw.loadData("Module:zh/data/dial-pron")
		local pagename = mw.title.getCurrentTitle().text
		if m_dial[pagename] then
			nOccur = pagename == "下" and 3 or (mw.ustring.match(pagename, "[任會興喝應數更橫燎甲看着累繞肚闢難]") and 2 or 1)
			text = text .. 
				'\n{| class="wikitable mw-collapsible mw-collapsed" style="margin:0; text-align:center;"\n|-\n!colspan=' ..
				(nOccur + 2) .. ' style="background:#F7FFF7; width:' .. (20 + 10 * nOccur) ..
				'em"|Dialectal pronunciations (<b><span class="Hani" lang="zh">' .. pagename .. '</span></b>)<sup>'
			
			local dialPron = {}
			local locStart = '\n|-\n!'
			local readingStart = '\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", {["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"|'
			index = 0
			while index < nOccur do
				table.insert(dialPron, m_dial[pagename .. (index == 0 and "" or (index + 1))])
				index = index + 1
			end
			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 = {
				headclr .. "Variety\n!" .. headclr .. "Location",
				"rowspan=17 " .. mclr .. "Mandarin\n!" .. mclr .. "[[w:Beijing dialect|Beijing]]\n|" .. mclr,
				mclr .. "[[w:Harbin dialect|Harbin]]\n|" .. mclr,
				mclr .. "[[w:Tianjin dialect|Tianjin]]\n|" .. mclr,
				mclr .. "[[w:Jinan dialect|Jinan]]\n|" .. mclr,
				mclr .. "[[w:Qingdao dialect|Qingdao]]\n|" .. mclr,
				mclr .. "[[w:zh:鄭州話|Zhengzhou]]\n|" .. mclr,
				mclr .. "[[w:Xi'an dialect|Xi'an]]\n|" .. mclr,
				mclr .. "[[w:Xining|Xining]]\n|" .. mclr,
				mclr .. "[[w:Yinchuan|Yinchuan]]\n|" .. mclr,
				mclr .. "[[w:zh:蘭州話|Lanzhou]]\n|" .. mclr,
				mclr .. "[[w:zh:烏魯木齊話|Ürümqi]]\n|" .. mclr,
				mclr .. "[[w:zh:武漢話|Wuhan]]\n|" .. mclr,
				mclr .. "[[w:Chengdu dialect|Chengdu]]\n|" .. mclr,
				mclr .. "[[w:zh:貴陽話|Guiyang]]\n|" .. mclr,
				mclr .. "[[w:Kunming dialect|Kunming]]\n|" .. mclr,
				mclr .. "[[w:Nanjing dialect|Nanjing]]\n|" .. mclr,
				mclr .. "[[w:zh:合肥話|Hefei]]\n|" .. mclr,
				"rowspan=3 " .. jclr .. "Jin\n!" .. jclr .. "[[w:zh:太原話|Taiyuan]]\n|" .. jclr,
				jclr .. "[[w:Pingyao|Pingyao]]\n|" .. jclr,
				jclr .. "[[w:Hohhot dialect|Hohhot]]\n|" .. jclr,
				"rowspan=4 " .. wclr .. "Wu\n!" .. wclr .. "[[w:Shanghai dialect|Shanghai]]\n|" .. wclr,
				wclr .. "[[w:Suzhou dialect|Suzhou]]\n|" .. wclr,
				wclr .. "[[w:Hangzhou dialect|Hangzhou]]\n|" .. wclr,
				wclr .. "[[w:Wenzhou dialect|Wenzhou]]\n|" .. wclr,
				"rowspan=2 " .. huclr .. "Hui\n!" .. huclr .. "[[w:Shexian|Shexian]]\n|" .. huclr,
				huclr .. "[[w:zh:屯溪話|Tunxi]]\n|" .. huclr,
				"rowspan=2 " .. xclr .. "Xiang\n!" .. xclr .. "[[w:Changsha dialect|Changsha]]\n|" .. xclr,
				xclr .. "[[w:zh:湘潭話|Xiangtan]]\n|" .. xclr,
				gclr .. "Gan\n!" .. gclr .. "[[w:Nanchang dialect|Nanchang]]\n|" .. gclr,
				"rowspan=2 " .. haclr .. "Hakka\n!" .. haclr .. "[[w:Meixian dialect|Meixian]]\n|" .. haclr,
				haclr .. "[[w:Taoyuan, Taiwan|Taoyuan]]\n|" .. haclr,
				"rowspan=3 " .. cclr .. "Cantonese\n!" .. cclr .. "[[w:Guangzhou dialect|Guangzhou]]\n|" .. cclr,
				cclr .. "[[w:Nanning|Nanning]]\n|" .. cclr,
				cclr .. "[[w:Hong Kong dialect|Hong Kong]]\n|" .. cclr,
				"rowspan=5 " .. minclr .. "Min\n!" .. minclr .. "[[w:Xiamen dialect|Xiamen]] (Min Nan)\n|" .. minclr,
				minclr .. "[[w:Fuzhou dialect|Fuzhou]] (Min Dong)\n|" .. minclr,
				minclr .. "[[w:Jian'ou dialect|Jian'ou]] (Min Bei)\n|" .. minclr,
				minclr .. "[[w:Shantou dialect|Shantou]] (Min Nan)\n|" .. minclr,
				minclr .. "[[w:Haikou dialect|Haikou]] (Min Nan)\n|" .. minclr }
			
			function fmtDial(text)
				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 ""
					table.insert(fmttedPron, "<span class=\"IPA\"><small>/" .. ipa_format(ipa) .. "/</small></span> " ..
						"<small><span class=\"Hani\" lang=\"zh\">" .. environ .. "</small></span>")
				end
				return table.concat(fmttedPron, "<br>")
			end
				
			for locationNo = 1, 40 do
				for readingNo = 1, nOccur do
					if readingNo == 1 then
						text = text .. locStart .. locList[locationNo]
					end
					if locationNo == 1 then
						situation = dialPron[readingNo][1]
						text = text .. readingStart .. pagename .. (pagename ~= situation and " (" ..
							gsub(situation, pagename, "<b>" .. pagename .. "</b>") .. ")" or "") .. "</span>"
					else
						text = text .. (readingNo == 1 and "" or "\n|" .. clrList[locationNo-1])
						text = text .. locEnd .. fmtDial(dialPron[readingNo][2][locationNo-1]) .. "</span>"
					end
				end
			end
			text = text .. "\n|}"
		end
	end
	
	return text
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)
	if audio ~= "" then
		if audio == "y" then audio = lang .. '-' .. mw.title.getCurrentTitle().baseText .. '.ogg' end
		text = text .. '\n*** [[File:' .. audio .. ']]'
		text = text .. '[[Category:'..langname[lang]..' terms with audio links]]'
	end
	return text
end

function export.make_cat(frame)
	local args = frame:getParent().args
	local m_rom = args["m"] or ''
	local c_rom = args["c"] 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 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 text = args["cat"]
	local cat = {}
	local conv_text = ''
	local cat_start = '[[Category:'
	local cat_end = ']]'
	if m_rom == '' then
		m_rom = mw.title.getCurrentTitle().text
	end
	if mw.ustring.match(m_rom,'[一-龯㐀-䶵]') then
		m_rom = gsub(m_rom,'.',m_zh_data.py)
	end
	m_rom = m_pron.py_transform(m_rom,true,true)
	if w_rom ~= '' then
		w_rom = gsub(w_rom, '%d', '')
	end
	if text and text ~= '' and mw.title.getCurrentTitle().nsText == '' or mw.title.getCurrentTitle().nsText == 'User' then
		cat = mw.text.split(text,',',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])
				conv_text = conv_text .. cat_start .. 'Chinese ' .. category .. '|' .. m_rom .. cat_end
				conv_text = conv_text .. cat_start .. lang_name .. ' ' .. category .. '|' .. 
					(lang_name == 'Cantonese' and c_rom or (lang_name == 'Min Nan' and mn_rom or m_rom)) .. cat_end
			else
				cat[i] = pos_aliases_cat[cat[i]] or cat[i]
				conv_text = conv_text .. cat_start .. 'Chinese ' .. cat[i] .. '|' .. m_rom .. cat_end
				if args["m"] then
					conv_text = conv_text .. cat_start .. 'Mandarin ' .. cat[i] .. '|' .. m_rom .. cat_end
				end
				if c_rom ~= '' then conv_text = conv_text .. cat_start .. 'Cantonese ' .. cat[i] .. '|' .. c_rom:gsub('[%[%]]','') .. cat_end end
				if g_rom ~= '' or g_audio ~= '' then conv_text = conv_text .. cat_start .. 'Gan ' .. cat[i] .. '|' .. m_rom .. cat_end end
				if mw.ustring.match(h_rom, '^pfs=.') or h_audio ~= '' then conv_text = conv_text .. cat_start .. 'Hakka ' .. cat[i] .. '|' .. m_rom .. cat_end end
				if j_rom ~= '' or j_audio ~= '' then conv_text = conv_text .. cat_start .. 'Jin ' .. cat[i] .. '|' .. m_rom .. cat_end end
				if md_rom ~= '' or md_audio ~= '' then conv_text = conv_text .. cat_start .. 'Min Dong ' .. cat[i] .. '|' .. md_rom .. cat_end end
				if mn_rom ~= '' or mn_audio ~= '' then conv_text = conv_text .. cat_start .. 'Min Nan ' .. cat[i] .. '|' .. mn_rom .. cat_end end
				if mn_t_rom ~= '' or mn_t_audio ~= '' then conv_text = conv_text .. cat_start .. 'Min Nan ' .. cat[i] .. '|' .. mn_t_rom .. cat_end end
				if w_rom ~= '' or w_audio ~= '' then conv_text = conv_text .. cat_start .. 'Wu ' .. cat[i] .. '|' .. w_rom .. cat_end end
				if x_rom ~= '' or x_audio ~= '' then conv_text = conv_text .. cat_start .. 'Xiang ' .. cat[i]  .. '|'  .. m_rom .. cat_end end
			end
		end
	end
	conv_text = conv_text .. cat_start .. 'Chinese terms with IPA pronunciation|' .. m_rom .. cat_end
	if mw.ustring.len(mw.title.getCurrentTitle().text) == 1 then
		conv_text  = conv_text .. cat_start .. 'Chinese hanzi|' .. m_rom .. cat_end
	end
	return conv_text
end

return export