模組:Btx-translit

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

這個模組會將卡羅巴塔克語未確定的文字拉丁化。

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

關於測試用例,請參閱Module:Btx-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.

local export = {}
 
local consonants = {
	['ᯀ']='(h)',  ['ᯂ']='k', ['ᯅ']='b',
	['ᯇ']='p', ['ᯉ']='n', ['ᯋ']='w',
	['ᯎ']='g', ['ᯐ']='j', ['ᯑ']='d', ['ᯒ']='r', ['ᯔ']='m',
	['ᯗ']='t', ['ᯘ']='s', ['ᯛ']='y',
	['ᯝ']='ng', ['ᯞ']='l', ['ᯠ']='c', ['ᯡ']='c',
}

local diacritics = {
	['ᯧ']= 'e' , ['ᯩ']='e' , ['ᯪ']='i' , ['ᯫ']='i' , ['ᯨ']='o' , 
	['ᯭ']='o' ,  ['ᯬ']='u' , ['᯳']='' , 
}

local nonconsonants = {
	-- vowels
	['ᯤ']='i' , ['ᯥ']='u' ,
	-- aditional characters
	['ᯰ']='ng',
	['ᯱ']='h',
}

-- translit any words or phrases
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, '.', nonconsonants)
	
	return text
end
 
return export