模組:Deva-Limb-translit


This module will transliterate text in the 天城文. 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:Deva-Limb-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.

local export = {}
local U = mw.ustring.char
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local sub = mw.ustring.sub  
local conv = {
	['क']='ᤁ', ['ख']='ᤂ', ['ग']='ᤃ', ['घ']='ᤄ', 
    ['ङ']='ᤅ', ['च']='ᤆ', ['छ']='ᤇ', ['ज']='ᤈ',
    ['झ']='ᤋ', ['ञ']='ᤊ', ['ट']='ᤋ', ['ठ']='ᤌ', 
    ['ड']='ᤍ', ['ढ']='ᤎ', ['ण']='ᤏ', ['त']='ᤋ', 
    ['थ']='ᤌ', ['द']='ᤍ', ['ध']='ᤎ', ['न']='ᤏ', 
	['प']='ᤐ', ['फ']='ᤑ', ['ब']='ᤒ', ['भ']='ᤓ', 
    ['म']='ᤔ', ['य']='ᤕ', ['र']='ᤖ', ['ल']='ᤗ', 
    ['व']='ᤘ', ['ळ']='ᤗ', ['श']='ᤙ', ['ष']='ᤚ', 
    ['स']='ᤛ', ['ह']='ᤜ', ['ॽ']='᤹',

	['ा']='ᤠ', ['ि']='ᤡ', ['ी']='ᤡ᤺', ['ु']='ᤢ', 
    ['ू']='ᤢ᤺', ['ृ']='ᤪᤡ', ['ॄ']='ᤪᤡ᤺', ['ॢ']='ᤡ', 
    ['ॣ']='ᤡ᤺', ['े']='ᤣ', ['ै']='ᤤ', ['ो']='ᤥ', 
    ['ौ']='ᤦ', ['ॅ']='ᤧ', ['ॉ']='ᤨ', ['ॆ']='ᤧ', 
    ['ॊ']='ᤨ', 

	-- vowels
	['अ']='ᤀ', ['आ']='ᤀᤠ', ['इ']='ᤀᤡ', ['ई']='ᤀᤡ᤺', 
    ['उ']='ᤀᤢ', ['ऊ']='ᤀᤢ᤺', ['ऋ']='ᤖᤡ', ['ॠ']='ᤖᤡ᤺',
	['ऌ']='ᤗᤪᤡ', ['ॡ']='ᤗᤪᤡ᤺', ['ए']='ᤀᤣ', ['ऐ']='ᤀᤤ', 
    ['ओ']='ᤀᤥ', ['औ']='ᤀᤦ', ['ऍ']='ᤀᤧ', ['ऑ']='ᤀᤨ', 
    ['ऎ']='ᤀᤧ', ['ऒ']='ᤀᤨ',
	-- chandrabindu    
	['ँ']='ᤲ',
	-- anusvara    
	['ं']='ᤲ',
	-- visarga    
	['ः']='᤺',
	-- avagraha
	['ऽ']='',
	--punctuation
	['॰']='.',
    ['॥']='॥',
	['।']='॥',
	['ॐ']='ᤀᤥᤶ',
    ['!']='᥄',
    ['?']='᥅',

    --Vedic extensions
    ['ᳵ']='', ['ᳶ']='',

		['०']='᥆', ['१']='᥇', ['२']='᥈', ['३']='᥉', ['४']='᥊', ['५']='᥋', ['६']='᥌', ['७']='᥍', ['८']='᥎', ['९']='᥏'
}

function export.tr(text, lang, sc)
	text = mw.ustring.gsub(
		text,
		".",
		function(c)
			return conv[c]
		end)
        text = gsub(text, '([ᤁᤂᤃᤄᤅᤆᤇᤈᤉᤊᤋᤌᤍᤎᤏᤐᤑᤒᤓᤔᤕᤖᤗᤘᤙᤚᤛᤜᤝᤞᤀ])([᤺]?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)(़?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)([᤺]?)ᤁ्', '%1%2%3%4%5%6ᤰ')
        text = gsub(text, '([ᤁᤂᤃᤄᤅᤆᤇᤈᤉᤊᤋᤌᤍᤎᤏᤐᤑᤒᤓᤔᤕᤖᤗᤘᤙᤚᤛᤜᤝᤞᤀ])([᤺]?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)(़?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)([᤺]?)ᤅ्', '%1%2%3%4%5%6ᤱ')
        text = gsub(text, '([ᤁᤂᤃᤄᤅᤆᤇᤈᤉᤊᤋᤌᤍᤎᤏᤐᤑᤒᤓᤔᤕᤖᤗᤘᤙᤚᤛᤜᤝᤞᤀ])([᤺]?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)(़?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)([᤺]?)ᤋ्', '%1%2%3%4%5%6ᤳ')
        text = gsub(text, '([ᤁᤂᤃᤄᤅᤆᤇᤈᤉᤊᤋᤌᤍᤎᤏᤐᤑᤒᤓᤔᤕᤖᤗᤘᤙᤚᤛᤜᤝᤞᤀ])([᤺]?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)(़?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)([᤺]?)ᤏ्', '%1%2%3%4%5%6ᤴ')
        text = gsub(text, '([ᤁᤂᤃᤄᤅᤆᤇᤈᤉᤊᤋᤌᤍᤎᤏᤐᤑᤒᤓᤔᤕᤖᤗᤘᤙᤚᤛᤜᤝᤞᤀ])([᤺]?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)(़?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)([᤺]?)ᤐ्', '%1%2%3%4%5%6ᤵ')
        text = gsub(text, '([ᤁᤂᤃᤄᤅᤆᤇᤈᤉᤊᤋᤌᤍᤎᤏᤐᤑᤒᤓᤔᤕᤖᤗᤘᤙᤚᤛᤜᤝᤞᤀ])([᤺]?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)(़?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)([᤺]?)ᤔ्', '%1%2%3%4%5%6ᤶ')
        text = gsub(text, '([ᤁᤂᤃᤄᤅᤆᤇᤈᤉᤊᤋᤌᤍᤎᤏᤐᤑᤒᤓᤔᤕᤖᤗᤘᤙᤚᤛᤜᤝᤞᤀ])([᤺]?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)(़?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)([᤺]?)ᤖ्', '%1%2%3%4%5%6ᤷ')
        text = gsub(text, '([ᤁᤂᤃᤄᤅᤆᤇᤈᤉᤊᤋᤌᤍᤎᤏᤐᤑᤒᤓᤔᤕᤖᤗᤘᤙᤚᤛᤜᤝᤞᤀ])([᤺]?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)(़?)([ᤠ	ᤡ	ᤢ	ᤣ	ᤤ	ᤥ	ᤦ	ᤧ	ᤨ	ᤩ	ᤪ]?)([᤺]?)ᤗ्', '%1%2%3%4%5%6ᤸ')
        text = gsub(text, '्ᤖ', 'ᤪ')
        text = gsub(text, '्ᤕ', 'ᤩ')
        text = gsub(text, '्ᤘ', 'ᤫ')
        text = gsub(text, 'ज्ञ', 'ᤝ')
        text = gsub(text, 'त्र', 'ᤞ')
        text = mw.ustring.gsub(text, 'ᤀᤣ़', 'ᤀᤧ')
        text = mw.ustring.gsub(text, 'ᤀᤥ़', 'ᤀᤨ')
        text = mw.ustring.gsub(text, 'ᤣ़', 'ᤧ')
        text = mw.ustring.gsub(text, 'ᤥ़', 'ᤨ')
        text = mw.ustring.gsub(text, '़', '')
        text = mw.ustring.gsub(text, '्', '')
	return text
end
 
return export