Module:sa-utilities/translit/Deva-to-SLP1

Ut Wikiwurdboek
local export = {}

local consonants = {
	['क'] = 'k', ['ख'] = 'K', ['ग'] = 'g', ['घ'] = 'G', ['ङ'] = 'N',
	['च'] = 'c', ['छ'] = 'C', ['ज'] = 'j', ['झ'] = 'J', ['ञ'] = 'Y',
	['ट'] = 'w', ['ठ'] = 'W', ['ड'] = 'q', ['ढ'] = 'Q', ['ण'] = 'R',
	['त'] = 't', ['थ'] = 'T', ['द'] = 'd', ['ध'] = 'D', ['न'] = 'n',
	['प'] = 'p', ['फ'] = 'P', ['ब'] = 'b', ['भ'] = 'B', ['म'] = 'm',
	['य'] = 'y', ['र'] = 'r', ['ल'] = 'l', ['व'] = 'v', ['ळ'] = 'L',
	['श'] = 'S', ['ष'] = 'z', ['स'] = 's', ['ह'] = 'h',
}

local diacritics = {
	['्'] = '', ['ा'] = 'A',
	['ि'] = 'i', ['ी'] = 'I',
	['ु'] = 'u', ['ू'] = 'U',
	['ृ'] = 'f', ['ॄ'] = 'F',
	['ॢ'] = 'x', ['ॣ'] = 'X',
	['े'] = 'e', ['ै'] = 'E',
	['ो'] = 'o', ['ौ'] = 'O',
}

local tt = {
	-- vowels
	['अ'] = 'a', ['आ'] = 'A',
	['इ'] = 'i', ['ई'] = 'I',
	['उ'] = 'u', ['ऊ'] = 'U',
	['ऋ'] = 'f', ['ॠ'] = 'F',
	['ऌ'] = 'x', ['ॡ'] = 'X',
	['ए'] = 'e', ['ऐ'] = 'E',
	['ओ'] = 'o', ['औ'] = 'O',
	-- chandrabindu
	['ँ'] = '~',
	-- anusvara
	['ं'] = 'M',
	-- visarga
	['ः'] = 'H',
	-- avagraha
	['ऽ'] = '',
	--numerals
	['०'] = '0', ['१'] = '1', ['२'] = '2', ['३'] = '3', ['४'] = '4', ['५'] = '5', ['६'] = '6', ['७'] = '7', ['८'] = '8', ['९'] = '9',
	--punctuation
	['॥'] = '.', --double danda
	['।'] = '.', --danda
	--Vedic extensions
	['ᳵ'] = 'Z',
	['ᳶ'] = 'V',
	--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