Module:bn-translit

Hello, you have come here looking for the meaning of the word Module:bn-translit. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:bn-translit, but we will also tell you about its etymology, its characteristics and you will know how to say Module:bn-translit in singular and plural. Everything you need to know about the word Module:bn-translit you have here. The definition of the word Module:bn-translit will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:bn-translit, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module will transliterate Bengali language text per WT:BN 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:bn-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.

-- Transliteration for Bengali
local export = {}

local m_str_utils = require("Module:string utilities")

local u = m_str_utils.char
local gmatch = m_str_utils.gmatch
local gsub = m_str_utils.gsub
local len = m_str_utils.len
local match = m_str_utils.match
local sub = m_str_utils.sub
local toNFC = mw.ustring.toNFC

local QO = u(0x003F) -- question mark

local char = {
	-- consonants
	 = "k",
	 = "kh",
	 = "g",
	 = "gh",
	 = "ṅ",
	 = "c",
	 = "ch",
	 = "j",
	 = "jh",
	 = "ñ",
	 = "ṭ",
	 = "ṭh",
	 = "ḍ",
	 = "ḍh",
	 = "ṇ",
	 = "t",
	 = "th",
	 = "d",
	 = "dh",
	 = "n",
	 = "p",
	 = "ph",
	 = "b",
	 = "bh",
	 = "m",
	 = "j",
	 = "r",
	 = "l",
	 = "ś",
	 = "ṣ",
	 = "s",
	 = "h",
	 = "ṛ",
	 = "ṛh",
	 = "ẏ",

	-- vowel diacritics
	 = "i",
	 = "u",
	 = "ri",
	 = "e",
	 = "ō",
	 = "a",
	 = "i",
	 = "u",
	 = "ōi",
	 = "ōu",

	-- archaic vowel diacritics
	 = "ri",
	 = "li",
	 = "li",

	-- visarga
	 = "ḥ",

	-- vowel signs
	 = "o",
	 = "i",
	 = "u",
	 = "ri",
	 = "e",
	 = "ō",
	 = "a",
	 = "i",
	 = "u",
	 = "ōi",
	 = "ōu",

	-- archaic vowel signs
	 = "ri",
	 = "li",
	 = "li",

	--virama
	 = "",

	-- chandrabindu
	 = "̃",

	-- avagraha
	 = '’',

	-- anusvara
	 = "ṅ",

	-- khandata,
	 = "t",

	-- numerals
	 = "0",
	 = "1",
	 = "2",
	 = "3",
	 = "4",
	 = "5",
	 = "6",
	 = "7",
	 = "8",
	 = "9",

	-- punctuation
	 = ".", -- dãri
}

local consonant, vowel, vowel_sign = "ক-হড়-য়", "oা-ৌ’", "অ-ঔ"
local c = ""
local cc = "়?" .. c
local v = ""
local syncope_pattern = "(" .. v .. cc .. v .. cc .. ")o(" .. cc .. "ঁ?" .. v .. ")"

local deaspirate = ""

local function rev_string(text)
	local result, length = "", len(text)
	for i = 1, length do
		result = result .. sub(text, length - i + 1, length - i + 1)
	end
	return result
end

function export.tr(text, lang, sc, override)
	text = gsub(text, "(" .. c .. ")ও", "%1্ও")
	text = gsub(text, "^(" .. c .. ")্ও", "%1ও")

	text = gsub(text, "(" .. c .. ")্‌(" .. c .. ")$", "%1্%2্")
	text = gsub(text, "(" .. c .. ")্‌(" .. c .. ") ", "%1্%2্ ")

	text = gsub(text, "(" .. v .. ")ঞ(" .. v .. ")", "%1̃%2")

	text = gsub(text, "(" .. c .. "়?)(?)", function(a, b)
		return a .. (b == "" and "o" or b)
	end)

	for word in gmatch(text, "+") do
		local orig_word = word
		word = rev_string(word)
		word = gsub(word, "^o(়?" .. c .. ")(ঁ?" .. v .. ")", "%1%2")
		while match(word, syncope_pattern) do
			word = gsub(word, syncope_pattern, "%1%2")
		end
		text = gsub(text, orig_word, rev_string(word))
	end

	text = gsub(text, "(" .. deaspirate .. ")হ", "%1'h")

	text = gsub(text, "্ম", "ṃ")
	text = gsub(text, "্য", "y")
	text = gsub(text, "্ব", "v")

	text = gsub(text, "িত$", "ito")
	text = gsub(text, "িত ", "ito ")

	text = gsub(text, "ৃত$", "rito")
	text = gsub(text, "ৃত ", "rito ")

	text = gsub(text, "িব$", "ibo")
	text = gsub(text, "িব ", "ibo ")

	text = gsub(text, "র্চ$", "র্চ্‌")
	text = gsub(text, "র্চ ", "র্চ্‌ ")

	text = gsub(text, "ছিল$", "chilo")
	text = gsub(text, "ছিল ", "chilo ")

	text = gsub(text, "র()o", "রo%1")

	text = gsub(text, "(" .. cc .. ")o()", "%1%2")
	text = gsub(text, "(" .. cc .. ")ও", "%1oō")

	text = gsub(text, ".?", char)
	text = gsub(text, ".", char)

	local v_Latn = "̃?"
	local c_Latn = ""
	local consonants_no_h = ""

	-- inherent vowel deletion
	text = gsub(text, "(" .. v_Latn .. ")bo()(" .. v_Latn .. ")", "%1b%2%3")
	text = gsub(text, "(" .. v_Latn .. ")cho()(" .. v_Latn .. ")", "%1ch%2%3")
	text = gsub(text, "(" .. v_Latn .. ")do()(" .. v_Latn .. ")", "%1d%2%3")
	text = gsub(text, "(" .. v_Latn .. ")dho()(" .. v_Latn .. ")", "%1dh%2%3")

	text = gsub(text, "(" .. v_Latn .. ")go()(" .. v_Latn .. ")", "%1g%2%3")

	text = gsub(text, "(" .. v_Latn .. ")jo()(" .. v_Latn .. ")", "%1j%2%3")
	text = gsub(text, "(" .. v_Latn .. ")ko()(" .. v_Latn .. ")", "%1k%2%3")
	text = gsub(text, "(" .. v_Latn .. ")kho()(" .. v_Latn .. ")", "%1kh%2%3")
	text = gsub(text, "(" .. v_Latn .. ")lo(h?)(" .. v_Latn .. ")", "%1l%2%3")
	text = gsub(text, "(" .. v_Latn .. ")lo(v)(" .. v_Latn .. ")", "%1l%2%3")

	text = gsub(text, "(" .. v_Latn .. ")mo()(" .. v_Latn .. ")", "%1m%2%3")
	text = gsub(text, "(" .. v_Latn .. ")no(?)(" .. v_Latn .. ")", "%1n%2%3")
	text = gsub(text, "(" .. v_Latn .. ")ṅo(h?)(" .. v_Latn .. ")", "%1ṅ%2%3")
	text = gsub(text, "(" .. v_Latn .. ")po()(" .. v_Latn .. ")", "%1p%2%3")
	text = gsub(text, "(" .. v_Latn .. ")pho(?)(" .. v_Latn .. ")", "%1ph%2%3")

	text = gsub(text, "(" .. v_Latn .. ")ro(h?)(" .. v_Latn .. ")", "%1r%2%3")
	text = gsub(text, "(" .. v_Latn .. ")ṣo()(" .. v_Latn .. ")", "%1ṣ%2%3")
	text = gsub(text, "(" .. v_Latn .. ")śo()(" .. v_Latn .. ")", "%1ś%2%3")
	text = gsub(text, "(" .. v_Latn .. ")so()(" .. v_Latn .. ")", "%1s%2%3")
	text = gsub(text, "(" .. v_Latn .. ")ṭo()(" .. v_Latn .. ")", "%1ṭ%2%3")

	text = gsub(text, "(" .. v_Latn .. ")ẏo()(" .. v_Latn .. ")", "%1ẏ%2%3")

	-- exceptional
	text = gsub(text, "()ch$", "%1cho")
	text = gsub(text, "()ch ", "%1cho ")
	text = gsub(text, "()ch(" .. QO .. ")", "%1cho%2")

	text = gsub(text, "apon(" .. v_Latn .. ")", "apn%1")
	text = gsub(text, "arbi", "arobi")

	text = gsub(text, "goñjo$", "gonj")
	text = gsub(text, "goñjo ", "gonj ")
	text = gsub(text, "got", "goto")

	text = gsub(text, "hojjo", "hojj")

	text = gsub(text, "ikta$", "ikota")
	text = gsub(text, "ikta ", "ikota ")

	text = gsub(text, "iẏ$", "iẏo")
	text = gsub(text, "iẏ ", "iẏo ")

	text = gsub(text, "ken$", "keno")
	text = gsub(text, "ken ", "keno ")
	text = gsub(text, "ken(" .. QO .. ")", "keno%1")

	text = gsub(text, "korob", "korbo")

	text = gsub(text, "sṭo$", "sṭ")
	text = gsub(text, "sṭo ", "sṭ ")

	text = gsub(text, "ajon(" .. v_Latn .. ")", "ajn")
	text = gsub(text, "(" .. v_Latn .. ")koṭr(" .. v_Latn .. ")", "%1kṭr%2")
	text = gsub(text, "(" .. v_Latn .. ")khost(" .. v_Latn .. ")", "%1khst%2")
	text = gsub(text, "(" .. v_Latn .. ")jost(" .. v_Latn .. ")", "%1jst%2")
	text = gsub(text, "(" .. v_Latn .. ")no(" .. c_Latn .. "h?)(" .. c_Latn .. "h?)(" .. v_Latn .. ")", "%1n%2%3%4")
	text = gsub(text, "(" .. v_Latn .. ")rkoṭ(" .. v_Latn .. ")", "%1rkṭ%2")
	text = gsub(text, "(" .. v_Latn .. ")ṣdh(" .. v_Latn .. ")", "%1ṣodh%2")
	text = gsub(text, "(" .. v_Latn .. ")sm(" .. v_Latn .. ")", "%1śom%2")

	text = gsub(text, "^up(" .. c_Latn .. ")", "upo%1")
	text = gsub(text, " up(" .. c_Latn .. ")", " upo%1")

	-- qualifiers
	text = gsub(text, "(" .. c_Latn .. ")oṭa$", "%1ṭa")
	text = gsub(text, "(" .. c_Latn .. ")oṭa ", "%1ṭa ")
	text = gsub(text, "(" .. c_Latn .. ")oṭi$", "%1ṭi")
	text = gsub(text, "(" .. c_Latn .. ")oṭi ", "%1ṭi ")

	-- Cv
	text = gsub(text, "()v", "%1b")
	text = gsub(text, "udv", "udb")
	text = gsub(text, "ttv", "tt")
	text = gsub(text, "^sv", "ś")                           -- initial
	text = gsub(text, "()v", "śś")                    -- medial

	text = gsub(text, "^(" .. consonants_no_h .. "h?)v", "%1") -- initial
	text = gsub(text, " (" .. consonants_no_h .. "h?)v", " %1") -- initial
	text = gsub(text, "()(" .. consonants_no_h .. "h?)v", "%1%2")
	text = gsub(text, "(" .. consonants_no_h .. ")v", "%1%1") -- medial
	text = gsub(text, "(" .. consonants_no_h .. ")hv", "%1%1h") -- medial_h

	--ahv, ihv
	text = gsub(text, "ahv", "aubh")
	text = gsub(text, "ihv", "iubh")

	text = gsub(text, "hv", "hb")

	-- kṣ
	text = gsub(text, "^kṣ", "kh") -- initial
	text = gsub(text, " kṣ", " kh") -- initial
	text = gsub(text, "ṅkṣ", "ṅkh") -- after_ṅ
	text = gsub(text, "kṣ", "kkh") -- medial
	text = gsub(text, "kkhṃ", "kkh") -- before_ṃ

	-- sm
	text = gsub(text, "^()ṃ(" .. v_Latn .. ")", "ś%2̃") -- initial
	text = gsub(text, "()ṃ(" .. v_Latn .. ")", "śś%2̃") -- medial

	-- tm
	text = gsub(text, "^tṃ", "t") -- initial
	text = gsub(text, "tṃ", "tt") -- medial

	text = gsub(text, "ṃ", "m")
	text = gsub(text, "ṣ", "ś")

	-- visarga deletion
	text = gsub(text, "ḥkh", "kkh")

	-- foreign conjuncts
	text = gsub(text, "()ḍo$", "%1ḍ")
	text = gsub(text, "()nḍo ", "%1ḍ ")

	text = gsub(text, "rko$", "rk")
	text = gsub(text, "rko ", "rk ")

	text = gsub(text, "(" .. v_Latn .. ")h$", "%1ho")
	text = gsub(text, "(" .. v_Latn .. ")h ", "%1ho ")

	text = gsub(text, "()aho$", "%1ah")
	text = gsub(text, "()aho ", "%1ah ")

	text = gsub(text, "ṇn", "ṇon")
	text = gsub(text, "ṇ", "n")

	text = gsub(text, "^eya", "ê")
	text = gsub(text, " eya", " ê")
	text = gsub(text, "^oya", "ê")
	text = gsub(text, " oya", " ê")

	text = gsub(text, "^(" .. consonants_no_h .. "h?)ya", "%1ê")                             -- initial
	text = gsub(text, " (" .. consonants_no_h .. "h?)ya", " %1ê")                            -- initial
	text = gsub(text, "^(" .. consonants_no_h .. "h?)(" .. consonants_no_h .. "h?)ya", "%1%2ê") -- initial_double
	text = gsub(text, " (" .. consonants_no_h .. "h?)(" .. consonants_no_h .. "h?)ya", " %1%2ê") -- initial_double
	text = gsub(text, "^hya", "hê")                                                          -- h_initial
	text = gsub(text, "yal$", "êl")                                                          -- final_l

	text = gsub(text, "^jñan", "gên")                                                       -- jñan_initial
	text = gsub(text, " jñan", " gên")                                                      -- jñan_initial
	text = gsub(text, "jñan", "ggên")                                                       -- jñan_medial

	text = gsub(text, "ñ", "n")

	text = gsub(text, "yanḍ", "ênḍ")

	text = gsub(text, "^(" .. consonants_no_h .. "h?)yo", "%1ê") -- initial
	text = gsub(text, " (" .. consonants_no_h .. "h?)yo", " %1ê") -- initial

	-- Cy
	text = gsub(text, "^(" .. consonants_no_h .. "h?)y", "%1") -- initial
	text = gsub(text, "ṅ(" .. consonants_no_h .. "h?)y", "ṅ%1")
	text = gsub(text, "(" .. consonants_no_h .. ")y", "%1%1") -- medial
	text = gsub(text, "(" .. consonants_no_h .. ")hy", "%1%1h") -- medial_h

	-- hy
	text = gsub(text, "^hy", "h") -- initial
	text = gsub(text, " hy", " h") -- initial
	text = gsub(text, "hy", "jjh") -- medial

	-- ry
	text = gsub(text, "ry", "rj")

	text = gsub(text, "ẏo()()", "ẏ%1%2")
	text = gsub(text, "ẏoō", "ẏō")
	text = gsub(text, "oō$", "ō")

	text = gsub(text, "()ẏ()", "%1ẏo%2")
	text = gsub(text, "()ẏ$", "%1ẏo")

	-- rules for changing s to ś (applicable for native words only)
	text = gsub(text, "s(" .. v_Latn .. ")$", "ś%1") -- final
	text = gsub(text, "s(" .. v_Latn .. ") ", "ś%1 ") -- final
	text = gsub(text, "s(" .. v_Latn .. ")", "ŝ%1") -- medial

	text = gsub(text, "()s$", "%1ś")
	text = gsub(text, "()s ", "%1ś ")

	text = gsub(text, "os$", "oŝ")
	text = gsub(text, "os ", "oŝ ")

	text = gsub(text, "^(" .. c_Latn .. ")oŝ$", "%1os")
	text = gsub(text, " (" .. c_Latn .. ")oŝ$", " %1os")
	text = gsub(text, "^(" .. c_Latn .. ")oŝ ", "%1os ")

	text = gsub(text, "^ŝe(" .. c_Latn .. ")$", "^se%1")
	text = gsub(text, " ŝe(" .. c_Latn .. ")$", " se%1")
	text = gsub(text, "^ŝe(" .. c_Latn .. ") ", "^se%1 ")
	text = gsub(text, " ŝe(" .. c_Latn .. ") ", " se%1 ")

	text = gsub(text, "ŝalam", "salam")

	text = gsub(text, "ŝ", "ś")

	text = gsub(text, "śl", "sl")
	text = gsub(text, "śr", "sr")
	text = gsub(text, "sp", "śp")
	text = gsub(text, "^śp", "sp")
	text = gsub(text, " śp", " sp")

	text = gsub(text, "śṭh$", "śṭho")

	text = gsub(text, "^(h?)()", "%1o%2")
	text = gsub(text, "^(" .. c_Latn .. ")()b$", "%1%2bo")
	text = gsub(text, "^(" .. c_Latn .. ")()b ", "%1%2bo ")

	text = gsub(text, "^()()bh$", "%1%2bho")
	text = gsub(text, "^()()bh ", "%1%2bho ")

	text = gsub(text, "lona$", "lna")
	text = gsub(text, "nola$", "nla")

	text = gsub(text, "ōẏ", "ōẇ")
	text = gsub(text, "ō̃ẏ", "ō̃ẇ")

	text = gsub(text, "ōẇ$", "ōẏ")
	text = gsub(text, "ōẇ ", "ōẏ ")

	text = gsub(text, "oo", "o")

	if match(text, "") and mode ~= "debug" then
		return nil
	else
		return toNFC(text)
	end
end

return export