Module:sa-Mlym-translit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

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-Mlym-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.

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', 

	-- chillus, consonants that never take vowels
	['ൺ']='ṇ' , ['ൻ']='ṉ' , ['ർ']='r' , ['ൽ']='l' , ['ൾ']='ḷ' , ['ൿ']='k' , ['ൔ']='m', ['ൕ']='y', ['ൖ']='ḻ',
	['ൎ']='ṟ',
	-- 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
    -- ['ᳵ']='x', ['ᳶ']='f',
    --Om
    ['ഓം']='oṃ',
    --reconstructed
    ['*'] = '',
}

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