local export = {}
local gsub = mw.ustring.gsub
local consonants = {
='k', ='kh', ='g', ='gh', ='ṅ',
='c', ='ch', ='j', ='jh', ='ny',
='t', ='th', ='d', ='dh', ='n',
='p', ='ph', ='b', ='bh', ='m',
='y', ='r', ='l', ='w',
='ś', ='ṣ', ='s', ='h',
='gy', ='tr', ='',
}
local diacritics = {
='a' , ='i' , ='u' , ='e' , ='ai' , ='o' , ='au' , ='ê' , ='ô'
}
local special = {
-- idk what to call these
='’', --mukphreng (glottalizer)
= '̃', --anusvara (now obsolete)
}
local subjoined = {
='r', ='w', ='y',
}
local finals = {
='k', ='ṅ', ='t', ='n', ='p', ='m', ='r', ='l',
}
local nonconsonants = {
-- digits
= '0', = '1', = '2', = '3', = '4',
= '5', = '6', = '7', = '8', = '9',
='.', ='!', ='?',
='lo'
}
-- translit any words or phrases
function export.tr(text, lang, sc)
text = mw.ustring.gsub(text, '()᤻', '᤺%1⌫') -- treat underscore as kemphreng
text = mw.ustring.gsub(
text,
'()'..
'(?)'..
'(?)'..
'(?)'..
'(?)',
function(c, d, e, f, g)
-- mw.log('match', c, d)
return (consonants or c) ..
(subjoined or d) ..
(diacritics or (e ~= "") and e or 'ô') ..
(special or f) ..
(finals or g)
end)
text = mw.ustring.gsub(text, '.', nonconsonants)
text = mw.ustring.gsub(text, '(.)⌫', '')
text = gsub(text, 'aᤣ', 'o')
text = gsub(text, 'ᤣᤣ', 'ai')
text = gsub(text, 'aᤣᤣ', 'au')
text = mw.ustring.gsub(text, '᤺', '̄')
text = mw.ustring.gsub(text, 'ᤰ', 'k')
text = mw.ustring.gsub(text, 'ᤱ', 'ṅ')
text = mw.ustring.gsub(text, 'ᤳ', 't')
text = mw.ustring.gsub(text, 'ᤴ', 'n')
text = mw.ustring.gsub(text, 'ᤵ', 'p')
text = mw.ustring.gsub(text, 'ᤶ', 'm')
text = mw.ustring.gsub(text, 'ᤷ', 'r')
text = mw.ustring.gsub(text, 'ᤸ', 'l')
text = gsub(text, '̄ᤣ', 'ō')
text = mw.ustring.gsub(text, 'aō', 'ō')
return mw.ustring.toNFC(text)
end
return export