Pergi ke kandungan

Modul:kn-translit

Daripada Wikikamus

Modul ini akan mentransliterasi Bahasa Kannada teks. Ia juga digunakan untuk mentransliterasi Badaga, Bellari, Beary, Middle Kannada, Old Kannada, Kodava, Korra Koraga, Konkani, Sholaga, Tulu, 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:kn-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', ['ಙ']='ng', 
	['ಚ']='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' , ['ೂ']='ū' , ['ೃ']='r̥' , ['ೄ']='r̥̄' ,
	['ೆ']='e' , ['ೇ']='ē' , ['ೈ']='ai' , ['ೊ']='o' , ['ೋ']='ō' , ['ೌ']='au' 
}

local nonconsonants = {
	-- vowels
	['ಅ']='a' , ['ಆ']='ā' , ['ಇ']='i' , ['ಈ']='ī' , ['ಉ']='u' , ['ಊ']='ū' , 
	['ಋ']='r̥' , ['ೠ']='r̥̄' , ['ಌ']='l̥' , ['ೡ']='l̥̄', ['ಎ']='e' , ['ಏ']='ē' ,
	['ಐ']='ai' , ['ಒ']='o' , ['ಓ']='ō' , ['ಔ']='au' , ['ಅಂ']='aṃ' , ['ಅಃ']='ah' , 
	-- other symbols
	['ಂ']='ṃ', -- anusvara
	['ಃ']='ḥ',  -- visarga
	--halant, supresses the inherent vowel "a"
	['್']='',
	-- 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)
			if d == "" then        
				return consonants[c] .. 'a'
			else
				return consonants[c] .. (diacritics[d] or d)
			end
		end)
	
	text = mw.ustring.gsub(text, '.', nonconsonants)
	
	return text
end
 
return export