Jump to content

Module:sa-Guru-translit

From Wiktionary, the free dictionary

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-Guru-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 m_str_utils = require("Module:string utilities")
local gsub = m_str_utils.gsub

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