This module will transliterate Sanskrit language text per WT:SA TR. The module should preferably not be called directly from templates or other modules. To use it from a template, use {{xlit}}. Within a module, use Module:languages#Language:transliterate.

For testcases, see Module:sa-Telu-translit/testcases.

Functions

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by the code sc, and language specified by the code lang.
When the transliteration fails, returns nil.

Testcases

edit

Module:sa-Telu-translit/testcases:

All tests passed. (refresh)

TextExpectedActualComments
test:
Passedవాక్vākvāk
Passedవాకvākavāka
Passedఅదృష్టadṛṣṭaadṛṣṭa
Passedసోఽహమ్so’hamso’ham
Passedదుఃఖduḥkhaduḥkha
Passedనీళnīḷanīḷa
Passednn

local gsub = mw.ustring.gsub

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 tt = {
	-- vowels
	['అ']='a', ['ఆ']='ā', ['ఇ']='i', ['ఈ']='ī', ['ఉ']='u', ['ఊ']='ū', ['ఋ']='ṛ', ['ౠ']='ṝ',
	['ఌ']='ḷ', ['ౡ']='ḹ', ['ఏ']='e', ['ఐ']='ai', ['ఓ']='o', ['ఔ']='au', 
	-- Nakaara Pollu
	['ౝ']='n', 	
	-- chandrabindu    
	['ఁ']='m̐', --until a better method is found
	-- anusvara    
	['ం']='ṃ', --until a better method is found
	-- visarga    
	['ః']='ḥ',
	-- avagraha
	['ఽ']='’',
	--numerals
	['౦']='0', ['౧']='1', ['౨']='2', ['౩']='3', ['౪']='4', ['౫']='5', ['౬']='6', ['౭']='7', ['౮']='8', ['౯']='9',
	--punctuation        
    ['॥']='.', --double danda
	['।']='.', --danda
    --Vedic extensions
	-- ["ᳵ"] = "ᳵ", ["ᳶ"] = "ᳶ",
    --Om
    ['ఓం']='oṃ',
    --reconstructed
    ['*'] = '',
}

function export.tr(text, lang, sc)
	text = gsub(
		text,
		'([కఖగఘఙచఛజఝఞటఠడఢణతథదధనపఫబభమయరలవళశషసహ])'..
		'([ాిీుూృౄౢౣేైోౌ్]?)',

		function(c, d)
			if d == "" then        
				return consonants[c] .. 'a'
			else
				return consonants[c] .. diacritics[d]
			end
		end)

	text = gsub(text, '.', tt)
	
	return text
end
 
return export