Module:saz-translit

This module will transliterate Saurashtra language text. 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:saz-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', ['꣄']='', ['ꢴ']='h',
}

local nonconsonants = {
	-- vowels
	['ꢂ']='a', ['ꢃ']='ā', ['ꢄ']='i', ['ꢅ']='ī', ['ꢆ']='u', ['ꢇ']='ū', 
	['ꢈ']='ṛ', ['ꢉ']='ṝ', ['ꢊ']='ḷ', ['ꢋ']='ḹ', ['ꢌ']='e', ['ꢍ']='ē',
	['ꢎ']='ai', ['ꢏ']='o', ['ꢐ']='ō', ['ꢑ']='au',
	-- other symbols
	['ꢀ']='ṃ', -- anusvara
	['ꢁ']='ḥ',  -- visarga
	['ꣅ']='◌̃', 
	['꣎']='.',
	-- digits
	['꣐'] = '0', ['꣑'] = '1', ['꣒'] = '2', ['꣓'] = '3', ['꣔'] = '4',
	['꣕'] = '5', ['꣖'] = '6', ['꣗'] = '7', ['꣘'] = '8', ['꣙'] = '9',
}

-- translit any words or phrases
function export.tr(text, lang, sc)
	text = mw.ustring.gsub(
		text,
		'([ꢒꢓꢔꢕꢖꢗꢘꢙꢚꢛꢜꢝꢞꢟꢠꢡꢢꢣꢤꢥꢦꢧꢨꢩꢪꢫꢬꢭꢮꢯꢰꢱꢲꢳ])'..
		'([ꢵꢶꢷꢸꢹꢺꢻꢼꢽꢾꢿꣀꣁꣂꣃ꣄ꢴ]?)',
		function(c, d)
			-- mw.log('match', c, d)
			c = consonants[c] or c
			if d == "" then        
				return c .. 'a'
			else
				return c .. (diacritics[d] or d)
			end
		end)
	
	text = mw.ustring.gsub(text, '.', nonconsonants)
	
	return text
end
 
return export