Module:sa-Modi-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-Modi-translit/testcases.

Functions

[edit]
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', 
	-- 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