local export = {}

local consonants = {
	['क'] = 'k', ['ख'] = 'kh', ['ग'] = 'g', ['घ'] = 'gh', ['ङ'] = 'G',
	['च'] = 'c', ['छ'] = 'ch', ['ज'] = 'j', ['झ'] = 'jh', ['ञ'] = 'J',
	['ट'] = 'T', ['ठ'] = 'Th', ['ड'] = 'D', ['ढ'] = 'Dh', ['ण'] = 'N',
	['त'] = 't', ['थ'] = 'th', ['द'] = 'd', ['ध'] = 'dh', ['न'] = 'n',
	['प'] = 'p', ['फ'] = 'ph', ['ब'] = 'b', ['भ'] = 'bh', ['म'] = 'm',
	['य'] = 'y', ['र'] = 'r', ['ल'] = 'l', ['व'] = 'v', ['ळ'] = 'L',
	['श'] = 'z', ['ष'] = 'S', ['स'] = 's', ['ह'] = 'h',
}

local diacritics = {
	['्'] = '', ['ा'] = 'A',
	['ि'] = 'i', ['ी'] = 'I',
	['ु'] = 'u', ['ू'] = 'U',
	['ृ'] = 'R', ['ॄ'] = 'RR',
	['ॢ'] = 'lR', ['ॣ'] = 'lRR',
	['े'] = 'e', ['ै'] = 'ai',
	['ो'] = 'o', ['ौ'] = 'au',
}

local tt = {
	-- vowels
	['अ'] = 'a', ['आ'] = 'A',
	['इ'] = 'i', ['ई'] = 'I',
	['उ'] = 'u', ['ऊ'] = 'U',
	['ऋ'] = 'R', ['ॠ'] = 'RR',
	['ऌ'] = 'lR', ['ॡ'] = 'lRR',
	['ए'] = 'e', ['ऐ'] = 'ai',
	['ओ'] = 'o', ['औ'] = 'au',
	-- chandrabindu    
	['ँ'] = 'M', --until a better method is found
	-- anusvara    
	['ं'] = 'M', --until a better method is found
	-- visarga    
	['ः'] = 'H',
	-- avagraha
	['ऽ'] = '’',
	--numerals
	['०'] = '0', ['१'] = '1', ['२'] = '2', ['३'] = '3', ['४'] = '4', ['५'] = '5', ['६'] = '6', ['७'] = '7', ['८'] = '8', ['९'] = '9',
	--punctuation        
	['॥'] = '.', --double danda
	['।'] = '.', --danda
	--Vedic extensions
	['ᳵ'] = 'x',
	['ᳶ'] = 'f',
	--Om
	['ॐ'] = 'oM',
}

function export.tr(text, lang, sc)
	text = mw.ustring.gsub(text,
		'([कखगघङचछजझञटठडढणतथदधनपफबभमयरलळवशषसह])' ..
				'([ािीुूृॄॢॣेैोौ्]?)',
		function(c, d)
			if d == "" then
				return consonants[c] .. 'a'
			else
				return consonants[c] .. diacritics[d]
			end
		end)
	
	text = mw.ustring.gsub(text, '.', tt)
	
	return text
end

return export
"https://si.wiktionary.org/w/index.php?title=Module:sa-utilities/translit/Deva-to-HK&oldid=41854" වෙතින් සම්ප්‍රවේශනය කෙරිණි