Module:User:Stríðsdrengur/mhr-IPA

local export = {}

local m_IPA = require("Module:IPA") local lang = require("Module:languages").getByCode("mhr")

-- single characters that map to IPA sounds local phonetic_chars_map = { ["а"] = "ɑ", ["е"] = "e", ["э"] = "e", ["и"] = "i", ["о"] = "o", ["у"] = "u", ["ю"] = "ʲu", ["ы"] = "ə", ["я"] = "ʲɑ", ["б"] = "b", ["в"] = "v", ["г"] = "ɡ", ["д"] = "d", ["ж"] = "ʒ", ["з"] = "z", ["й"] = "j", ["к"] = "k", ["л"] = "l", ["м"] = "m", ["н"] = "n", ["п"] = "p", ["р"] = "ɾ", ["с"] = "s", ["т"] = "t", ["ф"] = "f", ["х"] = "x", ["ц"] = "t͡s", ["ч"] = "t͡ɕ", ["ш"] = "ʃ", ["щ"] = "ɕː", ["ҥ"] = "ŋ", }

-- character sequences of two that map to IPA sounds local phonetic_2chars_map = { ["ль"] = "lʲ", ["нь"] = "nʲ", ["дь"] = "dʲ", }

function export.to_IPA(word) word = mw.ustring.lower(word)

local phonetic = word

for pat, repl in pairs(phonetic_2chars_map) do		phonetic = phonetic:gsub(pat, repl) end

phonetic = mw.ustring.gsub(phonetic, '.', phonetic_chars_map)

-- handle unstressed syllabic sonorants in loanwords phonetic = mw.ustring.gsub(phonetic, "%f[%a%-]([rlʎmnɲ])([bʋgdʒzkmnɲpstfxʃɕʑ])", "%1̩%2") phonetic = mw.ustring.gsub(phonetic, "([bʋgdʒzkmnɲpstfxʃɕʑ])([rlʎmnɲ])([bʋgdʒzkmnɲpstfxʃɕʑ])", "%1%2̩%3") phonetic = mw.ustring.gsub(phonetic, "([bʋgdʒzkmnɲpstfxʃɕʑ])([rlʎmnɲ])%f[%A]", "%1%2̩") phonetic = mw.ustring.gsub(phonetic, "̩̩", "̩")

-- enable use of an apostrophe to keep letters from forming digraphs, e.g. nad'žívjeti phonetic = mw.ustring.gsub(phonetic, "'", "")

return "/" .. phonetic .. "/" end

function export.pronunciation(word) if type(word) == "table" then word = word.args[1] or word:getParent.args[1] end if not word or (word == "") then error("Please put the word as the first positional parameter!") end local items = {} table.insert(items, {pron = export.to_IPA(word), note = nil}) return m_IPA.format_IPA_full { lang = lang, items = items } end

return export