မဝ်ဂျူ:inc-pra-Deva-translit

နူ ဝိက်ရှေန်နရဳ

This is the unit-testing module for Module:inc-pra-Deva-translit.

All tests passed. (refresh)

လိက် ဗွဲမရံၚ်လၟဳ မဇေတ်ဍာံ ဒၞာဲတၞဟ်ခြာ
testcases for tr function in Module:inc-pra-Deva-translit:
Passed सेट्ठि sĕṭṭhi sĕṭṭhi
Passed एक्क ĕkka ĕkka
Passed बोल्लइ bŏllaï bŏllaï
Passed ओक्किअ ŏkkia ŏkkia
Passed तेल tela tela
Passed एसज्ज esajja esajja
Passed तोस tosa tosa
Passed ओहि ohi ohi
Passed अउअ aüa aüa
Passed अइउट्ट aïuṭṭa aïuṭṭa
Passed अउम aüma aüma
Passed सउण saüṇa saüṇa
Passed वाअउ vāaü vāaü

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', ['ू']='ū', ['ृ']='ṛ', ['ॄ']='ṝ', 
	['ॢ']='ḷ', ['ॣ']='ḹ', ['ॆ']='ĕ', ['े']='e', ['ै']='ai', ['ॊ']='ŏ', ['ो']='o', ['ौ']='au',  ['्']='',
}

local diatrema = { -- vowels with diaereis added in transliteration
	['इ']='ï', ['उ']='ü',
}

local tt = {
	-- vowels
	['अ']='a', ['आ']='ā', ['इ']='i', ['ई']='ī', ['उ']='u', ['ऊ']='ū', ['ऋ']='ṛ', ['ॠ']='ṝ',
	['ऌ']='ḷ', ['ॡ']='ḹ', ['ऎ']='ĕ', ['ए']='e', ['ऐ']='ai', ['ऒ']='ŏ', ['ओ']='o', ['औ']='au',
	-- chandrabindu
	['ँ']='m̐', --until a better method is found
	-- anusvara
	['ं']='ṃ', --until a better method is found
	--numerals
	['०']='0', ['१']='1', ['२']='2', ['३']='3', ['४']='4', ['५']='5', ['६']='6', ['७']='7', ['८']='8', ['९']='9',
	--punctuation        
    ['॥']='.', --double danda
	['।']='.', --danda
    --Om
    ['ॐ']='oṃ',
    --reconstructed
    ['*'] = '',
}

function export.tr(text, lang, sc)
	if sc ~= "Deva" then
		return nil
	end

	text = mw.ustring.gsub(text, '(े)([अ-ह][़]?)(्)([अ-ह][़]?)', 'ॆ%2%3%4')
	text = mw.ustring.gsub(text, '(ए)([अ-ह][़]?)(्)([अ-ह][़]?)', 'ऎ%2%3%4')
	text = mw.ustring.gsub(text, '(ो)([अ-ह][़]?)(्)([अ-ह][़]?)', 'ॊ%2%3%4')
	text = mw.ustring.gsub(text, '(ओ)([अ-ह][़]?)(्)([अ-ह][़]?)', 'ऒ%2%3%4')
	
	text = mw.ustring.gsub(
		text,
		'([क-ह][़]?)'..
		'([ािीुूृॄॢॣॆेैॊोौ्]?)'..
		'([इउ]?)',
		function(c, d, e)
			if d == "" and e ~= "" then        
				if tt[e] == "i" or tt[e] == "u" then return consonants[c] .. 'a' .. tt[e] .. '̈'
				else return consonants[c] .. 'a' .. tt[e] end
			elseif e ~= "" then
				return consonants[c] .. diacritics[d] .. tt[e]
			elseif d == "" then        
				return consonants[c] .. 'a'
			else
				return consonants[c] .. diacritics[d]
			end
		end)

-- Adjacent vowel letters needing dieresis
	text = mw.ustring.gsub(text, '([अ])([इउ])', function(a, b) return tt[a]..diatrema[b] end)
 
	text = mw.ustring.gsub(text, '.', tt)
	
	return text
end
 
return export