Bu modul uchun Modul:hak-pron/doc nomli hujjat sahifasini yaratishingiz mumkin

local export = {}

function export.rom_display(text,convtype)
	if type(text) == 'table' then text,convtype = text.args[1],(text.args[2] or '') end
	local display = ''
	local decomp = mw.text.split(text,';',true)
	for i = 1,#decomp,1 do
		if mw.ustring.match(decomp[i],'pfs') then
			display = display .. "\n*** ''[[w:Pha̍k-fa-sṳ|Pha̍k-fa-sṳ]]'': <tt>" .. string.gsub(string.gsub(decomp[i],'[%[%]]',''),'pfs=','') .. '</tt>'
			if convtype ~= '' then
				display = string.gsub(decomp[i],'pfs=','')
				return display
			end
		end
		if mw.ustring.match(decomp[i],'gd') then display = display .. "\n*** ''[[w:Guangdong_Romanization#Hakka|Guangdong]]'': <tt>" .. string.gsub(decomp[i],'gd=','') .. '</tt>' end
		if mw.ustring.match(decomp[i],'hpy') then display = display .. "\n*** ''[[w:Hagfa Pinyim|Hagfa Pinyim]]'': <tt>" .. string.gsub(decomp[i],'hpy=','') .. '</tt>' end
		if mw.ustring.match(decomp[i],'poj') then display = display .. "\n*** ''[[w:POJ#Adaptations for other languages or dialects|POJ]]'': <tt>" .. string.gsub(decomp[i],'poj=','') .. '</tt>' end
	end
	return display
end

function export.ipa(text)
	local syllables, initial, final, tone, tone_conv = {}, {}, {}, {}, {}
	local ipa = {}
	if type(text) == 'table' then text = text.args[1] end
	syllables = mw.text.split(mw.ustring.gsub(mw.ustring.lower(text), 'pfs=', ''), "-")
	for i, syllable in ipairs(syllables) do
		local palatal = false
		initial[i] = mw.ustring.match(syllable, '^[mnptkcfvshyl]?[gh]?h?')
		final[i] = mw.ustring.sub(syllable, mw.ustring.len(initial[i]) + 1, -1)
		if mw.ustring.find(final[i], '^[iíìî]') then
			palatal = true
		end
		local function add_palatal(text, add_or_not)
			local palatal_initial = {
				['ch'] = true,
				['chh'] = true,
				['s'] = true,
				['ng'] = true
			}
			if add_or_not and palatal_initial[text] then
				return text .. 'i'
			else
				return text
			end
		end
		local initial_ipa = {
			['ngi'] = 'ɲ',
			['ng'] = 'ŋ',
			['ph'] = 'pʰ',
			['th'] = 'tʰ',
			['kh'] = 'kʰ',
			['ch'] = 't͡s',
			['chi'] = 't͡ɕ',
			['chh'] = 't͡sʰ',
			['chhi'] = 't͡ɕʰ',
			['si'] = 'ɕ',
			['y'] = 'j',
		}
		initial[i] = initial_ipa[add_palatal(initial[i], palatal)] or initial[i]
		if mw.ustring.find(final[i], '[âêîôû̂]') then
			tone[i] = 1
		elseif mw.ustring.find(final[i], '[àèìòù̀]') then
			tone[i] = 2
		elseif mw.ustring.find(final[i], '[áéíóú́]') then
			tone[i] = 3
		elseif mw.ustring.find(final[i], '̍') then
			tone[i] = 6
		elseif mw.ustring.find(final[i], '[ptk]$') then
			tone[i] = 5
		else
			tone[i] = 4
		end
		local final_conv = {
			['á'] = 'a', ['é'] = 'e', ['í'] = 'i', ['ó'] = 'o', ['ú'] = 'u', ['́'] = '',
			['à'] = 'a', ['è'] = 'e', ['ì'] = 'i', ['ò'] = 'o', ['ù'] = 'u', ['̀'] = '',
			['â'] = 'a', ['ê'] = 'e', ['î'] = 'i', ['ô'] = 'o', ['û'] = 'u', ['̂'] = '',
			['ń'] = 'n', ['ǹ'] = 'n',
			['̍'] = '',
			['ṳ'] = 'ɨ',
		}
		final[i] = mw.ustring.gsub(final[i], '[âêîôû̂àèìòù̀áéíóú́ńǹ̍ṳ]', final_conv)
		final[i] = mw.ustring.gsub(final[i], '([ptk])$', '%1̚')
		final[i] = mw.ustring.gsub(final[i], 'ng$', 'ŋ')
		final[i] = final[i] == 'ŋ' and 'ŋ̍' or final[i]
		final[i] = mw.ustring.gsub(final[i], '([aeiouɨ])([aeiouɨ])([aeiouɨ]?)', function(first, second, third)
			if third ~= '' then
				return first .. '̯' .. second .. third .. '̯'
			else
				return first .. '̯' .. second
			end end)
	end
	for i, syllable in ipairs(syllables) do
		local tone_ipa = {
			[1] = '²⁴',
			[2] = '¹¹',
			[3] = '³¹',
			[4] = '⁵⁵',
			[5] = '²',
			[6] = '⁵',
		}
		tone_conv[i] = tone_ipa[tone[i]]
		if tone[i] == 1 and mw.ustring.find(tostring(tone[i+1]), '[146]') then
			tone_conv[i] = tone_conv[i] .. '⁻¹¹'
		end
		ipa[i] = initial[i] .. final[i] .. tone_conv[i]
	end
	return table.concat(ipa, " ")
end

return export