Maithili IPA pronunciation module. See {{mai-IPA}}
.
local export = {}
local lang = require("Module:languages").getByCode("mai")
local sc = require("Module:scripts").getByCode("Deva")
local m_IPA = require("Module:IPA")
local gsub = mw.ustring.gsub
local gmatch = mw.ustring.gmatch
local find = mw.ustring.find
local correspondences = {
= "ŋ", = "ɡ",
= "ʦ", = "ʣ", = "ɲ",
= "ʈ", = "ɖ", = "ɳ",
= "t", = "d",
= "j", = "ʋ", = "l",
= "ɕ", = "ʂ", = "ɦ",
= "ɽ", = "n", = "ʒ",
= "z", = "ɹ", = "rɪ",
= "riː", = "̃", = "",
= ",", = "ɾ", = "j̃",
= "ə", = "ᵊ", = "a",
= "aː", = "ɪ", = "iː",
= "o", = "e", = "eː",
= "ʊ", = "uː", = "oː",
= "əŏ", = "əĕ", = "ː",
= "æ", = "ɔ",
= "ə̃",
= "ãː",
= "ɪ̃",
= "ʊ̃",
= "ẽ",
= "ẽː",
= "õ",
= "õː",
= "ə̃ʊ̯̃",
= "ə̃ʊ̯̃",
= "ĭ",
= "ŭ",
= "ĕ",
= "ŏ",
= "ː",
= "ʰ", = "‿", = "ɪ", = "ʊ", = "ᵊ",
}
local vowels = "aāā̃ẽõiīuūᵊɔɪʊi̯u̯âäæeī̃ū̃ĩôoʌʌ̃ãũŏĕ̤"
local weak_v = "ᵊiu ̆"
local weak_h_c = "gʣjdḍd̪ṇɽbnmlṛvrɾṟwy"
local weak_h = "()h"
local aspirate = "()"
local syllabify_pattern = "(+)(+)(+)"
local function find_consonants(text)
local current = ""
local cons = {}
for cc in mw.ustring.gcodepoint(text .. " ") do
local ch = mw.ustring.char(cc)
if find(current .. ch, "^$") or find(current .. ch, "^h$") then
current = current .. ch
else
table.insert(cons, current)
current = ch
end
end
return cons
end
local function syllabify(text)
for count = 1, 2 do
text = gsub(text, syllabify_pattern, function(a, b, c)
b_set = find_consonants(b)
table.insert(b_set, #b_set > 1 and 2 or 1, "")
return a .. table.concat(b_set) .. c
end)
end
return text
end
local identical = "knlsfzθð"
for character in gmatch(identical, ".") do
correspondences = character
end
local function transliterate(text)
return (lang:transliterate(text))
end
function export.link(term)
return require("Module:links").full_link{ term = term, lang = lang, sc = sc }
end
function export.toIPA(text, alternate)
local translit = transliterate(text)
if not translit then
error('The term "' .. Maithili .. '" could not be transliterated.')
end
if alternate then
translit= gsub(translit, "(?)(?)()$", "%3%1%2")
translit= gsub(translit, "()(?)(?)()$", "%4%1%2%3")
translit= gsub(translit, "(?)(?)() ", "%3%1%2 ")
translit= gsub(translit, "()(?)(?)() ", "%4%1%2%3 ")
translit = gsub(translit, "()(ː?)(?)(̃?)(?)()(̯?)(̃?)", "æ%3%4%8")
translit = gsub(translit, "()(ː?)(?)(̃?)(?)()(̯?)(̃?)", "ɔ%3%4%8")
translit = gsub(translit, "ě(̃?)", "ɛ%1")
translit = gsub(translit, "ǒ(̃?)", "ɔ%1")
translit = gsub(translit, "()", "s")
translit = gsub(translit, "v$", "b")
translit = gsub(translit, "v ", "b")
translit = gsub(translit, "()(ː?)ṛ(?)(?)(̃?)", "%1%2ɾ%3%4%5")
end
local result = gsub(translit, ".", correspondences)
translit = gsub(translit, "͠", "̃")
translit = gsub(translit, "rr̥", "ri")
translit = gsub(translit, "rr̥̄", "riː")
translit = gsub(translit, "()(ː?)(?)(̃?)()(̃?)", "%1%2%3%4%5%6")
translit = gsub(translit, "()(ː?)(?)(̃?)()(̃?)", "%1%2%3%4%5̆%6")
translit = gsub(translit, "(#)va()", "bə%2")
translit = gsub(translit, "(#)v()(ː?)", "b%2%3")
translit = gsub(translit, "(#)()a()()", "bə%3%4")
translit = gsub(translit, "()v()(ː?)()",
"%1w%2%3%4")
translit = gsub(translit, "()()()(ː?)()", "%1w%3%4%5")
translit = gsub(translit, "()(ː?)()(̪)", "%1%2%3̪%4") -- dental assimilation
translit = gsub(translit, "()(ː?)n()", "%1%2ɳ%3") -- retroflex aassimilation
translit = gsub(translit, "()()", "ɭ%2")
translit = gsub(translit, "()(ː?)ɾ()(ː?)", "%1%2ɾ%3%4")
translit = gsub(translit, "ṣp", "ɸp")
translit = gsub(translit, "(#)(?)ya", "%2jə")
translit = gsub(translit, "()(ː?)kṣ", "%1%2t̚ʦʰ") -- kṣ ligature
translit = gsub(translit, "()kṣ", "ʦʰ") -- kṣ initial
translit = gsub(translit, "%-", " ")
translit = gsub(translit, "r̥", "ri")
translit = gsub(translit, "r̥̄", "riː")
translit = syllabify(translit)
-- aspiration rules
translit = gsub(translit, aspirate .. "h", '%1ʰ')
translit = gsub(translit, weak_h, '%1ʱ')
translit = gsub(translit, '()%.h', '.%1ʱ')
translit = gsub(translit, aspirate .. '%.h', '.%1ʰ')
translit = gsub(translit, "%.ː", "ː.")
local result = gsub(translit, ".", correspondences)
-- formatting
result = gsub(result, "(...)ə$", "%1ᵊ")
result = gsub(result, "(...)ə ", "%1ᵊ ")
result = gsub(result, "(...)ə%.?%-", "%1ᵊ-")
result = gsub(result, "()$", "%1̆")
result= gsub(result, "()(ː)(?)()(ː?)(?)(?)()(ː?)$", "%1%3%4%5%6%7%8%9")
result= gsub(result, "()(ː)(?)()(ː?)(?)()(ː?)(?)$", "%1%3%4%5%6%7%8%9")
result= gsub(result, "()(ː)(?)()(ː?)(?)(?)()(ː?) ", "%1%3%4%5%6%7%8%9 ")
result= gsub(result, "()(ː)(?)()(ː?)(?)()(ː?)(?) ", "%1%3%4%5%6%7%8%9 ")
result = gsub(result, "ː̃", "̃ː")
result = gsub(result, "ʦ", "t͡ɕ")
result = gsub(result, "ʣ", "d͡ʑ")
result = gsub(result, "ː.̃", "̃ː.")
result = gsub(result, "%. ", " ")
result = gsub(result, "%.$", " ")
result = gsub(result, "%.?%-", ".")
result = gsub(result, "ː%.̃", "̃ː.")
return result
end
function export.make(frame)
local args = frame:getParent().args
local pagetitle = mw.title.getCurrentTitle().text
local p, results = {}, {}
if args then
for index, item in ipairs(args) do
table.insert(p, (item ~= "") and item or nil)
end
else
p = { pagetitle }
end
for _, Maithili in ipairs(p) do
table.insert(results, { pron = "" })
if export.toIPA(Maithili, true) ~= export.toIPA(Maithili) then
table.insert(results, { pron = "" })
end
end
return m_IPA.format_IPA_full { lang = lang, items = results }
end
return export