Definition from Wiktionary, the free dictionary
Jump to: navigation, search
The following documentation is located at Module:hi-translit/documentation. [edit]

This module will transliterate Hindi language text per WT:HI TR.

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:hi-translit/testcases.


tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by sc, and language specified by lang. When the transliteration fails, returns nil.

Transliteration for Hindi (possibly Sanskrit, Nepali, Marathi, any language using Devanagari script)
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', ['ग़']='ġ', ['ज़']='z', ['झ़']='ž', ['ड़']='ṛ', ['फ़']='f',  ['ढ़']='ṛh'
local diacritics = {
	['ि']='i', ['ु']='u', ['ृ']='ŕ', ['े']='e', ['ो']='o', ['ा']='ā', ['ी']='ī', ['ू']='ū', ['ै']='ai', ['ौ']='au'
local tt = {
	-- vowels
	['अ']='a', ['इ']='i', ['उ']='u', ['ऋ']='ŕ', ['ए']='e', ['ओ']='o', ['आ']='ā', ['ई']='ī', ['ऊ']='ū', ['ऐ']='ai', ['औ']='au', 
	-- chandrabindu    
	['ँ']='m̐', --until a better method is found
	-- anusvara    
	['ं']='ṁ', --until a better method is found
	-- visarga    
	['०']='0', ['१']='1', ['२']='2', ['३']='3', ['४']='4', ['५']='5', ['६']='6', ['७']='7', ['८']='8', ['९']='9',
	['।']='.', --danda
	-- additional characters
function, lang, sc)
	text = mw.ustring.gsub(text, '([कखगघङचछजझञटठडढणतथदधनपफबभमयरलवशषसह]\224\164\188?)\224\165\141\226\128\141?', consonants) -- conjucts (<consonant><virama>[<ZWJ>])
	text = mw.ustring.gsub(text, '([कखगघङचछजझञटठडढणतथदधनपफबभमयरलवशषसह]\224\164\188?)([\224\164\191\224\165\129\224\165\131\224\165\135\224\165\139\224\164\190\224\165\128\224\165\130\224\165\136\224\165\140]?)', function(c, d)
		if d == "" then
			return consonants[c] .. 'a'
			return consonants[c] .. diacritics[d]
	text = mw.ustring.gsub(text, '.', tt)
	return text
return export