Module:kru-Deva-translit

This module will transliterate Kurukh language text. 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:kru-Deva-translit/testcases.

Functions

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.

Testcases edit

Module:kru-Deva-translit/testcases:

6 of 6 tests failed. (refresh)

TextExpectedActualComments
test_translit_kurukh:
Failedआलारālārālāra
Failedए–ड़ाēṛāe–ḍa़ा
Failedख़ंज्पाxañjpākha़ṃjpā
Failedनिंग्योniṅgyoniṃgyo
Failedतंबसtaṃbastaṃbasa
Failedएम्बसembasembasa

local gsub = mw.ustring.gsub
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',
	['क़'] = 'q', ['ख़'] = 'x', ['ग़'] = 'ġ', ['फ़'] = 'f',
	['ज़'] = 'z', ['झ़'] = 'ź', ['ड़'] = 'ṛ', ['ढ़'] = 'ṛh',
}

local diacritics = {
	['ा']='ā', ['ि']='i', ['ी']='ī', ['ु']='u', ['ू']='ū', ['ृ']='ṛ', ['ॄ']='ṝ', 
	['ॢ']='ḷ', ['ॣ']='ḹ', ['े']='e', ['ै']='ai', ['ो']='o', ['ौ']='au',  ['्']='', }

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
    --Om
    ['ॐ']='oṃ',
}

function export.tr(text, lang, sc)
	text = gsub(
		text,
		'([क-ह])'..
		'([ािीुूृॄॢॣेैोौ्]?)'..
		'([अ-औ]?)',
		function(c, d)
			if not consonants[c] then
				return c
			end
			if d == "" then
				return consonants[c] .. "a"
			else
				return consonants[c] .. diacritics[d]
			end
		end)

	text = gsub(text, '.', tt)

    text = gsub(text, 'ṁ([kgṅ])', 'ṅ%1')
	text = gsub(text, 'ṁ([cjñ])', 'ñ%1')
	text = gsub(text, 'ṁ([ṭḍṇ])', 'ṇ%1')
	text = gsub(text, 'ṁ([tdn])', 'n%1')
	text = gsub(text, 'ṁ([pbm])', 'm%1')

	return text
end
 
return export