Module:Mahj-translit

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

This module will transliterate text in the Mahajani script. It is used to transliterate Marwari. 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:Mahj-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', 
	['๐‘…ญ']='r', ['๐‘…ฎ']='l', ['๐‘…ฏ']='v',
	['๐‘…ฐ']='s', ['๐‘…ฑ']='h', ['๐‘…ฒ'] = 'แน›',
}

local nonconsonants = {
	-- vowels
	['๐‘…']='a', ['๐‘…‘']='i', ['๐‘…’']='u', ['๐‘…“']='e', ['๐‘…”']='o',

	-- other symbols
	['๐‘…ดโ€Ž']='.', -- abbreviation mark
	['๐‘…ต']='ยง', -- section mark
	['๐‘…ถ']='Shri', -- ligature [[เคถเฅเคฐเฅ€]]
}

-- translit any words or phrases
function export.tr(text, lang, sc)
	text = mw.ustring.gsub(
		text,
		'([๐‘…•๐‘…–๐‘…—๐‘…˜๐‘…™๐‘…š๐‘…›๐‘…œ๐‘…๐‘…ž๐‘…Ÿ๐‘… ๐‘…ก๐‘…ข๐‘…ฃ๐‘…ค๐‘…ฅ๐‘…ฆ๐‘…ง๐‘…จ๐‘…ฉ๐‘…ช๐‘…ซ๐‘…ฌ๐‘…ญ๐‘…ฎ๐‘…ฏ๐‘…ฐ๐‘…ฑ๐‘…ฒ])'..
		'([๐‘…ณ]?)',
		function(c, d)
			-- mw.log('match', c, d)
			return (consonants[c] or c)
		end)
	
	text = mw.ustring.gsub(text, '.', nonconsonants)
	
	return text
end
 
return export