--This code is borrowed and expanded from ] made by ], 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 rfind = mw.ustring.find
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, ",", " |")
text = rsub(text, " | ", "# | #")
text = "#" .. rsub(text, " ", "# #") .. "#"
text = rsub(text, ".", phon)
--special combinations
text = rsub(text, "ъə", "i")
text = rsub(text, "əŋ()", "əŋ%1")
text = rsub(text, "()ʲiŋ", "%1ʲəŋ")
text = rsub(text, "#ʲiŋ", "#jəŋ")
text = rsub(text, "u()", "ɞ%1")
text = rsub(text, "ʲu()", "ʲɞ%1")
text = rsub(text, "uː()", "ɞː%1")
text = rsub(text, "ə()", "ɞ%1")
text = rsub(text, "ə̄ɣ", "ɨːɣ")
--consonant easing
text = rsub(text, "()pl", "%1pəl")
text = rsub(text, "()()()", "%1ə%2%3")
-- palatalisation
text = rsub(text, "ʲ()", "ʲə%1")
text = rsub(text, "ʲʲ", "ʲj")
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, "()ʲ", "%1j")
text = rsub(text, "ʲ", "")
--long vowels
text = rsub(text, "(ʲ?)̄", "%1ː")
text = rsub(text, "ə̄", "iː")
--long consonants
text = rsub(text, "()%1", "%1ː")
-- affricates
text = rsub(text, "ц", "ts")
text = rsub(text, "ч", "tɕ")
text = rsub(text, "kw", "kʷ")
text = rsub(text, "xw", "xʷ")
-- final adjustments
text = rsub(text, "ъ", "")
text = rsub(text, "ə()", "ɪ%1")
text = rsub(text, "()(ʷ?)ə", "%1%2i")
text = rsub(text, "()ə(ʷ?)", "%1i%2")
text = rsub(text, "ə()", "i%1")
text = rsub(text, "ɞm()", "im%1")
text = rsub(text, "ɞː()(ʷ?)", "uː%1%2")
--stress
text = rsub(text, "-", "ˌ")
text = rsub(text, "#()", "#ˈ%1")
text = rsub(text, "(*ː?*ː?*)()", "%1ˌ%2")
text = rsub(text, "(*ː?*ː?*)()", "%1ˌ%2")
text = rsub(text, "(*ː?*ː?*)()", "%1ˌ%2")
text = rsub(text, "(ː?*)(ʷ?)ˌ()", "%1ˌ%2%3")
text = rsub(text, "(ʷ?)ˌː", "%1ˌ%1")
if rfind(text, "ˌ#?$") ~= nil then
text = rsub(text, "", "")
end
if rfind(text, "^#?ˌ") ~= nil then
text = rsub(text, "", "")
end
-- really final
text = rsub(text, "ɞ", "ɞ̝")
text = rsub(text, "ts", "t͡s")
text = rsub(text, "tɕ", "t͡ɕ")
text = rsub(text, "tc", "tʲː")
text = rsub(text, "lʎ", "lʲː")
text = rsub(text, "nɲ", "nʲː")
text = rsub(text, "c", "tʲ")
text = rsub(text, "ʎ", "lʲ")
text = rsub(text, "ɲ", "nʲ")
text = rsub(text, "#", "")
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 = "" })
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 = "" })
end
end
end
for _, word in ipairs(words) do
table.insert(IPA_results, { pron = "" })
end
return m_IPA.format_IPA_full { lang = lang, items = IPA_results }
end
return export