local export = {}
local PAGENAME = mw.title.getCurrentTitle().text
local m_IPA = require("Module:IPA")
local m_a = require("Module:accent qualifier")
local lang = require("Module:languages").getByCode("car")
-- single characters that map to IPA sounds
local phonetic_chars_map = {
= "a",
= "aʔ",
= "aː",
= "aːʔ",
= "e",
= "eʔ",
= "eː",
= "eːʔ",
= "i",
= "iʔ",
= "iː",
= "iːʔ",
= "j",
= "k",
= "ʔ",
= "m",
= "n",
= "o",
= "oʔ",
= "oː",
= "oːʔ",
= "p",
= "ɽ",
= "s",
= "t",
= "u",
= "uʔ",
= "uː",
= "uːʔ",
= "w",
= "ɨ",
= "ɨʔ",
= "ɨː",
= "ɨːʔ",
= "b",
= "d",
= "f",
= "ɡ",
}
-- character sequences of two that map to IPA sounds
local phonetic_2chars_map = {
= "ʃ",
}
function export.to_base_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)
-- unwritten glottal stop
phonetic = mw.ustring.gsub(phonetic, "(ː?)(ː?)ʔ", "%1ʔ%2ʔ")
-- vowel lengthening/stress
phonetic = mw.ustring.gsub(phonetic, "()", "N%1")
phonetic = mw.ustring.gsub(phonetic, "%f", "N")
phonetic = mw.ustring.gsub(phonetic, "()i", "%1J")
phonetic = mw.ustring.gsub(phonetic, "()ɨ", "%1Y")
phonetic = mw.ustring.gsub(phonetic, "()u", "%1W")
phonetic = mw.ustring.gsub(phonetic, "%f(p?t?k?b?d?ɡ?f?s?ʃ?m?n?ɽ?j?w?)()", "%1ː%2")
phonetic = mw.ustring.gsub(phonetic, "%f(p?t?k?b?d?ɡ?f?s?ʃ?m?n?ɽ?j?w?p?t?k?b?d?ɡ?f?s?ʃ?m?n?ɽ?j?w?)", "%1ː")
phonetic = mw.ustring.gsub(phonetic, "%f(p?t?k?b?d?ɡ?f?s?ʃ?m?n?ɽ?j?w?)(p?t?k?b?d?ɡ?f?s?ʃ?m?n?ɽ?j?w?)ː(ʔ?J?Y?W?N?)%f", "%1ː%2%3")
phonetic = mw.ustring.gsub(phonetic, "ː(ʔ?J?Y?W?N?p?t?k?b?d?ɡ?f?s?ʃ?m?n?ɽ?j?w?ʔ?J?Y?W?N?p?t?k?b?d?ɡ?f?s?ʃ?m?n?ɽ?j?w?)", "ː%1ː")
phonetic = mw.ustring.gsub(phonetic, "ː(ʔ?J?Y?W?N?p?t?k?b?d?ɡ?f?s?ʃ?m?n?ɽ?j?w?ʔ?J?Y?W?N?p?t?k?b?d?ɡ?f?s?ʃ?m?n?ɽ?j?w?)()", "ː%1ː%2")
phonetic = mw.ustring.gsub(phonetic, "ː(ʔ?J?Y?W?N?p?t?k?b?d?ɡ?f?s?ʃ?m?n?ɽ?j?w?ʔ?J?Y?W?N?p?t?k?b?d?ɡ?f?s?ʃ?m?n?ɽ?j?w?)()", "ː%1ː%2")
phonetic = mw.ustring.gsub(phonetic, "ː(ʔ?J?Y?W?N?p?t?k?b?d?ɡ?f?s?ʃ?m?n?ɽ?j?w?ʔ?J?Y?W?N?p?t?k?b?d?ɡ?f?s?ʃ?m?n?ɽ?j?w?)()", "ː%1ː%2")
phonetic = mw.ustring.gsub(phonetic, "ː(ʔ?J?Y?W?N?p?t?k?b?d?ɡ?f?s?ʃ?m?n?ɽ?j?w?ʔ?J?Y?W?N?p?t?k?b?d?ɡ?f?s?ʃ?m?n?ɽ?j?w?)()", "ː%1ː%2")
phonetic = mw.ustring.gsub(phonetic, "()ː()", "%1%2")
phonetic = mw.ustring.gsub(phonetic, "()ː%f", "%1")
phonetic = mw.ustring.gsub(phonetic, "J", "i")
phonetic = mw.ustring.gsub(phonetic, "Y", "ɨ")
phonetic = mw.ustring.gsub(phonetic, "W", "u")
-- palatalization
phonetic = mw.ustring.gsub(phonetic, "(iː?ʔ?N?)p()", "%1pʲ%2")
phonetic = mw.ustring.gsub(phonetic, "(iː?ʔ?N?)t()", "%1tʲ%2")
phonetic = mw.ustring.gsub(phonetic, "(iː?ʔ?N?)k()", "%1kʲ%2")
phonetic = mw.ustring.gsub(phonetic, "(iː?ʔ?N?)b()", "%1bʲ%2")
phonetic = mw.ustring.gsub(phonetic, "(iː?ʔ?N?)d()", "%1dʲ%2")
phonetic = mw.ustring.gsub(phonetic, "(iː?ʔ?N?)ɡ()", "%1ɡʲ%2")
phonetic = mw.ustring.gsub(phonetic, "(iː?ʔ?N?)s()", "%1ʃ%2")
phonetic = mw.ustring.gsub(phonetic, "si", "ʃi")
phonetic = mw.ustring.gsub(phonetic, "(iː?ʔ?N?)ʃi", "%1si")
phonetic = mw.ustring.gsub(phonetic, "(ː?ʔ?N?)ɽ", "%1ɾ")
phonetic = mw.ustring.gsub(phonetic, "(iː?ʔ?N?)m()", "%1mʲ%2")
phonetic = mw.ustring.gsub(phonetic, "(iː?ʔ?N?)n()", "%1ɲ%2")
-- glottal allophones
phonetic = mw.ustring.gsub(phonetic, "ʔ()", "h%1")
-- nasals
phonetic = mw.ustring.gsub(phonetic, "N()", "ɲ%1")
phonetic = mw.ustring.gsub(phonetic, "N()", "ŋ%1")
phonetic = mw.ustring.gsub(phonetic, "N()", "m%1")
phonetic = mw.ustring.gsub(phonetic, "N()", "n%1") -- not sure about s/ʃ, they might require ŋ rather than n
phonetic = mw.ustring.gsub(phonetic, "N", "n")
phonetic = mw.ustring.gsub(phonetic, "aN%f", "ã")
phonetic = mw.ustring.gsub(phonetic, "eN%f", "ẽ")
phonetic = mw.ustring.gsub(phonetic, "iN%f", "iɲ")
phonetic = mw.ustring.gsub(phonetic, "oN%f", "õ")
phonetic = mw.ustring.gsub(phonetic, "uN%f", "ũ")
phonetic = mw.ustring.gsub(phonetic, "ɨN%f", "ɨ̃")
phonetic = mw.ustring.gsub(phonetic, "N", "ŋ")
return phonetic
end
function export.finalize_IPA(word)
local phonetic = word
-- diphthong offglides
phonetic = mw.ustring.gsub(phonetic, "()i", "%1j")
phonetic = mw.ustring.gsub(phonetic, "()ɨ", "%1ɰ")
phonetic = mw.ustring.gsub(phonetic, "()u", "%1w")
-- unpronounced/indistinct w and j in certain environments
phonetic = mw.ustring.gsub(phonetic, "(.)u", "%1u")
phonetic = mw.ustring.gsub(phonetic, "(ː?)e", "%1e")
-- notation
phonetic = mw.ustring.gsub(phonetic, "ɽ", "ɺ̢")
return phonetic
end
function export.to_IPA(word)
local phonetic = export.to_base_IPA(word)
-- non-phonemic vowel loss
phonetic = mw.ustring.gsub(phonetic, "%fɨ()", "%1")
phonetic = mw.ustring.gsub(phonetic, "%fi()", "%1")
phonetic = mw.ustring.gsub(phonetic, "m()%f", "m(%1)")
phonetic = export.finalize_IPA(phonetic)
return ""
end
function export.to_Venezuelan_IPA(word)
local phonetic = word
-- basic phonetic differences
phonetic = mw.ustring.gsub(phonetic, "j", "ð")
phonetic = mw.ustring.gsub(phonetic, "w", "β")
-- palatalization
phonetic = mw.ustring.gsub(phonetic, "tʲ", "tʃ")
phonetic = mw.ustring.gsub(phonetic, "ŋkʲ", "nʃ")
phonetic = mw.ustring.gsub(phonetic, "kʲ", "ʃ")
phonetic = mw.ustring.gsub(phonetic, "(iː?ʔ?h?)ɾ()", "%1j%2")
phonetic = mw.ustring.gsub(phonetic, "(iː?ʔ?h?ɲ?)ð()", "%1j%2")
phonetic = mw.ustring.gsub(phonetic, "(iː?ʔ?h?ŋ?)β()", "%1βʲ%2")
-- fleeting ɰ/u
phonetic = mw.ustring.gsub(phonetic, "(ː?m?)()", "%1w%2")
phonetic = mw.ustring.gsub(phonetic, "(ɨː?ʔ?m?)m()", "%1mɰ%2")
phonetic = mw.ustring.gsub(phonetic, "(uː?ʔ?m?)m()", "%1mw%2")
phonetic = mw.ustring.gsub(phonetic, "%f(ɨː?ʔ?h?n?ŋ?)()", "%1ɰ%2")
phonetic = mw.ustring.gsub(phonetic, "(ɨː?ʔ?)ɽ()", "%1ɽɰ%2") -- not fully accurate; I haven’t succeeded in determining the full conditions of the actual rule
phonetic = mw.ustring.gsub(phonetic, "(ɨː?ʔ?)ɽã", "%1ɽɰã") -- continued
phonetic = mw.ustring.gsub(phonetic, "(ː?ʔ?m?n?ɲ?ŋ?)β()", "%1w%2")
-- nasals
phonetic = mw.ustring.gsub(phonetic, "ɲ", "ɲɲ")
-- coalescence
phonetic = mw.ustring.gsub(phonetic, "hpʲ?", "h")
phonetic = mw.ustring.gsub(phonetic, "ɨi%f", "i")
-- non-phonemic vowel loss
phonetic = mw.ustring.gsub(phonetic, "%fɨ()", "%1")
phonetic = mw.ustring.gsub(phonetic, "%fi()", "%1")
phonetic = mw.ustring.gsub(phonetic, "m()%f", "m(%1)")
-- different treatment of long high vowels
phonetic = mw.ustring.gsub(phonetic, "()ːp", "%1pp")
phonetic = mw.ustring.gsub(phonetic, "()ːt", "%1tt")
phonetic = mw.ustring.gsub(phonetic, "()ːtʃ", "%1ttʃ")
phonetic = mw.ustring.gsub(phonetic, "()ːk", "%1kk")
phonetic = mw.ustring.gsub(phonetic, "()ːb", "%1bb")
phonetic = mw.ustring.gsub(phonetic, "()ːd", "%1dd")
phonetic = mw.ustring.gsub(phonetic, "()ːɡ", "%1ɡɡ")
phonetic = mw.ustring.gsub(phonetic, "()ːf", "%1hf")
phonetic = mw.ustring.gsub(phonetic, "()ːs", "%1hs")
phonetic = mw.ustring.gsub(phonetic, "()ːʃ", "%1hʃ")
phonetic = mw.ustring.gsub(phonetic, "()ːm", "%1mm")
phonetic = mw.ustring.gsub(phonetic, "()ːn", "%1nn")
phonetic = mw.ustring.gsub(phonetic, "()ːɲ", "%1ɲɲ")
phonetic = mw.ustring.gsub(phonetic, "()ːŋ", "%1ŋŋ")
phonetic = mw.ustring.gsub(phonetic, "()ːj", "%1jj")
phonetic = mw.ustring.gsub(phonetic, "()ːð", "%1ðð")
phonetic = mw.ustring.gsub(phonetic, "()ːw", "%1ww")
phonetic = mw.ustring.gsub(phonetic, "()ːβ", "%1ββ")
-- coalescence of palatalizing diphthongs
phonetic = mw.ustring.gsub(phonetic, "()ipʲ", "%1ppʲ")
phonetic = mw.ustring.gsub(phonetic, "()itʃ", "%1ttʃ")
phonetic = mw.ustring.gsub(phonetic, "()iʃ", "%1hʃ")
phonetic = mw.ustring.gsub(phonetic, "()ibʲ", "%1bbʲ")
phonetic = mw.ustring.gsub(phonetic, "()idʲ", "%1ddʲ")
phonetic = mw.ustring.gsub(phonetic, "()iɡʲ", "%1ɡɡʲ")
phonetic = mw.ustring.gsub(phonetic, "()imʲ", "%1mmʲ")
phonetic = mw.ustring.gsub(phonetic, "()iɲ", "%1ɲɲ")
phonetic = mw.ustring.gsub(phonetic, "()ij", "%1jj")
phonetic = export.finalize_IPA(phonetic)
return ""
end
function export.to_West_Surinamese_IPA(word)
local phonetic = word
-- voicing
phonetic = mw.ustring.gsub(phonetic, "()p", "%1b")
phonetic = mw.ustring.gsub(phonetic, "()t", "%1d")
phonetic = mw.ustring.gsub(phonetic, "()k", "%1ɡ")
-- palatalization
phonetic = mw.ustring.gsub(phonetic, "kʲ", "c")
phonetic = mw.ustring.gsub(phonetic, "ŋɡʲ", "ɲɟ")
phonetic = mw.ustring.gsub(phonetic, "ɡʲ", "ɟ")
phonetic = mw.ustring.gsub(phonetic, "(i)ɲ()", "%1j%2")
phonetic = mw.ustring.gsub(phonetic, "(i)ɾ()", "%1dʝ%2")
phonetic = mw.ustring.gsub(phonetic, "%f(iː?ʔ?h?)ɾ()", "%1dʝ%2")
phonetic = mw.ustring.gsub(phonetic, "(i)j()", "%1ʝ%2")
phonetic = mw.ustring.gsub(phonetic, "%f(iː?ʔ?h?ɲ?)j()", "%1ʝ%2")
phonetic = mw.ustring.gsub(phonetic, "(iː?ʔ?h?ŋ?)w()", "%1ɥ%2")
-- allophone of w
phonetic = mw.ustring.gsub(phonetic, "w", "ʋ")
phonetic = mw.ustring.gsub(phonetic, "(uː?ʔ?h?ŋ?)ʋ", "%1w")
-- nasals
phonetic = mw.ustring.gsub(phonetic, "ɲ", "jj")
-- non-phonemic vowel loss
phonetic = mw.ustring.gsub(phonetic, "%fɨ()", "%1")
phonetic = mw.ustring.gsub(phonetic, "%fi()", "%1")
phonetic = mw.ustring.gsub(phonetic, "m()%f", "m(%1)")
phonetic = export.finalize_IPA(phonetic)
return ""
end
function export.to_East_Surinamese_IPA(word)
local phonetic = word
-- palatalization
phonetic = mw.ustring.gsub(phonetic, "tʲ", "c")
phonetic = mw.ustring.gsub(phonetic, "kʲ", "c")
phonetic = mw.ustring.gsub(phonetic, "dʲ", "ɟ")
phonetic = mw.ustring.gsub(phonetic, "ɡʲ", "ɟ")
phonetic = mw.ustring.gsub(phonetic, "ŋ()", "ɲ%1")
-- voicing
phonetic = mw.ustring.gsub(phonetic, "()i", "%1J")
phonetic = mw.ustring.gsub(phonetic, "()ɨ", "%1Y")
phonetic = mw.ustring.gsub(phonetic, "()u", "%1W")
phonetic = mw.ustring.gsub(phonetic, "()p", "%1b")
phonetic = mw.ustring.gsub(phonetic, "()t", "%1d")
phonetic = mw.ustring.gsub(phonetic, "()c", "%1ɟ")
phonetic = mw.ustring.gsub(phonetic, "()k", "%1ɡ")
phonetic = mw.ustring.gsub(phonetic, "J", "i")
phonetic = mw.ustring.gsub(phonetic, "Y", "ɨ")
phonetic = mw.ustring.gsub(phonetic, "W", "u")
-- nasals
phonetic = mw.ustring.gsub(phonetic, "ɲj", "jj")
-- coalescence
phonetic = mw.ustring.gsub(phonetic, "%fʃiʃ", "ʃː")
phonetic = mw.ustring.gsub(phonetic, "%fʃi()", "ʃ%1")
phonetic = mw.ustring.gsub(phonetic, "ʃb", "ʃp")
phonetic = mw.ustring.gsub(phonetic, "ʃd", "ʃt")
phonetic = mw.ustring.gsub(phonetic, "ʃɟ", "ʃc")
phonetic = mw.ustring.gsub(phonetic, "ʃɡ", "ʃk")
-- non-phonemic vowel loss
phonetic = mw.ustring.gsub(phonetic, "%fɨ()", "%1")
phonetic = mw.ustring.gsub(phonetic, "%fi()", "%1")
phonetic = mw.ustring.gsub(phonetic, "m()%f", "m(%1)")
phonetic = mw.ustring.gsub(phonetic, "(ɨʔ?h?)()", "(%1)%2")
phonetic = mw.ustring.gsub(phonetic, "%(m", "m(")
-- different treatment of stressed vowels and diphthongs before plosives
phonetic = mw.ustring.gsub(phonetic, "()ːp", "%1ʔp")
phonetic = mw.ustring.gsub(phonetic, "()ːt", "%1ʔt")
phonetic = mw.ustring.gsub(phonetic, "()ːc", "%1ʔc")
phonetic = mw.ustring.gsub(phonetic, "()ːk", "%1ʔk")
phonetic = mw.ustring.gsub(phonetic, "()ːb", "%1ʔb")
phonetic = mw.ustring.gsub(phonetic, "()ːd", "%1ʔd")
phonetic = mw.ustring.gsub(phonetic, "()ːɟ", "%1ʔɟ")
phonetic = mw.ustring.gsub(phonetic, "()ːɡ", "%1ʔɡ")
phonetic = mw.ustring.gsub(phonetic, "()p", "%1hp")
phonetic = mw.ustring.gsub(phonetic, "()t", "%1ht")
phonetic = mw.ustring.gsub(phonetic, "()c", "%1hc")
phonetic = mw.ustring.gsub(phonetic, "()k", "%1hk")
phonetic = mw.ustring.gsub(phonetic, "()b", "%1hb")
phonetic = mw.ustring.gsub(phonetic, "()d", "%1hd")
phonetic = mw.ustring.gsub(phonetic, "()ɟ", "%1hɟ")
phonetic = mw.ustring.gsub(phonetic, "()ɡ", "%1hɡ")
phonetic = export.finalize_IPA(phonetic)
return ""
end
function export.pronunciation(word)
local parent_args = word:getParent().args
if type(word) == "table" then
word = word.args or word:getParent().args
end
if not word or (word == "") then
word = PAGENAME
end
local generate_ven = true
local generate_wsur = true
local generate_esur = true
if parent_args == '0' then
generate_ven = false
end
if parent_args == '0' then
generate_wsur = false
end
if parent_args == '0' then
generate_esur = false
end
local final_text = ""
local base_IPA = export.to_base_IPA(word)
if generate_ven then
local items = {}
table.insert(items, {pron = export.to_Venezuelan_IPA(base_IPA), note = nil})
ven = m_IPA.format_IPA_full { lang = lang, items = items }
final_text = final_text .. "* " .. m_a.format_qualifiers(lang, {"Venezuela"}) .. " " .. ven
if generate_wsur or generate_esur then
final_text = final_text .. "\n"
end
end
if generate_wsur then
local items = {}
table.insert(items, {pron = export.to_West_Surinamese_IPA(base_IPA), note = nil})
wsur = m_IPA.format_IPA_full { lang = lang, items = items }
final_text = final_text .. "* " .. m_a.format_qualifiers(lang, {"West Suriname"}) .. " " .. wsur
if generate_esur then
final_text = final_text .. "\n"
end
end
if generate_esur then
local items = {}
table.insert(items, {pron = export.to_East_Surinamese_IPA(base_IPA), note = nil})
esur = m_IPA.format_IPA_full { lang = lang, items = items }
final_text = final_text .. "* " .. m_a.format_qualifiers(lang, {"East Suriname"}) .. " " .. esur
end
if generate_wsur and generate_esur and (wsur == esur) then
if generate_ven then
if ven == wsur then
final_text = "* " .. ven
else
final_text = "* " .. m_a.format_qualifiers(lang, {"Venezuela"}) .. " " .. ven .. "\n* " .. m_a.format_qualifiers(lang, {"Suriname"}) .. " " .. wsur
end
else
final_text = "* " .. m_a.format_qualifiers(lang, {"Suriname"}) .. " " .. wsur
end
else
if generate_wsur and generate_ven and (wsur == ven) then
if generate_esur then
final_text = "* " .. m_a.format_qualifiers(lang, {"Venezuela", "West Suriname"}) .. " " .. ven .. "\n* " .. m_a.format_qualifiers(lang, {"East Suriname"}) .. " " .. esur
else
final_text = "* " .. m_a.format_qualifiers(lang, {"Venezuela", "West Suriname"}) .. " " .. ven
end
end
end
return final_text
end
return export