local export = {}
local m_script_utils = require("Module:script utilities")
local U = mw.ustring.char
local long = "ː"
local nasal = U(0x0303)
local high = U(0x0301)
local low = U(0x0300)
local desc = U(0x0302)
local asc = U(0x030C)
-- single characters that map to IPA sounds (except vowels) (the characters h, l, m, n, w, x and z represent the same sound as in the IPA)
local simple_char = {="ʔ", ="p", ="t", ="k", ="t͡ʃ", ="kʰ", ="ɬ", ="tʰ", ="j" }
local three_char = {="ñ͡ʃf", ="ñ͡ɬf", ="ñ͡sf", }
local multiple_char = { ="ñ͡ʃʰ", ="ñˡ", ="ñ͡s", ="ɣ", ="xʷ", ="qf", ="qʰʷ", ="ʃ", ="ñf", ="ñ͡ɬʰ", ="ñ͡sʰ", ="ʒ"}--ñ and q substitute temporarily t and k.
local simple_oral = {="à", ="á", ="ɛ"..low, ="ɛ"..high, ="ɪ"..low, ="ɪ"..high, ="ò", ="ó"}
local multiple_oral = {="àː", ="áː", ="âː", ="ǎː",
="зː", ="бː", ="вː", ="дː",
="ùː", ="úː", ="ûː", ="ǔː",
="òː", ="óː", ="ôː", ="ǒː"}
local final_c = {="k", ="t", ="ʼ"}--undo the previous substitutions
local final_v= {="ì", ="í", ="î", ="ǐ",
="ê", ="ě", ="é", ="è"}--undo the previous substitutions
local simple_nasal = {="ã"..low, ="ã"..high, ="ẽ"..low, ="ẽ"..high, ="ĩ"..low, ="ĩ"..high, ="õ"..low, ="õ"..high}
local multiple_nasal = {
="ã"..low..long, ="ã"..high..long, ="ã"..desc..long, ="ã"..asc..long,
="ẽ"..low..long, ="ẽ"..high..long, ="ẽ"..desc..long, ="ẽ"..asc..long,
="ĩ"..low..long, ="ĩ"..high..long, ="ĩ"..desc..long, ="ĩ"..asc..long,
="õ"..low..long, ="õ"..high..long, ="õ"..desc..long, ="õ"..asc..long}
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
word = mw.ustring.lower(word)
local phonetic = word
--initial glottal stop
phonetic = mw.ustring.gsub(phonetic, " ()", " ʔ%1")
local sy = mw.text.split(phonetic, "")
if mw.ustring.find(sy, "") then
sy = "ʔ"..sy
end
phonetic = table.concat(sy,"")
--vowels
for pat, repl in pairs(multiple_oral) do
phonetic = mw.ustring.gsub(phonetic, pat, repl)
end
phonetic = mw.ustring.gsub(phonetic, '.', simple_oral)
for pat, repl in pairs(multiple_nasal) do
phonetic = mw.ustring.gsub(phonetic, pat, repl)
end
phonetic = mw.ustring.gsub(phonetic, '.', simple_nasal)
for pat, repl in pairs(final_v) do
phonetic = mw.ustring.gsub(phonetic, pat, repl)
end
--consonants
for pat, repl in pairs(three_char) do
phonetic = mw.ustring.gsub(phonetic, pat, repl)
end
for pat, repl in pairs(multiple_char) do
phonetic = mw.ustring.gsub(phonetic, pat, repl)
end
phonetic = mw.ustring.gsub(phonetic, '.', simple_char)
for pat, repl in pairs(final_c) do
phonetic = mw.ustring.gsub(phonetic, pat, repl)
end
--changes to the notation
phonetic = mw.ustring.gsub(phonetic, 'á', "ɑ"..high)
phonetic = mw.ustring.gsub(phonetic, 'à', "ɑ"..low)
phonetic = mw.ustring.gsub(phonetic, 'â', "ɑ"..desc)
phonetic = mw.ustring.gsub(phonetic, 'ǎ', "ɑ"..asc)
phonetic = mw.ustring.gsub(phonetic, 'a', "ɑ")
phonetic = mw.ustring.gsub(phonetic, 'ã', "ɑ"..nasal)
return phonetic
end
return export