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")
} ..
" — " ..
tagIPA(IPA)
end
return export