local export = {}
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local conv = {
-- consonants
= 'k', = 'kh', = 'g', = 'gh', = 'ṅ',
= 'c', = 'ch', = 'j', = 'jh', = 'ñ',
= 'ṭ', = 'ṭh', = 'ḍ', = 'ḍh', = 'ṇ',
= 't', = 'th', = 'd', = 'dh', = 'n',
= 'p', = 'ph', = 'b', = 'bh', = 'm',
= 'y', = 'r', = 'l', = 'v', = 'ḷ',
= 'ś', = 'ṣ', = 's', = 'h',
= 't̰', = 'z', = 'ng', = 'ṛ', = 'ṛh', = 'ṉ', = 'f',
--vowel diacritics
= 'ā', = 'i', = 'ī', = 'u', = 'ū', = 'ru', = 'ṝ',
= 'e', = 'ai', = 'o', = 'au', = 'ɛ', = 'ɔ',
-- vowel mātras
= 'a', = 'ā', = 'i', = 'ī', = 'u', = 'ū', = 'ru', = 'ṝ',
= 'e', = 'ai', = 'o', = 'au', = 'ɛ', = 'ɔ',
-- chandrabindu
= 'm̐', --until a better method is found
-- anusvara
= 'ṃ', --until a better method is found
-- visarga
= 'ḥ',
-- virama
= '',
-- avagraha
= '’',
--numerals
= '0', = '1', = '2', = '3', = '4', = '5', = '6', = '7', = '8', = '9',
--punctuation
= '.', --danda
= '', -- compound separator
--om
= 'OM',
}
local nasal_assim = {
h?"] = "ṅ",
h?"] = "ñ",
h?"] = "ṇ",
h?"] = "n",
h?"] = "m",
= "n",
= "m",
}
function export.tr(text, lang, sc)
local c = '(઼?)'
local no_drop = 'ય'
local final_no_drop = 'યરલવહનમ'
local v = '(ઁ?)'
local virama = '(્)'
local n = '(ં?)'
local nukta = '(઼)'
local can_drop = gsub(c,"","")
local final_can_drop = gsub(c,"","")
local no_virama = gsub(v,virama,"")
text = text .. " "
--text = gsub(text,"(%S)"..c.."%2","%1ː%2")
text = gsub(text,c,"%1a")
text = gsub(text,"a"..v,"%1")
text = gsub(text,no_virama..n..can_drop.."a ","%1%2%3 ") --ending
text = gsub(text,virama..n..final_can_drop.."a ","%1%2%3 ") --ending
local pattern = no_virama..n..can_drop.."a"..c..no_virama
while match(text,"(.*)"..pattern) do
text = gsub(text,"(.*)"..pattern,"%1%2%3%4%5%6")
end
text = gsub(text,nukta,conv)
text = gsub(text,".",conv)
for key,val in pairs(nasal_assim) do
text = gsub(text,"()ṃ("..key..")", "%1"..val.."%2")
end
text = gsub(text,"()ṃ", "%1̃")
text = gsub(text,"ː(.)","%1%1")
text = gsub(text," $","")
text = gsub(text,"ā̃tar","āntar")
text = gsub(text,"OM","oṃ")
return mw.ustring.toNFC(text)
end
return export