Module:Shrd-translit

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

This module will transliterate text in the Sharada script. It is used to transliterate Kashmiri. 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:Shrd-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', 
	-- 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
				if not diacritics[d] then error("Missing data for diacritic '" .. d .. "'") end
				return consonants[c] .. diacritics[d]
			end
		end)

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