มอดูล:shn-pron

จาก วิกิพจนานุกรม พจนานุกรมเสรี
local export = {}
local PAGENAME = mw.title.getCurrentTitle().text

local initials = {
	['ၵ'] = 'k', ['ၶ'] = 'kʰ', ['ၷ'] = 'ɡ', ['င'] = 'ŋ',
	['ၸ'] = 't͡ɕ', ['ၹ'] = 'z', ['ၺ'] = 'ɲ',
	['တ'] = 't', ['ထ'] = 'tʰ', ['ၻ'] = 'd', ['ၼ'] = 'n',
	['ပ'] = 'p', ['ၽ'] = 'pʰ', ['ၾ'] = 'f', ['ၿ'] = 'b', ['မ'] = 'm',
	['ယ'] = 'j', ['ရ'] = 'r', ['လ'] = 'l', ['ဝ'] = 'w',
	['ႀ'] = 'θ', ['သ'] = 'sʰ', ['ႁ'] = 'h', ['ဢ'] = 'ʔ',
	['သျ'] = 'ʃ', ['ၵျ'] = 'd͡ʑ', ['ၶျ'] = 't͡ɕʰ',
}

local medials = {
	[''] = '', ['ျ'] = 'j', ['ြ'] = 'r', ['ႂ'] = 'w',
}

local vowels = {
	[''] = 'a', ['ၢ'] = 'aː', ['ႃ'] = 'aː', ['ိ'] = 'i', ['ီ'] = 'iː', ['ု'] = 'u', ['ူ'] = 'uː', ['ူ*'] = 'o',
	['ေ'] = 'eː', ['ဵ'] = 'e', ['ႄ'] = 'ɛː', ['ႅ'] = 'ɛ', ['ွ'] = 'ɔ',
	['ဝ်'] = 'aw', ['ၢဝ်'] = 'aːw', ['ိဝ်'] = 'iw', ['ဵဝ်'] = 'ew', ['ႅဝ်'] = 'ɛw',
	['ို'] = 'ɯ', ['ိုဝ်'] = 'ɯː', ['ိူ'] = 'ɤ', ['ိူဝ်'] = 'ɤː', ['ူဝ်'] = 'oː', ['ေႃ'] = 'ɔː', ['ႂ်'] = 'aɰ',
	['ွႃ'] = 'ɔaː', -- rare
	['!'] = '', -- pure consonant sound
}

local finals = {
	[''] = '', ['ၵ်'] = 'k̚', ['င်'] = 'ŋ', ['တ်'] = 't̚', ['ၼ်'] = 'n',
	['ပ်'] = 'p̚', ['မ်'] = 'm', ['ၺ်'] = 'j',
}

local tones = {
	[''] = '˨˦', ['ႇ'] = '˩', ['ႈ'] = '˧˧˨', ['း'] = '˥', ['ႉ'] = '˦˨ˀ', ['ႊ'] = '˧',
	['x'] = '', -- no tone for !
}

local shn2th_initials = {
	['ၵ'] = 'ก',
	['ၶ'] = 'ข',
	['ၷ'] = 'ก',
	['င'] = 'หฺง',

	['ၸ'] = 'จ',
	['ၹ'] = 'จ',
	['ၺ'] = 'หฺญ',

	['တ'] = 'ต',
	['ထ'] = 'ถ',
	['ၻ'] = 'ด',
	['ၼ'] = 'หฺน',

	['ပ'] = 'ป',
	['ၽ'] = 'ผ',
	['ၾ'] = 'ฝ',
	['ၿ'] = 'บ',
	['မ'] = 'หฺม',

	['ယ'] = 'หฺย',
	['ရ'] = 'หฺร',
	['လ'] = 'หฺล',
	['ဝ'] = 'หฺว',

	['ႀ'] = 'ต',
	['သ'] = 'ส',
	['ႁ'] = 'ห',
	['ဢ'] = 'อ',

	['သျ'] = 'ฉ',
	['ၵျ'] = 'จ',
	['ၶျ'] = 'ฉ',

}

local shn2th_medials = {
	[''] = '',
	['ျ'] = 'ฺย',
	['ြ'] = 'ฺร',
	['ႂ'] = 'ฺว',

}

local shn2th_vowels = {
	[''] = 'ั',
	['ၢ'] = 'า',
	['ႃ'] = 'า',
	['ိ'] = 'ิ',
	['ီ'] = 'ี',
	['ု'] = 'ุ',
	['ူ'] = 'ู',
	['ူ*'] = '+โ-',

	['ေ'] = '+เ-',
	['ဵ'] = '+เ-',
	['ႄ'] = '+แ-',
	['ႅ'] = '+แ-',
	['ွ'] = 'อ',

	['ဝ်'] = '+เ-า',
	['ၢဝ်'] = 'าว',
	['ိဝ်'] = 'ิว',
	['ဵဝ်'] = '+เ-็ว',
	['ႅဝ်'] = '+แ-ว',

	['ို'] = 'ื',
	['ိုဝ်'] = 'ือ',
	['ိူ'] = '+เ-ิ',
	['ိူဝ်'] = '+เ-อ',
	['ူဝ်'] = '+โ-',
	['ေႃ'] = 'อ',
	['ႂ်'] = 'ะ-อือ',
	['ွႃ'] = 'อ-อา',

	['!'] = '',
	-- pure consonant sound
}

local shn2th_finals = {
	[''] = '',
	['ၵ်'] = 'ก',
	['င်'] = 'ง',
	['တ်'] = 'ต',
	['ၼ်'] = 'น',

	['ပ်'] = 'บ',
	['မ်'] = 'ม',
	['ၺ်'] = 'ย',

}

local shn2th_tones = {
	[''] = '๋',
	['ႇ'] = '่',
	['ႈ'] = '̄',
	['း'] = '๊',
	['ႉ'] = '้',
	['ႊ'] = '้',

	['x'] = '',
	-- no tone for !
}



function export.show(frame)

	local args = frame:getParent().args
	local text = args[1] or PAGENAME -- supports only one pronunciation
	local debug = args['d'] or nil
	local qualifier = args['q'] or nil
	local audioFile = args['a'] or args['audio'] or nil  -- not to use the expensive 'exists' property
	local ipa = {}
	local thai = {}
	local rhyme

	for syl in mw.text.gsplit(text, '[ %.%-]') do
		syl = mw.ustring.gsub(syl, 'ႆ', 'ၺ်') -- for easier detection
		local i, m, v, f, t = mw.ustring.match(syl,
			'^([ၵၶၷငၸၹၺတထၻၼပၽၾၿမယရလဝႀသႁဢ])([ျြႂ]?)([ၢႃိီုူေဵႄႅွဝ်!]*)([ၵငတၼပမၺ်]*)([ႇႈးႉႊx]?)$')
		
		if not i then
			error("Pattern did not match the syllable " .. tostring(syl) .. ".")
		end
		
		if i == 'သ' and m == 'ျ' then
			i = 'သျ'
			m = ''
		end
		if i == 'ၵ' and m == 'ျ' then
			i = 'ၵျ'
			m = ''
		end
		if i == 'ၶ' and m == 'ျ' then
			i = 'ၶျ'
			m = ''
		end
		if m == 'ႂ' and v == '်' then
			m = ''
			v = 'ႂ်'
		end
		if v == 'ူ' and f ~= '' then
			v = 'ူ*'
		end
		if v == '!' then
			t = 'x'
		end
		if debug then
			table.insert(ipa, '['..(i or '-')..']['..(m or '-')..']['..(v or '-')..']['..(f or '-')..']['..(t or '-')..']')
		else
			table.insert(ipa, initials[i] .. medials[m] .. vowels[v] .. finals[f] .. tones[t])
			rhyme = vowels[v] .. finals[f] -- This is meant to overwrite previous syllable.
		end

	end

	for syl in mw.text.gsplit(text, '[ %.%-]') do
		syl = mw.ustring.gsub(syl, 'ႆ', 'ၺ်') -- for easier detection
		local i, m, v, f, t = mw.ustring.match(syl,
			'^([ၵၶၷငၸၹၺတထၻၼပၽၾၿမယရလဝႀသႁဢ])([ျြႂ]?)([ၢႃိီုူေဵႄႅွဝ်!]*)([ၵငတၼပမၺ်]*)([ႇႈးႉႊx]?)$')

		if i == 'သ' and m == 'ျ' then
			i = 'သျ'
			m = ''
		end
		if i == 'ၵ' and m == 'ျ' then
			i = 'ၵျ'
			m = ''
		end
		if i == 'ၶ' and m == 'ျ' then
			i = 'ၶျ'
			m = ''
		end
		if m == 'ႂ' and v == '်' then
			m = ''
			v = 'ႂ်'
		end
		if v == 'ူ' and f ~= '' then
			v = 'ူ*'
		end
		if v == '!' then
			t = 'x'
		end
	

		if debug then
			table.insert(thai, '['..(i or '-')..']['..(m or '-')..']['..(t or '-')..']['..(v or '-')..']['..(f or '-')..']')

		else
			table.insert(thai, shn2th_initials[i] .. shn2th_medials[m] .. shn2th_tones[t] .. shn2th_vowels[v] .. shn2th_finals[f] )	
			end
		end


	return '* ' .. (qualifier and frame:expandTemplate{title = 'qualifier', args = {qualifier}} .. ' ' or '') .. '[[วิกิพจนานุกรม:สัทอักษรสากล|สัทอักษรสากล]]<sup>([[ภาคผนวก:การออกเสียงภาษาไทใหญ่|คำอธิบาย]])</sup>: <span class="IPA">/' .. table.concat(ipa, '.') ..'/</span>\n*คำอ่านภาษาไทย (ประมาณ): <span class="Thai">/' .. table.concat(thai, '.') ..'/</span>[[หมวดหมู่:ศัพท์ภาษาไทใหญ่ที่มีการออกเสียงไอพีเอ]]\n' .. (audioFile and '*'..frame:expandTemplate{title = 'audio', args = {'shn', audioFile, 'เสียง'}}..'\n' or '') .. (rhyme and '*'..frame:expandTemplate{title = 'rhymes', args = {'shn', rhyme}}..'\n' or '') .. (#ipa > 0 and '[[หมวดหมู่:ศัพท์ภาษาไทใหญ่ที่มี ' .. #ipa .. ' พยางค์]]' or '')
end



return export