Jump to content

Module:lsi-IPA

From Wiktionary, the free dictionary


local export = {}

local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("lsi")
local rsub = mw.ustring.gsub
local rlower = mw.ustring.lower

local function phonetic(text)
	text = rlower(text)
	-- syllable
	text = rsub(text, "^([aeiou])", "ʔ%1")
	text = rsub(text, " ([aeiou])", "ʔ%1")
	text = rsub(text, "$", ".")
	text = rsub(text, " ", ". .")
	text = rsub(text, "([bpdtzxjcgkvfshmnrlywʔ]g?y?h?)([aeiouw])", ".%1%2")
	text = rsub(text, "%.%.", ".")
	-- initials
	text = rsub(text, "z", "dz")
	text = rsub(text, "x", "tsʰ")
	text = rsub(text, "j", "dʑ")
	text = rsub(text, "jh", "tɕX")
	text = rsub(text, "c", "tɕʰ")
	text = rsub(text, "sh", "ɕ")
	text = rsub(text, "ng", "ŋ")
	text = rsub(text, "ny", "ɲ")
	text = rsub(text, "([mnrlyŋɲ])h", "%1X")
	text = rsub(text, "([ptk])h", "%1ʰ")
	text = rsub(text, "([ptk])(y?[aeiou])", "%1X%2")
	text = rsub(text, "Xy", "yX")
	text = rsub(text, "y", "j")
	text = rsub(text, "r", "ɹ")
	text = rsub(text, "q", "ɣ")
	
	-- syllables
	text = rsub(text, "%.m%.", ".m̩.")
	text = rsub(text, "%.n%.", ".n̩.")
	
	-- finals
	text = rsub(text, "u([iea])", "w%1")
	text = rsub(text, "Xw", "wX")
	text = rsub(text, "ei", "ɨ")
	text = rsub(text, "eu", "ʉ")
	text = rsub(text, "a([mp])", "æ%1")
	text = rsub(text, "oe", "ø")
	text = rsub(text, "oo", "O")
	text = rsub(text, ",", "ʔ")
	text = rsub(text, "([aeiOouɨʉæøɔmbndŋgʔ])%.", "%1F.")
	text = rsub(text, "꞉", "L")
	text = rsub(text, "ˮ", "H")
	text = rsub(text, "ʼ", "Q")
	text = rsub(text, "o(ʔ?[FLHQ])", "ɔ%1")
	text = rsub(text, "b([FLHQ])%.", "p̚%1.")
	text = rsub(text, "d([FLHQ])%.", "t̚%1.")
	text = rsub(text, "g([FLHQ])%.", "k̚%1.")
	text = rsub(text, "au", "aw")
	text = rsub(text, "ou", "ow")
	text = rsub(text, "oi", "oj")
	text = rsub(text, "O", "o")
	
	text = rsub(text, "X([aeiouɨʉæøɔ])", "%1̰")
	
	text = rsub(text, "F", "˧")
	text = rsub(text, "L", "˩˩")
	text = rsub(text, "H", "˥˥")
	text = rsub(text, "Q", "˥˩")
	
	-- final fixes
	text = rsub(text, "g", "ɡ")
	text = rsub(text, "%.$", "")
	text = rsub(text, "^%.", "")
	text = rsub(text, "%. ", " ")
	text = rsub(text, " %.", " ")
	text = rsub(text, "X", "")
	text = rsub(text, "t([sɕ])", "t͡%1")
	text = rsub(text, "d([zʑ])", "d͡%1")
	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
		words = {mw.title.getCurrentTitle().text}
	end
	
	local IPA_results = {}
	
	for _, word in ipairs(words) do
		table.insert(IPA_results, { pron = "[" .. phonetic(word) .. "]" })
	end
	
	return m_IPA.format_IPA_full { lang = lang, items = IPA_results }
end

return export