跳转到内容

模組:Kn-translit

維基詞典,自由的多語言詞典

這個模組會將卡納達語未確定的文字拉丁化。

最好不要直接從模板或其他模組調用此模組。要從模板中使用它,請以{{xlit}}做為替代;若要在模組中使用,則以Module:languages#Language:transliterate替代。

關於測試用例,請參閱Module:Kn-translit/testcases

函數

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.

-- Transliteration for Kannada 康納達語轉譯

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', ['ಳ']='ḷ', ['ೞ']='ḻ', 
	['ಫ಼']='f', ['ಜ಼']='z', ['ಳ಼']='zh', 
}

local diacritics = {
	['ಾ']= 'ā' , ['ಿ']='i' , ['ೀ']='ī' , ['ು']='u' , ['ೂ']='ū' , ['ೃ']='ru' , ['ೄ']='rū' ,
	['ೆ']='e' , ['ೇ']='ē' , ['ೈ']='ai' , ['ೊ']='o' , ['ೋ']='ō' , ['ೌ']='au' 
}

local nonconsonants = {
	-- vowels
	['ಅ']='a' , ['ಆ']='ā' , ['ಇ']='i' , ['ಈ']='ī' , ['ಉ']='u' , ['ಊ']='ū' , 
	['ಋ']='ru' , ['ೠ']='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)
			c = consonants[c] or c
			if d == "" then        
				return c .. 'a'
			else
				return c .. (diacritics[d] or d)
			end
		end)
	
	text = mw.ustring.gsub(text, '.', nonconsonants)
	
	-- anusvara
	text = mw.ustring.gsub(text, 'ṃ([kgṅ])', 'ṅ%1')
	text = mw.ustring.gsub(text, 'ṃ([cjñ])', 'ñ%1')
	text = mw.ustring.gsub(text, 'ṃ([ṭḍṇ])', 'ṇ%1')
	text = mw.ustring.gsub(text, 'ṃ([tdn])', 'n%1')
	text = mw.ustring.gsub(text, 'ṃ([pbm])', 'm%1')
	
	return text
end
 
return export