ထာမ်ပလိက်တဏအ်ဒးနွံကဵုလိက်စၟတ်သမ္တီမချူလဝ်သာဓက။
သ္ပဂုန်တုဲထာမ်ပလိက်တဏအ်ဒးစၟတ်သမ္တီကဵုလိက်မချူလဝ်နူကဵုဓမံက်ထ္ၜးကဵုဗီုပြၚ်ကိစ္စမရန်တၟအ်လဝ် ကဵု ပရေၚ်မရပ်စပ်လ္တူမုက်လိက်နကဵုလိက်စၟတ်သမ္တီမချူလဝ်သာဓက

local export = {}

local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("mus")
local m_a = require("Module:accent qualifier").format_qualifiers
local rsub = mw.ustring.gsub
local rlower = mw.ustring.lower

local function phonetic(text)
	text = rlower(text)
	-- pitch
	text = rsub(text, "é", "eH")
	text = rsub(text, "ú", "uH")
	text = rsub(text, "á", "aH")
	text = rsub(text, "ó", "oH")
	text = rsub(text, "í", "iH")
	text = rsub(text, "ḗ", "ēH")
	text = rsub(text, "́", "H")
	text = rsub(text, "ê", "eL")
	text = rsub(text, "û", "uL")
	text = rsub(text, "â", "aL")
	text = rsub(text, "ô", "oL")
	text = rsub(text, "î", "iL")
	text = rsub(text, "̂", "L")
	-- nasality
	text = rsub(text, "ę", "eN")
	text = rsub(text, "eN̄", "ēN")
	text = rsub(text, "ų", "uN")
	text = rsub(text, "ą", "aN")
	text = rsub(text, "ǫ", "oN")
	text = rsub(text, "į", "iN")
	text = rsub(text, "̨", "N")
	-- consonants
	text = rsub(text, "c", "tʃ")
	text = rsub(text, "r", "ɬ")
	text = rsub(text, "([veuaēoiHLNmnlwy])p([veuaēoi])", "%1b%2")
	text = rsub(text, "([veuaēoiHLNmnlwy])t([veuaēoi])", "%1d%2")
	text = rsub(text, "([veuaēoiHLNmnlwy])tʃ([veuaēoi])", "%1dʒ%2")
	text = rsub(text, "([veuaēoiHLNmnlwy])k([veuaēoi])", "%1ɡ%2")
	text = rsub(text, "([veuaēoiHLNmnlwy])f([veuaēoi])", "%1V%2")
	text = rsub(text, "([veuaēoiHLNmnlwy])s([veuaēoi])", "%1z%2")
	text = rsub(text, "(oN?H?L?)k([ptkfsɬhmnlwy])", "%1q%2")
	text = rsub(text, "(oN?H?L?)ɡ([ptkfsɬhmnlwy])", "%1ɢ%2")
	text = rsub(text, "(oN?H?L?)h([ptkfsɬhmnlwy])", "%1χ%2")
	text = rsub(text, "χh", "χχ")
	text = rsub(text, "qk", "kk")
	text = rsub(text, "y", "j")
	text = rsub(text, "([ptkfsɬχmnlwj])%1", "%1ː")
	text = rsub(text, "tʃtʃ", "tʃː")
	text = rsub(text, "tʃ(ː)k", "ts%1k")
	text = rsub(text, "n([kɡ])", "ŋ%1")
	text = rsub(text, "mh", "m̥")
	text = rsub(text, "nh", "n̥")
	text = rsub(text, "lh", "l̥")
	text = rsub(text, "wh", "ʍ")
	text = rsub(text, "jh", "j̊")
	-- vowels
	text = rsub(text, "v", "ə")
	text = rsub(text, "e", "ɪ")
	text = rsub(text, "u", "ʊ")
	text = rsub(text, "i(N?H?L?)", "e%1j")
	text = rsub(text, "əo(N?H?L?)", "ə%1w")
	text = rsub(text, "ʊɪ(N?H?L?)", "ʊ%1j")
	text = rsub(text, "a(N?H?L?)", "ɑ%1ˑ")
	text = rsub(text, "ē(N?H?L?)", "i%1ˑ")
	text = rsub(text, "o(N?H?L?)", "o%1ˑ")
	text = rsub(text, "([ɑio]N?)ˑ", "%1")
	text = rsub(text, "N", "̃")
	text = rsub(text, "ˑ̃", "̃ˑ")
	text = rsub(text, "H", "́")
	text = rsub(text, "L", "̂")
	text = rsub(text, "ə([kh][ptkfsɬhmnlwj])", "ɑ%1")
	text = rsub(text, "ʊ$", "o")
	text = rsub(text, "V", "v")
	-- affricates
	text = rsub(text, "tʃ", "t͡ʃ")
	text = rsub(text, "ts", "t͡s")
	text = rsub(text, "dʒ", "d͡ʒ")
	
	return text
end

function export.IPA(frame)
	local words = {}
	
	for _, word in ipairs(frame:getParent().args) do
		table.insert(words, word)
	end
	
	if #words == 0 then
		error("Please add a first parameter for the pronunciation module!")
	end
	
	local IPA_results = {}
	
	for _, word in ipairs(words) do
		table.insert(IPA_results, { pron = "[" .. phonetic(word) .. "]" })
	end
	
	return "*" .. m_a("အဝ်ခလာဟဝ်မာ") .. " " .. m_IPA.format_IPA_full(lang, IPA_results)
end

return export