模組:Kru-translit

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

這個模組將轉寫庫魯克語的文字。 最好不要直接從模板或其他模組呼叫此模組;要從模板中使用它, 請使用{{xlit}}; 要從模組中使用它,請使用Module:languages#Language:transliterate

關於測試用例,請見Module:Kru-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 = {
	['क']='k' , ['ख']='kh' , ['ग']='g' , ['घ']='gh' , ['ङ']='ṅ' , 
	['च']='c' , ['छ']='ch' , ['ज']='j' , ['झ']='jh' , ['ञ']='ñ' ,  
	['ट']='ṭ' , ['ठ']='ṭh' , ['ड']='ḍ' , ['ढ']='ṇ' , ['ञ़']='n̰' , 
	['त']='t' ,  ['थ']='th' , ['द']='d' , ['ध']='dh' , ['न']='n' ,
	['प']='p' , ['फ']='ph' , ['ब']='b' , ['भ']='bh' , ['म']='m' , 
	['य']='y' , ['र']='r' , ['ल']='l' , ['व']='v' ,  ['श']='ś' ,
	['ष']='š' , ['स']='s' ,  ['ह']='h' , ['क़']='q' , ['ख़']='x' ,
	['ग़']='ġ' , ['ज़']='z' , ['ड़']='ṛ' , ['ढ़']='ṛh' , ['फ़']='f' ,
	['व़']='w' , ['क्ष']='ks' , ['त्र']='tr' , ['श्र']='śr' , 
}

local diacritics = {
	['ा']='a' , ['ा']= 'ā' , ['ि']='i' ,  ['ु']='u' , ['ृ']='ṛ' , ['े']='e' , ['ो']='o' ,
	['ा़']='ä' , ['ो़']='ö' , ['ॅ']='æ' , ['ँ']='ṅ' , ['़']='o' , ['़']='o' ,
}

local tt = {
	-- vowels
	['अ']='a', ['आ']='ā', ['इ']='i', ['ई']='ī', ['उ']='u', ['ऊ']='ū', ['ऋ']='ṛ', ['ॠ']='ṝ',
	['ऌ']='ḷ', ['ॡ']='ḹ', ['ए']='e', ['ऐ']='ai', ['ओ']='o', ['औ']='au', 
	-- chandrabindu    
	['ँ']='m̐', --until a better method is found
	-- anusvara    
	['ं']='ṃ', --until a better method is found
	-- visarga    
	['ः']='ḥ',
	-- avagraha
	['ऽ']='’',
	--numerals
	['०']='0', ['१']='1', ['२']='2', ['३']='3', ['४']='4', ['५']='5', ['६']='6', ['७']='7', ['८']='8', ['९']='9',
	--punctuation        
    ['॥']='.', --double danda
	['।']='.', --danda
    --Vedic extensions
    ['ᳵ']='x', ['ᳶ']='f',
    --Om
    ['ॐ']='oṃ',
    --reconstructed
    ['*'] = '',
    --accentuation (needs to be handled)
    ['॑'] = '', ['॒'] = ''
}

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)
	
	return text
end
 
return export