Modul ini akan mentransliterasi Bahasa Malayalam teks. Ia juga digunakan untuk mentransliterasi Badaga, Bellari, Beary, Kodava, Kurichiya, Konkani, Malavedan, Mannan, Tulu, Muduga, and Ravula. 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:ml-translit/testcases.

Functions

sunting
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 = {
	['\224\181\129\224\181\141'] = 'ŭ',
	['\224\180\190'] = 'ā' ,
	['\224\180\191'] = 'i' ,
	['\224\181\128'] = 'ī' ,
	['\224\181\129'] = 'u' ,
	['\224\181\130'] = 'ū' ,
	['\224\181\131'] = 'r̥' ,
	['\224\181\132'] = 'r̥̄' ,
	['\224\181\134'] = 'e' ,
	['\224\181\135'] = 'ē' ,
	['\224\181\136'] = 'ai',
	['\224\181\138'] = 'o' ,
	['\224\181\139'] = 'ō' ,
	['\224\181\151'] = 'au',
	['\224\181\162'] = 'l̥ ',
	['\224\181\163'] = 'l̥̄' ,
	--halant, supresses the inherent vowel "a"
	['\224\181\141'] = '',
	-- no diacritic
	[''] = 'a'
}

local nonconsonants = {
	-- vowels
	['അ']='a' , ['ആ']='ā' , ['ഇ']='i' , ['ഈ']='ī' , ['ഉ']='u' , ['ഊ']='ū' , 
	['ഋ']='r̥' , ['ൠ']='r̥̄' , ['ഌ']='l̥' , ['ൡ']='l̥̄', ['എ']='e' , ['ഏ']='ē' ,
	['ഐ']='ai' , ['ഒ']='o' , ['ഓ']='ō' , ['ഔ']='au' ,
	-- other symbols
	['ം']='ṃ', -- anusvara
	['ഃ']='ḥ' ,  -- visarga
	['ഽ']='’',
	-- chillus, consonants that never take vowels
	['ൺ']='ṇ' , ['ൻ']='n' , ['ർ']='r' , ['ൽ']='l' , ['ൾ']='ḷ' , ['ൿ']='k' ,
	-- digits
	['൦'] = '0', ['൧'] = '1', ['൨'] = '2', ['൩'] = '3', ['൪'] = '4',
	['൫'] = '5', ['൬'] = '6', ['൭'] = '7', ['൮'] = '8', ['൯']= '9',
	['൰']='10', ['൱']='100', ['൲']='1000', ['൳']='¼', ['൴']='½', ['൵']='¾',
}

-- translit any words or phrases
function export.tr(text, lang, sc)
	text = mw.ustring.gsub(
		text,
		'([കഖഗഘങചഛജഝഞടഠഡഢണതഥദധനപഫബഭമയരലവശഷസഹളഴറഩഺ])'..
		'(\224\181\129?[\224\180\190\224\180\191\224\181\128\224\181\129\224\181\130\224\181\131\224\181\132\224\181\162\224\181\163\224\181\134\224\181\135\224\181\138\224\181\139\224\181\136\224\181\151\224\181\141]?)',
		function(c, d)
			return consonants[c] .. (diacritics[d] or d)
		end)
	
	text = mw.ustring.gsub(text, '.', nonconsonants)
	
	return text
end
 
return export