This module will transliterate බෙංගාලි භාෂාව 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:bn-translit/testcases.

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.

-- Transliteration for Bengali

local export = {}
local gsub = mw.ustring.gsub
local match = mw.ustring.match
 
local conv = {
	-- consonants
	["ক্ষ"] = "kh",
	['ক'] = 'k',	['খ'] = 'kh',	['গ'] = 'g',	['ঘ'] = 'gh',	['ঙ'] = 'ṅ',
	['চ'] = 'c',	['ছ'] = 'ch',	['জ'] = 'j',	['ঝ'] = 'jh',	['ঞ'] = 'ñ',
	['ট'] = 'ṭ',	['ঠ'] = 'ṭh',	['ড'] = 'ḍ',	['ঢ'] = 'ḍh',	['ণ'] = 'ṇ',
	['ত'] = 't',	['থ'] = 'th',	['দ'] = 'd',	['ধ'] = 'dh',	['ন'] = 'n',
	['প'] = 'p',	['ফ'] = 'ph',	['ব'] = 'b',	['ভ'] = 'ḅ',	['ম'] = 'm',
	['য'] = 'j',	['র'] = 'r',	['ল'] = 'l',
	['শ'] = 'ś',	['ষ'] = 'ṣ',	['স'] = 's',	['হ'] = 'h',	
	['য়'] = 'ẏ',	['ড়'] = 'ṛ',	['ঢ়'] = 'ṛh',
	['জ়'] = 'z',

	-- bisôrgô
	['ঃ'] = 'ḥ',

	-- vowel diacritics
	['ি'] = 'i',	['ু'] = 'u',	['ৃ'] = 'ŕ',	['ে'] = 'e',	['ো'] = 'o', ['্যা'] = 'æ',
	['া'] = 'a',	['ী'] = 'ī',	['ূ'] = 'ū',	['ৈ'] = 'oi',	['ৌ'] = 'ou',

	-- vowel signs
	['অ'] = 'ô',	['ই'] = 'i',	['উ'] = 'u',	['ঋ'] = 'ri',	['এ'] = 'e',	['ও'] = 'o',
	['আ'] = 'a',	['ঈ'] = 'ī',	['ঊ'] = 'ū',	['ঐ'] = 'oi',	['ঔ'] = 'ou',

	--hôsôntô
	['্'] = '',

	-- côndrôbindu
	["ঁ"] = "̃",
		
	-- ônusvar
	['ং'] = 'ṅ',
	
	-- ôbôgrôhô
	['ঽ']='’',

	-- khôndô tô
	['ৎ'] = 't',

	-- numerals
	['০'] = '0', ['১'] = '1', ['২'] = '2', ['৩'] = '3', ['৪'] = '4', ['৫'] = '5', ['৬'] = '6', ['৭'] = '7', ['৮'] = '8', ['৯'] = '9',
 
	-- punctuations
	['।'] = '.', -- dãṛi
    ['॥'] = '.', -- double dãṛi
}

local deaspirate = {
	['খ'] = 'ক',	['ঘ'] = 'গ',
	['ছ'] = 'চ',	['ঝ'] = 'জ',
	['ঠ'] = 'ট',	['ঢ'] = 'ড',
	['থ'] = 'ত',	['ধ'] = 'দ',
	['ফ'] = 'প',	['ভ'] = 'ব', 	
	['ঢ়'] = 'ড়',
}

local conv2 = {
	["ক্ষ"] = "ḱ",	["খ"] = "ḱ",
	["ঘ"] = "ǵ",
	["ঙ"] = "ŋ",	["ং"] = "ŋ",
	["ঝ"] = "ĵ",
	["ঠ"] = "ṫ",	["থ"] = "ť",
	["ঢ"] = "ḋ",	["ধ"] = "ď",
	["ফ"] = "ṗ",
	["ভ"] = "ḃ",
	["ঢ়"] = "ŕ",
	["ৃ"] = "ṙ",	["ঋ"] = "ṙ",
	["ৈ"] = "ʏ",	["ঐ"] = "ʏ",
	["ৌ"] = "ɵ",	["ঔ"] = "ɵ",
}

function export.tr(text, lang, sc)
	local c = '([কষজঞকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ]়?)'
	local y = 'য'
	local r = 'র'
	local v = '([ô্িুৃেোাীূৈৌঅইউঋএওআঈঊঐঔ])'
	local virama = '্'
	local n = '(ং?)' 

	local no_virama = gsub(v,virama,"")
	
	text = text .. " "
	
	text = gsub(text, c, "%1ô")
	text = gsub(text, "ô".. "([ô্িুৃেোাীূৈৌ])", "%1")
	
	text = gsub(text, v .. n .. c .. "ô ", function(j, k, l) -- ending
		return l == y and j .. k .. l .. "ô " or j .. k .. l .. " "
	end)
	
	local pattern = v .. n .. c .. "ô" .. c .. no_virama
	local continue = true
	while continue do
		continue = false
		text = gsub(text,"(.*)" .. pattern,
			function(d, e, f, g, h, i)
				if g ~= y and g ~= r then
					continue = true
				end
				return (g == y or g == r) and d .. e .. f .. g .. "ô" .. h .. i or d .. e .. f .. g .. h .. i
			end)
	end
	
	text = gsub(text, "ওয়", "w")
	text = gsub(text, "র্য", "rj")
	text = gsub(text, "্য", "y")
	text = gsub(text, "([জযডঢ]়)", conv)
	text = gsub(text, ".", conv)
	
	text = gsub(text, "ː(.)", "%1%1")
	
	text = gsub(text, " ?।", ".")

	text = gsub(text, "kṣ", "kh")
	text = gsub(text, "jñ", "gy")
	
	-- vowel fix
	text = gsub(text, "ôo", "ôu")
	text = gsub(text, "ôya", "æ")
	text = gsub(text, "eya", "æ")
	text = gsub(text, "ya", "æ")
	text = gsub(text, "æ$", "ya")
	text = gsub(text, "([bcdghjkmnpśṣstz])r$", "%1rô")

	-- bophola
	text = gsub(text, "([cdjtsś])b", "%1v")

	text = gsub(text, "ḅ", "bh")
	
	text = gsub(text, " $", "")
	
	return mw.ustring.toNFC(text)
end
 
return export
"https://si.wiktionary.org/w/index.php?title=Module:bn-translit&oldid=28568" වෙතින් සම්ප්‍රවේශනය කෙරිණි