Module:mns-nor-IPA


This module is ready to use.
This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

--This code is borrowed and expanded from [[Module:udm-IPA]] made by [[User:Thadh], used with his explicid permission!

local export = {}

local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("mns-nor")
local rsub = mw.ustring.gsub
local rlower = mw.ustring.lower
local rlast = require("Module:string/replace last").replace_last

local phon = {
	-- consonants, Both w and β should be present in the pronunciation
	["б"]="b",	["в"]="w",	["г"]="ɣ",	["д"]="d",
	["ж"]="ʒ",	["з"]="z",	["й"]="j",	["к"]="k",	["л"]="l",	["м"]="m",
	["ӈ"]="ŋ",	["н"]="n",	["п"]="p",	["р"]="r",	["с"]="s",	["т"]="t",
	["ч"]="ч",  ["ф"]="f",  ["х"]="x" , ["ц"]="ц",  ["ч"]="ч",
	["ш"]="ʃ",	["щ"]="ɕ",
	-- vowels
	["а"] = "a", ["е"] = "ʲe", ["ё"] = "ʲo", ["и"] = "ʲi",
	["ӣ"] = "ʲiː", ["о"] = "o", ["у"] = "u", ["ӯ"] = "uː", ["ы"] = "ə", ["э"] = "e", ["ю"] = "ʲu", ["я"] = "ʲa", ["ъ"]="ъ",
	["ь"] = "ʲ",
}

local function phonetic(text)
	text = rlower(text)
	-- general phonology
	text = rsub(text, ".", phon)

	-- assimilation (put it outside, not sure if we need it)
--	local i = 0
--	text = rsub(text, "b(ʲ?)$", "p%1")
--	text = rsub(text, "d(ʲ?)$", "t%1")
--	text = rsub(text, "ɣ(ʲ?)$", "k%1")
--	while i <= 5 do
--		text = rsub(text, "b(ʲ?[ptksчӵxfʃ])", "p%1")
--		text = rsub(text, "d(ʲ?[ptksчӵxfʃ])", "t%1")
--		text = rsub(text, "ɡ(ʲ?[ptksчӵxfʃ])", "k%1")
--		text = rsub(text, "z(ʲ?[ptksчӵxfʃ])", "s%1")
--		text = rsub(text, "ʒ(ʲ?[ptksчӵxfʃ])", "ʃ%1")
--		text = rsub(text, "p(ʲ?[bdɡzӟӝʒ])", "b%1")
--		text = rsub(text, "t(ʲ?[bdɡzӟӝʒ])", "d%1")
--		text = rsub(text, "k(ʲ?[bdɡzӟӝʒ])", "ɡ%1")
--		text = rsub(text, "s(ʲ?[bdɡzӟӝʒ])", "z%1")
--		text = rsub(text, "ч(ʲ?[bdɡzӟӝʒ])", "ӟ%1")
--		text = rsub(text, "ʃ(ʲ?[bdɡzӟӝʒ])", "ʒ%1")
--		i = i + 1
--	end
	--special combinations
	text = rsub(text, "əŋ([bβwɣdʒzjklmŋnprstfxʃɕ])", "əŋ%1")
	text = rsub(text, "ʲiŋ^", "jəŋ")
	text = rsub(text, "u([mpb])", "ɞ̝%1")
	text = rsub(text, "ʲu([mpb])", "ʲɞ̝%1")
	text = rsub(text, "uː([mpb])", "ɞ̝ː%1")
	text = rsub(text, "ə([mpb])", "ɞ̝%1")
	text = rsub(text, "nɣ", "ŋ")
	text = rsub(text, "ə̄ɣ", "i̬ɣː")
	
	--consonant easing
	text = rsub(text, "([bβwɣdʒzjklmŋnprstfxʃɕ])pl", "%1pəl")
	text = rsub(text, "w([bɣdʒzklmŋnprstfxʃɕ])([bɣdʒzklmŋnprstfxʃɕ])", "wə%1%2")
	text = rsub(text, "β([bɣdʒzklmŋnprstfxʃɕ])([bɣdʒzklmŋnprstfxʃɕ])", "βə%1%2")
	
	--long vowels
	text = rsub(text, "([a ʲa e ʲe o ʲo ʲu])̄", "%1ː")
	text = rsub(text, "ə̄", "iː")
	
	--long consonants
	text = rsub(text, "ɣɣ", "ɣː")
	text = rsub(text, "jj", "jː")
	text = rsub(text, "kk", "kː")
	text = rsub(text, "ll", "lː")
	text = rsub(text, "mm", "mː")
	text = rsub(text, "nn", "nː")
	text = rsub(text, "ŋŋ", "ŋː")
	text = rsub(text, "pp", "pː")
	text = rsub(text, "rr", "rː")
	text = rsub(text, "ss", "sː")
	text = rsub(text, "tt", "tː")
	text = rsub(text, "ff", "fː")
	text = rsub(text, "xx", "xː")
	text = rsub(text, "ʃʃ", "ʃː")
	text = rsub(text, "ɕɕ", "ɕː")
	
	-- palatalisation
	text = rsub(text, "tʲ", "c")
	text = rsub(text, "sʲ", "ɕ")
	text = rsub(text, "lʲ", "ʎ")
	text = rsub(text, "nʲ", "ɳ")
	text = rsub(text, "^ʲi", "i")
	text = rsub(text, "^ʲ", "j")
	text = rsub(text, "([aeiouə])ʲ", "%1j")
	text = rsub(text, "([ъ])ʲ", "%1j")
	text = rsub(text, "ʲ", "")
	
	-- stress (not yet)
--	if mw.ustring.find(text, "́") == nil then
--		text = rlast(text, "([vowels])", "ˈ%1", 1)
--	else
--		text = rsub(text, "([vowels])́", "ˈ%1")
--	end
--	text = rsub(text, "([consonants])ˈ", "ˈ%1")
--	text = rsub(text, "([palatalized])ːˈ", "%1ˈ%1")
--	text = rsub(text, "^([consonants]ː?[consonants]?ː?)ˈ", "ˈ%1")

	-- affricates
	text = rsub(text, "ц", "t͡s")
	text = rsub(text, "ч", "t͡ɕ")
	
	-- labialized
	text = rsub(text, "kw", "kʷ")
	text = rsub(text, "xw", "xʷ")
	
	-- final adjustments
	text = rsub(text, "ъ", "")
	text = rsub(text, "c", "tʲ")
	text = rsub(text, "ʎ", "lʲ")
	text = rsub(text, "ɳ", "nʲ")
	text = rsub(text, "ə([ɣ])", "ɪ%1")
	text = rsub(text, "^([bwɣdʒzjklmŋnprstfxʃɕ])ə", "%1i")
	text = rsub(text, "^ə([bwɣdʒzjklmŋnprstfxʃɕ])", "i%1")
	text = rsub(text, "ə$", "i")
	text = rsub(text, "ɞ̝m([aeiouə])", "im%1")
	
	text = rsub(text, "g", "ɡ")
	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 = {}
	
	local repl
	
	for _, word in ipairs(words) do
		if mw.ustring.match(word, "в") then
			repl = phonetic(rsub(word, "в", "β"))
			if mw.ustring.match(repl, "kβ") then repl = "" end
			if mw.ustring.match(repl, "xβ") then repl = "" end
			if repl ~= "" then
				table.insert(IPA_results, { pron = "[" .. repl .. "]" })
			end
		end
	end
	
	local repl
	
	for _, word in ipairs(words) do
		if mw.ustring.match(word, "х") then
			repl = phonetic(rsub(word, "х", "χ"))
			if repl ~= "" then
				table.insert(IPA_results, { pron = "[" .. repl .. "]" })
			end
		end
	end
	
	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