Pergi ke kandungan

Modul:Deva-Newa-translit

Daripada Wikikamus

Modul ini akan mentransliterasi teks dalam Tulisan Devanagari. 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-Newa-translit/testcases.

Functions

[sunting]
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 = 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, '𑐘𑑂𑐴', "𑐙")
        --text = mw.ustring.gsub(text, '𑑄$', "𑑈")
	return text
end
 
return export