Module:Modi-translit

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

This module will transliterate text in the Modi script. It is used to transliterate Old Marathi. 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:Modi-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',
	-- virama
	['๐‘˜ฟ'] = '',
}

local tt = {
	-- vowel signs
	['๐‘˜€'] = 'a', ['๐‘˜‚'] = 'i', ['๐‘˜„'] = 'u', ['๐‘˜Š'] = 'e', ['๐‘˜Œ'] = 'o',
	['๐‘˜'] = 'ฤ', ['๐‘˜ƒ'] = 'ฤซ', ['๐‘˜…'] = 'ลซ', 
	['๐‘˜†'] = 'ล•', 
	['๐‘˜‹'] = 'ai', ['๐‘˜'] = 'au', 
	['๐‘˜๐‘™€'] = 'ล',
	['๐‘˜€๐‘™€'] = 'ฤ•', ['๐‘˜Š๐‘™€'] = 'ฤ•',
	-- anusvara
	['๐‘˜ฝ'] = 'แนƒ',
	-- visarga
	['๐‘˜พ'] = 'แธฅ',
	-- numerals
	['๐‘™'] = '0', ['๐‘™‘'] = '1', ['๐‘™’'] = '2', ['๐‘™“'] = '3', ['๐‘™”'] = '4', ['๐‘™•'] = '5', ['๐‘™–'] = '6', ['๐‘™—'] = '7', ['๐‘™˜'] = '8', ['๐‘™™'] = '9',
	--punctuation        
	['๐‘™'] = '.', -- danda
	['๐‘™‚'] = '.', -- double danda
	['+'] = '', -- compound separator
	
	-- abbreviation sign
	['๐‘™ƒ'] = '.',
    --Om
    ['เฅ']='oแนƒ',
}

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)
	text = mw.ustring.gsub(text," ?[๐‘™๐‘™‚]",".")

	
	return text
end
 
return export