Module:User:Erutuon/ru-pronunciation

Hello, you have come here looking for the meaning of the word Module:User:Erutuon/ru-pronunciation. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:User:Erutuon/ru-pronunciation, but we will also tell you about its etymology, its characteristics and you will know how to say Module:User:Erutuon/ru-pronunciation in singular and plural. Everything you need to know about the word Module:User:Erutuon/ru-pronunciation you have here. The definition of the word Module:User:Erutuon/ru-pronunciation will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:User:Erutuon/ru-pronunciation, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

Testcases


local export = {}

local match = mw.ustring.match
local gsub = mw.ustring.gsub

local U = mw.ustring.char
local tie = U(0x361)
local acute = U(0x301)
local long = "ː"
local stress = "ˈ"

local correspondences = {
	 = "a",
	 = "b",
	 = "v",
	 = "g",
	 = "d",
	 = "ʲe",
	 = "ʲo",
	 = "ʐ",
	 = "z",
	 = "ʲi",
	 = "j",
	 = "k",
	 = "l",
	 = "m",
	 = "n",
	 = "o",
	 = "p",
	 = "r",
	 = "s",
	 = "t",
	 = "u",
	 = "f",
	 = "x",
	 = "t" .. tie .. "s",
	 = "t" .. tie .. "ɕ",
	 = "ʂ",
	 = "ɕ" .. long,
	 = "'",
	 = "ɨ",
	 = "ʲ",
	 = "e",
	 = "ʲu",
	 = "ʲa",
	 = stress,
}

local function tagIPA(IPA)
	return '<span class="IPA">/' .. IPA .. '/</span>'
end

function export.toIPA(word)
	local hasStress = match(word, acute)
	
	IPA = gsub(
		word,
		".",
		function(letter)
			return correspondences or letter
		end
	)
	
	local vowels = "aeiɨou"
	local vowel = ""
	
	IPA = gsub(IPA, "()ʲ", "%1j")
	
	IPA = gsub(IPA, "()ʲ", "%1")
	IPA = gsub(IPA, "(t" .. tie .. "s)ʲ", "%1")
	
	IPA = gsub(IPA, "()i", "%1ɨ")
	IPA = gsub(IPA, "(t" .. tie .. "s)i", "%1ɨ")
	
	-- Reduce vowels.
	local reduction = {
		 = "ɨ",
		 = "a",
	}
	local iotated_reduction = {
		 = "i",
		 = "i",
		 = "a",
	}
	
	if hasStress then
		local palatalization = "?" .. long .. "?"
		
		IPA = gsub(
			IPA,
			"^(" .. vowel .. ")()",
			function (vowel, nextCharacter)
				return ( reduction or vowel ) .. nextCharacter
			end
		)
		IPA = gsub(
			IPA,
			"(" .. palatalization .. ")(" .. vowel .. ")()",
			function (palatalization, vowel, nextCharacter)
				mw.log(word, palatalization, vowel, nextCharacter)
				if palatalization == "" then
					return ( reduction or vowel ) .. nextCharacter
				else
					return palatalization .. ( iotated_reduction or vowel ) .. nextCharacter
				end
			end
		)
		IPA = gsub(
			IPA,
			"(" .. palatalization .. ")(" .. vowel .. ")$",
			function (palatalization, vowel)
				if vowel ~= "e" then
					if palatalization == "" then
						return ( reduction or vowel )
					else
						return palatalization .. ( iotated_reduction or vowel )
					end
				end
			end
		)
	end
	
	-- Move stress mark before vowel.
	IPA = gsub(IPA, "()" .. stress, stress .. "%1")
	
	-- Move stress mark before consonants.
	while match(IPA, "" .. stress) do
		IPA = gsub(IPA, "()" .. stress, stress .. "%1")
	end
	
	return IPA
end

function export.IPA(frame)
	local params = {
		 = {},
	}
	
	local args = require("Module:parameters").process(frame.args, params)
	
	local IPA = export.toIPA(args)
	
	return require("Module:links").full_link
		{
			term = args,
			lang = require("Module:languages").getByCode("ru"),
			sc = require("Module:scripts").getByCode("Cyrl")
		} ..
		" &mdash; " ..
		tagIPA(IPA)
end

return export