Module:nan-pron

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
Text-x-generic with pencil.svg This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.
This module does romanisation conversion, IPA conversion, etc. for Min Nan.
local export = {}
 
function export.poj_format(text)
	text = mw.ustring.gsub(text, 'o[áàâā]', {
		['oá'] = 'óa',
		['oà'] = 'òa',
		['oâ'] = 'ôa',
		['oā'] = 'ōa',
	})
	text = mw.ustring.gsub(text, 'oa̍', 'o̍a')
	return text
end
 
function export.poj_to_tl_conv(text)
	if type(text) == 'table' then text = text.args[1] end
	text = mw.ustring.gsub(text,'e̍[kn][g]?',{['e̍k']='i̍k',['e̍ng']='i̍ng'})
	text = mw.ustring.gsub(text,'[eéèêē][kn][g]?',{['ek']='ik',['eng']='ing',['ék']='ík',['éng']='íng',['èk']='ìk',['èng']='ìng',['êk']='îk',['êng']='îng',['ēk']='īk',['ēng']='īng'})
	text = mw.ustring.gsub(text,'o̍[ae]',{['o̍a']='ua̍',['o̍e']='ue̍'})
	text = mw.ustring.gsub(text,'[oóòôō][ae]',{['oa']='ua',['óa']='uá',['òa']='uà',['ôa']='uâ',['ōa']='uā',['oe']='ue',['óe']='ué',['òe']='uè',['ôe']='uê',['ōe']='uē'})
	text = mw.ustring.gsub(text,'[úùûū]i',{['úi']='uí',['ùi']='uì',['ûi']='uî',['ūi']='uī'})
	text = mw.ustring.gsub(text,'[ớờơ̂ơ̄ơ̍]',{['ớ']='óo',['ờ']='òo',['ơ̂']='ôo',['ơ̄']='ōo',['ơ̍']='o̍o'})
	text = string.gsub(text,'u̍i','ui̍')
	text = string.gsub(text,'ⁿ','nn')
	text = string.gsub(text,'nnh','hnn')
	text = string.gsub(text,'ch','ts')
	return text
end
 
function export.poj_to_ipa_conv(text,loc)
	if type(text) == 'table' then text,loc = text.args[1],text.args["loc"] end
	local initial={}
	local final={}
	local tone={}
	local tonesandhi={}
	local ipa={}
	local readings = mw.text.split(mw.ustring.lower(text),'/',true)
 
	for i = 1,#readings,1 do
		p = mw.text.split(readings[i],'-',true)
		for i = 1,#p,1 do
			p[i] = mw.ustring.gsub(p[i],'[ớờơ̂ơ̄ơ̍]',{['ớ']='óo',['ờ']='òo',['ơ̂']='ôo',['ơ̄']='ōo',['ơ̍']='o̍o'})
			p[i] = mw.ustring.gsub(p[i],'[̍̂̄̀]',{['̍']='捌',['̂']='伍',['̄']='柒',['̀']='叁'})
			if mw.ustring.match(p[i],'[aeiou][捌]?[ptkh]') then
				if mw.ustring.match(p[i],'捌') then
					if mw.ustring.match(p[i],'h') then
						tone[i] = '八B'
					else
						tone[i] = '八A'
					end
				else
					if mw.ustring.match(p[i],'h') then
						tone[i] = '四B'
					else
						tone[i] = '四A'
					end
				end
			elseif mw.ustring.match(p[i],'[áíúéóḿń貳]') then
				tone[i] = '二'
			elseif mw.ustring.match(p[i],'[àìùèòǹ叁]') then
				tone[i] = '三'
			elseif mw.ustring.match(p[i],'[âîûêô伍]') then
				tone[i] = '五'
			elseif mw.ustring.match(p[i],'[āīūēō柒]') then
				tone[i] = '七'
			else
				tone[i] = '一'
			end
			p[i] = mw.ustring.gsub(p[i],'[áíúéóḿńàìùèòǹâîûêôāīūēō貳叁伍柒捌]',{['á']='a',['í']='i',['ú']='u',['é']='e',['ó']='o',['ḿ']='m',['ń']='n',['貳']='',['à']='a',['ì']='i',['ù']='u',['è']='e',['ò']='o',['ǹ']='n',['叁']='',['â']='a',['î']='i',['û']='u',['ê']='e',['ô']='o',['伍']='',['ā']='a',['ī']='i',['ū']='u',['ē']='e',['ō']='o',['柒']='',['捌']=''})
			if mw.ustring.sub(p[i],1,3) == 'chh' then
				initial[i] = 'chh'
				final[i] = mw.ustring.sub(p[i],4,-1)
			elseif mw.ustring.sub(p[i],1,2) == 'ng' then
				if mw.ustring.sub(p[i],3,3) == '' then
					initial[i] = 'ʔ'
					final[i] = 'ng'
				else
					initial[i] = 'ng'
					final[i] = mw.ustring.sub(p[i],3,-1)
				end
			elseif mw.ustring.gsub(mw.ustring.sub(p[i],1,2),'[ptkc]h','') == '' then
				initial[i] = mw.ustring.sub(p[i],1,2)
				final[i] = mw.ustring.sub(p[i],3,-1)
			elseif mw.ustring.gsub(mw.ustring.sub(p[i],1,1),'[mnpbtkgjshl]','') == '' then
				initial[i] = mw.ustring.sub(p[i],1,1)
				final[i] = mw.ustring.sub(p[i],2,-1)
			else
				initial[i] = ''
				final[i] = p[i]
			end
			initial[i] = mw.ustring.gsub(initial[i],'[cktpnj][hg]?[h]?',{['ch']='t͡s',['chh']='t͡sʰ',['j']='d͡z',['ng']='ŋ',['ph']='pʰ',['kh']='kʰ',['th']='tʰ'})
			if mw.ustring.gsub(initial[i],'[td]?[͡]?[sz][ʰ]?','') == '' then
				if mw.ustring.sub(final[i],1,1) == 'i' or final[i] == 'eng' or final[i] == 'ek' then
					initial[i] = mw.ustring.gsub(initial[i],'[td]?[͡]?[sz][ʰ]?',{['t͡s']='t͡ɕ',['t͡sʰ']='t͡ɕʰ',['d͡z']='d͡ʑ',['s']='ɕ'})
				end
			end
			final[i] = mw.ustring.gsub(final[i],'hⁿ','ⁿh')
			final[i] = mw.ustring.gsub(final[i],'[ptkhⁿn][g]?',{['h']='ʔ',['ⁿ']='̃',['p']='p̚',['t']='t̚',['k']='k̚',['ng']='ŋ'})
			if mw.ustring.gsub(final[i],'[mŋ][ʔ]?','') == '' then
				final[i] = mw.ustring.gsub(final[i],'[mŋ]?',{['m']='m̩',['ŋ']='ŋ̍'})
			end
			final[i] = mw.ustring.gsub(final[i],'[aeiou][aeiou]?[iu]?',{['ai']='aɪ',['au']='aʊ',['ia']='ia',['iau']='iaʊ',['io']='iɔ',['oai']='uai',['oa']='ua',['oe']='ue',['oo']='ɔɔ'})
			final[i] = mw.ustring.gsub(final[i],'ian','iɛn')
			final[i] = mw.ustring.gsub(final[i],'e([kŋ])','ɪ%1')
			final[i] = mw.ustring.gsub(final[i],'o','ɔ')
			if mw.ustring.find(final[i],'^[i]?ɔ[h]?$') then
				final[i] = mw.ustring.gsub(final[i],'ɔ','ə')
			end
			final[i] = mw.ustring.gsub(final[i],'͘','')
			final[i] = mw.ustring.gsub(final[i],'ɔɔ','ɔ')
			final[i] = mw.ustring.gsub(final[i],'a([ɪʊ])̃','%1̃a')
		end
		for i = 1,#p,1 do
			if i ~= #tone then
				if tone[i] == '一' then
					tonesandhi[i] = '一至七'
				elseif tone[i] == '二' then
					tonesandhi[i] = '二至一'
				elseif tone[i] == '三' then
					tonesandhi[i] = '三至二'
				elseif tone[i] == '四A' then
					tonesandhi[i] = '四至八'
				elseif tone[i] == '四B' then
					final[i] = mw.ustring.gsub(final[i],'ʔ','(ʔ)')
					tonesandhi[i] = '四至七'
				elseif tone[i] == '五' then
					tonesandhi[i] = '五至七'
				elseif tone[i] == '七' then
					tonesandhi[i] = '七至三'
				elseif tone[i] == '八A' then
					tonesandhi[i] = '八至四'
				elseif tone[i] == '八B' then
					final[i] = mw.ustring.gsub(final[i],'ʔ','(ʔ)')
					tonesandhi[i] = '八至三'
				end
			else
				tonesandhi[i] = mw.ustring.gsub(tone[i],'[AB]','')
			end
			if loc == 'Zhangzhou' then
				tonesandhi[i] = mw.ustring.gsub(tonesandhi[i],'[一二三四五七八至]',{['一']='³⁴',['二']='⁵³',['三']='²¹',['四']='³²',['五']='¹³',['七']='²²',['八']='¹²¹',['至']='⁻'})
			elseif loc == 'Taipei' then
				tonesandhi[i] = mw.ustring.gsub(tonesandhi[i],'[一二三四五七八至]',{['一']='⁴⁴',['二']='⁴¹',['三']='¹¹',['四']='³²',['五']='²³',['七']='³³',['八']='⁴',['至']='⁻'})
			end
			ipa[i] = (initial[i] .. final[i] .. tonesandhi[i])
		end
		readings[i] = table.concat(ipa," ")
	end
	return table.concat(readings,"/, /")
end
 
function export.poj_display(text)
	if type(text) == 'table' then text = text.args[1] end
	if not mw.ustring.match(text,' ') then
		text = '[[' .. text .. ']]'
		text = string.gsub(text,'/',']] / [[')
	end
	return text
end
 
return export