မာတိကာသို့ ခုန်သွားရန်

မဝ်ဂျူ:csb-IPA

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

local export = {}

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

local F = "[eɛi]"
local C = "[bdfɡxjklwmnprstvzʒʃŋɲɕʑʲ]"
local V = "[aõãɛeɜɔoɞu]"
local Vi = "[aõãɛeɜɔoɞui]"
local T = "[ptsʃɕkx]"
local D = "[bdzʒʑɡ]"

local di = {
	["ch"]="x",	["cz"]="tʃ", ["rz"]="r̝", ["sz"]="ʃ",
}

local phon = {
	["a"]="a",	["ą"]="õ",	["ã"]="ã",	["b"]="b",
	["c"]="ts", ["d"]="d",	["e"]="ɛ",	["é"]="e",
	["ë"]="ɜ",	["f"]="f",	["g"]="ɡ",	["h"]="x",
	["i"]="i",	["j"]="j",	["k"]="k",	["l"]="l",
	["ł"]="w",	["m"]="m",	["n"]="n",	["ń"]="ɲ",
	["o"]="ɔ",	["ò"]="wɛ",	["ó"]="o",	["ô"]="ɞ",
	["p"]="p",	["r"]="r",	["s"]="s",	["t"]="t",
	["u"]="u",	["ù"]="wu",	["w"]="v",	["y"]="I",
	["z"]="z",	["ż"]="ʒ",
}

local function phonemic(text)
	text = rlower(text)
	-- basic phonology
	text = rsub(text, "ts", "tss")
	text = rsub(text, "..", di)
	text = rsub("1" .. text, "..", di)
	text = rsub("1" .. text, "..", di)
	text = rsub(text, "1", "")
	text = rsub(text, ".", phon)
	text = rsub(text, "n([kɡx])", "ŋ%1")
	text = rsub(text, "([kɡxvfpbm])o", "%1wo")
	text = rsub(text, "vw", "w")
	-- palatalisation
	text = rsub(text, "(" .. C .. ")i(" .. V .. ")", "%1j%2")
	text = rsub(text, "r̝i(" .. V .. ")", "r̝j%2")
	text = rsub(text, "(" .. C .. ")(" .. F .. ")", "%1ʲ%2")
	text = rsub(text, "r̝(" .. F .. ")", "r̝ʲ%1")
	text = rsub(text, "nʲ", "ɲ")
	text = rsub(text, "nj", "ɲ")
	text = rsub(text, "ʃʲ", "ɕ")
	text = rsub(text, "ʒʲ", "ʑ")
	text = rsub(text, "jʲ", "j")
	text = rsub(text, "I", "i")
	-- voicing
	text = rsub(text, "b$", "p")
	text = rsub(text, "d$", "t")
	text = rsub(text, "ɡ$", "k")
	text = rsub(text, "z$", "s")
	text = rsub(text, "v$", "f")
	text = rsub(text, "ʒ$", "ʃ")
	text = rsub(text, "ʑ$", "ɕ")
	text = rsub(text, "br̝$", "pr̝")
	text = rsub(text, "dr̝$", "tr̝")
	text = rsub(text, "ɡr̝$", "kr̝")
	text = rsub(text, "zr̝$", "sr̝")
	text = rsub(text, "vr̝$", "fr̝")
	text = rsub(text, "ʒr̝$", "ʃr̝")
	text = rsub(text, "ʑr̝$", "ɕr̝")
	text = rsub(text, "r̝$", "r̝̊")
	local i = 0
	while i <= 5 do
		text = rsub(text, "b(" .. T .. ")", "p%1")
		text = rsub(text, "d(" .. T .. ")", "t%1")
		text = rsub(text, "ɡ(" .. T .. ")", "k%1")
		text = rsub(text, "z(" .. T .. ")", "s%1")
		text = rsub(text, "v(" .. T .. ")", "f%1")
		text = rsub(text, "ʒ(" .. T .. ")", "ʃ%1")
		text = rsub(text, "ʑ(" .. T .. ")", "ɕ%1")
		text = rsub(text, "p(" .. D .. ")", "b%1")
		text = rsub(text, "t(" .. D .. ")", "d%1")
		text = rsub(text, "k(" .. D .. ")", "ɡ%1")
		text = rsub(text, "s(" .. D .. ")", "z%1")
		text = rsub(text, "f(" .. D .. ")", "v%1")
		text = rsub(text, "ʃ(" .. D .. ")", "ʒ%1")
		text = rsub(text, "ɕ(" .. D .. ")", "ʑ%1")
		i = i + 1
	end
	text = rsub(text, "(" .. T .. ")v", "%1f")
	text = rsub(text, "(" .. T .. ")r̝", "%1r̝̊") 
	-- stress
	if mw.ustring.find(text, "'") == nil then
		text = "ˈ" .. text
	end
	text = rsub(text, "(" .. Vi .. ")'", "'%1")
	text = rsub(text, "^(" .. C .. "+ʲ?)'", "'%1")
	text = rsub(text, " (" .. C .. "+ʲ?)'", " '%1")
	text = rsub(text, "(" .. C .. "ʲ?)'", "'%1")
	text = rsub(text, "t's", "'ts")
	text = rsub(text, "'", "ˈ")
	-- affricates
	text = rsub(text, "t([sɕʃ])", "t͡%1")
	text = rsub(text, "d([zʑʒ])", "d͡%1")
	-- suffixes
	text = rsub(text, "^ˈ%-", "-")
	-- resolution
	text = rsub(text, "wʲ", "w")
	text = rsub(text, "jʲ", "j")
	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 = "/" .. phonemic(word) .. "/" })
	end
	
	return m_IPA.format_IPA_full(lang, IPA_results)
end

return export