The following is the personal copy of the code I have used in Bengali transliteration.
-- Transliteration for Bengali
local export = {}
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local conv = {
-- consonants
= "k", = "kh", = "g", = "gh", = "ṅ",
= "c", = "ch", = "j", = "jh", = "ñ",
= "ṭ", = "ṭh", = "ḍ", = "ḍh", = "ṇ",
= "t", = "th", = "d", = "dh", = "n",
= "p", = "ph", = "b", = "bh", = "m",
= "ĵ", = "r", = "l",
= "ś", = "ṣ", = "s", = "h",
= "ẏ", = "ṛ", = "ṛh", = "z",
-- vowel diacritics
= "i", = "u",
= "r̥", = "e", = "ō",
= "a", = "ī", = "ū", = "ōi", = "ōu",
-- archaic vowel diacritics
= "r̥̄", = "l̥", = "l̥̄",
-- visarga
= "ḥ",
-- vowel signs
= "o", = "i", = "u",
= "r̥", = "e", = "ō",
= "a", = "ī", = "ū", = "ōi", = "ōu",
-- archaic vowel diacritics
= "r̥̄", = "l̥", = "l̥̄",
--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 function rev_string(text)
local result, length = "", mw.ustring.len(text)
for i = 1, length do
result = result .. mw.ustring.sub(text, length - i + 1, length - i + 1)
end
return result
end
function export.tr(text, lang, sc, mode)
text = gsub(text, "݁", "্অ")
text = gsub(text, "", "্")
text = gsub(text, "ঃ", "্ḥ")
text = gsub(text, "টি" , "্টি")
text = gsub(text, "কার" , "্কার")
text = gsub(text, "খানা" , "্খানা")
text = gsub(text, "ডাল" , "্ডাল")
text = gsub(text, "খানি" , "্খানি")
text = gsub(text, "জন" , "্জন")
text = gsub(text, "সকল" , "্সকল")
text = gsub(text, "কে" , "্কে")
text = gsub(text, "ফল" , "্ফল")
text = gsub(text, "কেই" , "্কেই")
text = gsub(text, "মান" , "্মান")
text = gsub(text, "(" .. c .. "়?)(?)", function(a, b)
return a .. (b == "" and "o" or b) end)
for word in mw.ustring.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, "()্য", "%1y")
text = gsub(text, "্ব", "v")
text = gsub(text, ".?", conv)
text = gsub(text, ".", conv)
text = gsub(text, "()v", "%1b")
text = gsub(text, "hv", "hb")
text = gsub(text, "kṣ", "ḳh")
text = gsub(text, "jñ", "ġy")
text = gsub(text, "ry", "rĵ")
text = gsub(text, "nḍo$", "nḍ")
text = gsub(text, "()h$", "%1ho")
text = gsub(text, "()aho$", "%1ah")
text = gsub(text, "^oya", "æ")
text = gsub(text, "^eya", "æ")
text = gsub(text, "ẏo()()", "ẏ%1%2")
text = gsub(text, "oō$", "ō")
text = gsub(text, "()ẏ", "%1ẏo")
if match(text, "") and mode ~= "debug" then
return nil
else
return mw.ustring.toNFC(text)
end
end
return export