local export = {}
local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("sh")
-- single characters that map to IPA sounds
local phonetic_chars_map = {
= "a", = "a",
= "e", = "e",
= "i", = "i",
= "o", = "o",
= "u", = "u",
= "b", = "b",
= "ʋ", = "ʋ",
= "ɡ", = "ɡ",
= "d", = "d",
= "d͡ʑ", = "d͡ʑ",
= "ʒ", = "ʒ",
= "z", = "z",
= "j", = "j",
= "k", = "k",
= "l", = "l",
= "ʎ",
= "m", = "m",
= "n", = "n",
= "ɲ",
= "p", = "p",
= "r", = "r",
= "s", = "s",
= "t", = "t",
= "t͡ɕ", = "t͡ɕ",
= "f", = "f",
= "x", = "x",
= "t͡s", = "t͡s",
= "t͡ʃ", = "t͡ʃ",
= "d͡ʒ",
= "ʃ", = "ʃ",
= "ɕ",
= "ʑ",
= "ə", = "ə",
= "dz",
= "",
= "ː",
= "ˇ",
= "ǎː", = "ǎ", = "aː", = "â", = "âː",
= "ěː", = "ě", = "eː", = "ê", = "êː",
= "ǐː", = "ǐ", = "iː", = "î", = "îː",
= "ǒː", = "ǒ", = "oː", = "ô", = "ôː",
= "ǔː", = "ǔ", = "uː", = "û", = "ûː",
= "ř̩ː", = "r̩̂", = "r̩̂ː",
= "ˆ",
= "ˆː",
}
-- character sequences of two that map to IPA sounds
local phonetic_2chars_map = {
= "ʎ",
= "ɲ",
= "d͡ʒ",
= "ɕ",
= "ʑ",
= "ǎː", = "ǎ", = "aː", = "â", = "âː",
= "ěː", = "ě", = "eː", = "ê", = "êː",
= "ǐː", = "ǐ", = "iː", = "î", = "îː",
= "ǒː", = "ǒ", = "oː", = "ô", = "ôː",
= "ǔː", = "ǔ", = "uː", = "û", = "ûː",
= "ř̩", = "r̩ː",
= "ř̩ː", = "ř̩", = "r̩ː", = "r̩̂", = "r̩̂ː",
}
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()()", "%1̩%2")
phonetic = mw.ustring.gsub(phonetic, "()()()", "%1%2̩%3")
phonetic = mw.ustring.gsub(phonetic, "()()%f", "%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 or word:getParent().args
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