local export = {}
local m_IPA = require("Module:IPA")
local m_str_utils = require("Module:string utilities")
local find = m_str_utils.find
local gcodepoint = m_str_utils.gcodepoint
local gmatch = m_str_utils.gmatch
local gsub = m_str_utils.gsub
local u = m_str_utils.char
local lang = require("Module:languages").getByCode("mr")
local sc = require("Module:scripts").getByCode("Deva")
local correspondences = {
= "ŋ", = "ɡ",
= "t͡ɕ", = "d͡ʑ", = "t͡s", = "d͡z", = "n",
= "ʈ", = "ɖ", = "ɳ",
= "t̪", = "d̪",
= "j", = "ɾ", = "ʋ", = "l̪", = "ɭ̆",
= "ɕ", = "ʂ", = "ɦ",
= "ɽ", = "z", = "ɭ", = "ɡ", = "k", = "kʰ", = "n", = "ɾ",
= "ə", = "a", = "i",
= "i", = "o", = "e",
= "u", = "u", = "ɔ", = "æ",
= "ũ", = "õ", = "ə̃", = "ã",
= "oːm", = "ʰ", = "",
}
local deaspirate = {
= "क", = "ग",
= "च", = "ज",
= "ट", = "ड",
= "त", = "द",
= "प", = "ब"
}
local vowels = "aāiīuūoŏĕɔɛeæ"
local weak_h_c = "gjdḍṇbṛnmrṟlv"
local weak_h = "()h"
local aspirate = "()"
local syllabify_pattern = "(+)(+)(+)"
local function find_consonants(text)
local current = ""
local cons = {}
for cc in gcodepoint(text .. " ") do
local ch = u(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, phonetic)
--fix how aspiration is represented
text = gsub(text, '()(़?्)()', function(a, b, c)
if a == c then return deaspirate .. b .. c end
return a .. b .. c
end)
local translit = transliterate(text)
if not translit then
error('The term "' .. text .. '" could not be transliterated (is it in the correct script?).')
end
if phonetic then
translit = gsub(translit, 'ts', 'ċh') -- ts realization
translit = gsub(translit, '()aha()', '%1a%2') -- schwa dropping
translit = gsub(translit, '()ah()', '%1h%2') -- schwa dropping
translit = gsub(translit, '()()h()', '%1h%2%3') -- murmur + aspiration rules
translit = gsub(translit, '()ah()', '%1%2') -- schwa + h dropping
translit = gsub(translit, '()()ha()', '%1%2%3') -- schwa + h dropping 2
translit = gsub(translit, '()()h()', '%1%2%3') -- h dropping
end
-- vowels
translit = gsub(translit, "͠", "̃")
translit = gsub(translit, 'a(̃?)i', 'əi%1')
translit = gsub(translit, 'a(̃?)u', 'əu%1')
translit = gsub(translit, "%-", ".")
translit = gsub(translit, "ŕ", "ru")
-- schwa force
translit = gsub(translit, "%*", "a")
translit = syllabify(translit)
-- clusters
translit = gsub(translit, 'ndny', 'ndñ')
translit = gsub(translit, 'dny', 'dñ')
if phonetic then translit = gsub(translit, 'ts', 't͡sʰ') end
if phonetic then
translit = gsub(translit, '()āh', '%1hā')
translit = gsub(translit, aspirate .. "h", '%1ʰ')
translit = gsub(translit, weak_h, '%1ʱ')
translit = gsub(translit, '()%.h', '.%1ʱ')
translit = gsub(translit, aspirate .. '%.h', '.%1ʰ')
end
if phonetic then
translit = gsub(translit, '()()h%.', '%1%2.') -- more h dropping
translit = gsub(translit, '()()h$', '%1%2') -- more h dropping
end
translit = gsub(translit, "%.ː", "ː.")
-- aspiration
translit = gsub(translit, "()h", "%1ʰ")
translit = gsub(translit, "()ʰ", "%1ʱ")
translit = gsub(translit, "()%.h", ".%1ʱ")
local result = gsub(translit, ".̈?", correspondences)
-- formatting
result = gsub(result, "ː̃", "̃ː")
result = gsub(result, "ː.̃", "̃ː.")
result = gsub(result, "%. ", " ")
result = gsub(result, "%.$", "")
if phonetic then
-- lengthening of i/u in final syllables (Dhongde & Wali p. 9)
result = gsub(result, "i(*)$", "iː%1")
result = gsub(result, "u(*)$", "uː%1")
end
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 _, Marathi in ipairs(p) do
local broad, narrow = export.toIPA(Marathi, false), export.toIPA(Marathi, true)
table.insert(results, { pron = "/" .. broad .. "/" })
if broad ~= narrow then
table.insert(results, { pron = "" })
end
end
return m_IPA.format_IPA_full { lang = lang, items = results }
end
return export