local export = {}
local 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',
='ḷ', ='ḻ', ='ṟ' , ='ṉ' , ='ṯ' ,
}
local diacritics = {
= 'ŭ',
= 'ā' ,
= 'i' ,
= 'ī' ,
= 'u' ,
= 'ū' ,
= 'r̥' ,
= 'r̥̄' ,
= 'e' ,
= 'ē' ,
= 'ai',
= 'o' ,
= 'ō' ,
= 'au',
= 'l̥ ',
= 'l̥̄' ,
--virama, supresses the inherent vowel "a"
= '',
-- no diacritic
= 'a'
}
local nonconsonants = {
-- vowels
='a' , ='ā' , ='i' , ='ī' , ='u' , ='ū' ,
='r̥' , ='r̥̄' , ='l̥' , ='l̥̄', ='e' , ='ē' ,
='ai' , ='o' , ='ō' , ='au' ,
-- other symbols
='ṃ', -- anusvara
='ḥ' , -- visarga
='’', -- praślēṣam
-- chillus, consonants that never take vowels
='ṇ' , ='n' , ='r' , ='l' , ='ḷ' , ='k' ,
-- digits
= '0', = '1', = '2', = '3', = '4',
= '5', = '6', = '7', = '8', = '9',
='10', ='100', ='1000', ='¼', ='½', ='¾',
}
-- translit any words or phrases
function export.tr(text, lang, sc)
local VIRAMA = '്'
-- final virama rules
text = mw.ustring.gsub(text, VIRAMA .. "$", VIRAMA .. "ŭ")
text = mw.ustring.gsub(text, VIRAMA .. " ", VIRAMA .. "ŭ ")
text = mw.ustring.gsub(
text,
'()'..
'(\224\181\129??)',
function(c, d)
return consonants .. (diacritics or d)
end)
text = mw.ustring.gsub(text, '.', nonconsonants)
-- anusvara
text = mw.ustring.gsub(text, 'ṃ()', 'ṅ%1')
text = mw.ustring.gsub(text, 'ṃ()', 'ñ%1')
text = mw.ustring.gsub(text, 'ṃ()', 'ṇ%1')
text = mw.ustring.gsub(text, 'ṃ()', 'n%1')
text = mw.ustring.gsub(text, 'ṃ()', 'm%1')
text = mw.ustring.gsub(text, "ŭ ()", " \1") -- ŭ is elided before vowels
return text
end
return export