Jump to content

Module:ii-pron

From Wiktionary, the free dictionary

This module is experimental.
The details of its operation have not yet been fully decided upon. Do not deploy widely until the module is finished.

Pronunciation module for Nuosu. See {{ii-pron}}.


local export = {}
local translit = require("Module:ii-translit")
local gsub = mw.ustring.gsub
local find = mw.ustring.find

local convert_initial = {
	["b"] = "p", ["p"] = "pʰ", ["bb"] = "b", ["nb"] = "mb",
	["hm"] = "m̥", ["m"] = "m", ["f"] = "f", ["v"] = "v",
	["d"] = "t", ["t"] = "tʰ", ["dd"] = "d", ["nd"] = "nd",
	["hn"] = "n̥", ["n"] = "n", ["hl"] = "ɬ", ["l"] = "l",
	["j"] = "tɕ", ["q"] = "tɕʰ", ["jj"] = "dʑ", ["nj"] = "ndʑ",
	["ny"] = "n̠ʲ", ["x"] = "ɕj", ["y"] = "ʑ",
	["g"] = "k", ["k"] = "kʰ", ["gg"] = "ɡ", ["mg"] = "ŋɡ",
	["hx"] = "h", ["ng"] = "ŋ", ["h"] = "x", ["w"] = "ɣ",
	["z"] = "ts", ["c"] = "tsʰ", ["zz"] = "dz",
	["nz"] = "ndz", ["s"] = "s", ["ss"] = "z",
	["zh"] = "tʂ", ["ch"] = "tʂʰ", ["rr"] = "dʐ",
	["nr"] = "ndʐ", ["sh"] = "ʂ", ["r"] = "ʐ", [""] = "",
}

local convert_final = {
	["i"] = "i", ["ie"] = "ɛ", ["a"] = "a",
	["y"] = "z̩", ["yr"] = "z̩̱", ["e"] = "ɯ",
	["Y"] = "ʐ̩", ["Yr"] = "ʐ̩̱",
	["u"] = "u", ["ur"] = "u̱", ["o"] = "o", ["uo"] = "ɔ",
}

local convert_tone = {
	["t"] = "˥˥", ["x"] = "˧˦", [""] = "˧˧", ["p"] = "˨˩"
}

function export.ipa(text)
	text = string.lower(translit.tr(text))
	local syllables = mw.text.split(text, " ")
	for i, syllable in ipairs(syllables) do
		if syllable == "w" then
			syllables[i] = syllables[i-1]
		else
			local initial, final, tone = syllable:match("([bcdfghjklmnpqrstvwxyz]?[bdghjlmnrsxyz]?)([aeiouy][eor]?)([txp]?)$")
			if (find(initial, "[zcs]h") or find(initial, "r")) and find(final, "^yr?$") then
				final = gsub(final, "y", "Y")
			end
			syllables[i] = convert_initial[initial] .. convert_final[final] .. convert_tone[tone]
		end
	end
	
	return table.concat(syllables, " ")
end

return export