Module:Beng-Deva-translit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module will transliterate text in the Bengali script. 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:Beng-Deva-translit/testcases.

Functions[edit]

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 gsub = mw.ustring.gsub

local export = {}

local conv = {
	-- consonants
	['ক']='क', ['খ']='ख', ['গ']='ग', ['ঘ']='घ', ['ঙ']='ङ',
	['চ']='च', ['ছ']='छ', ['জ']='ज', ['ঝ']='झ', ['ঞ']='ञ', 
	['ট']='ट', ['ঠ']='ठ', ['ড']='ड', ['ঢ']='ढ', ['ণ']='ण',
	['ত']='त', ['থ']='थ', ['দ']='द', ['ধ']='ध', ['ন']='न', 
	['প']='प', ['ফ']='फ', ['ব']='ब', ['ভ']='भ', ['ম']='म',
	['য']='य', ['র']='र', ['ল']='ल', ['ল়']='ळ', ['শ']='श', 
    ['ষ']='ष', ['স']='स', ['হ']='ह',
    ['ড়']='ड़', ['ঢ়']='ढ़', ['য়']='य़', ['ৎ']='त्',

	-- maatra
	['া']='ा', ['ি']='ि', ['ী']='ी', ['ু']='ु', ['ূ']='ू', ['ৃ']='ृ', ['ৄ']='ॄ',
	['ৢ']='ॢ', ['ৣ']='ॣ', ['ে']='े', ['ৈ']='ै', ['ো']='ो', ['ৌ']='ौ',  ['্']='्', ['়']='़',

	-- vowels
	['অ']='अ', ['আ']='आ', ['ই']='इ', ['ঈ']='ई', ['উ']='उ', ['ঊ']='ऊ', ['ঋ']='ऋ', ['ৠ']='ॠ',
	['ঌ']='ऌ', ['ৡ']='ॡ', ['এ']='ए', ['ঐ']='ऐ', ['ও']='ओ', ['ঔ']='औ', 
	-- chandrabindu    
	['ঁ']='ँ',
	-- anusvara    
	['ং']='ं',
	-- visarga    
	['ঃ']='ः',
	-- avagraha
	['ঽ']='ऽ',
	--punctuation
    ['॥']='॥',
	['।']='।',
	['ওঁ']='ॐ',
    --Vedic extensions
    ['ᳵ']='ᳵ', ['ᳶ']='ᳶ',

		['০']='०', ['১']='१', ['২']='२', ['৩']='३', ['৪']='४',  ['৫']='५', ['৬']='६', ['৭']='७', ['৮']='८', ['৯']='९'
}

function export.tr(text, lang, sc, noNuqta)
	text = text:gsub("্ব", "्व")

	-- Nuqta is not used in Devanagari Sanskrit.
	if noNuqta and lang ~= "sa" then
		text = text:gsub("ড়", "ড")
			:gsub("ঢ়", "ঢ")
			:gsub("য়", "য")
	end

	text = gsub(
		text,
		".",
		function(c)
			return conv[c]
		end)

	return text
end
 
return export