This module will transliterate text in the Devanagari 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:Deva-Beng-translit/testcases.
tr(text, lang, sc)
text
written in the script specified by the code sc
, and language specified by the code lang
.nil
.local export = {}
local twoChars = {
= "অ্যা", = "এ্যা"
}
local oneChar = {
= "ক", = "খ", = "গ", = "ঘ", = "ঙ", = "চ", = "ছ", = "জ", = "ঝ", = "ঞ", = "ট", = "ঠ", = "ড", = "ঢ", = "ণ", = "ত", = "থ", = "দ", = "ধ", = "ন", = "প", = "ফ", = "ব", = "ভ", = "ম", = "য়", = "র", = "ল", = "ল়", = "ব", = "শ", = "ষ", = "স", = "হ",
= "অ", = "আ", = "অ্য", = "ই", = "ঈ", = "উ", = "ঊ", = "ঋ", = "ৠ", = "ঌ", = "ৡ", = "এ্য", = "এ", = "ঐ", = "ও", = "ঔ",
= "া", = "ি", = "ী", = "ু", = "ূ", = "ৃ", = "ৄ", = "ৢ", = "ৣ", = "্য", = "্যা", = "ে", = "ৈ", = "ো", = "ৌ", = "্",
= "ং", = "ঃ", = "ঁ", = "়", = "ঽ", = "৽", = "ঀ", = "ওঁ",
= "০", = "১", = "২", = "৩", = "৪", = "৫", = "৬", = "৭", = "৮", = "৯"
}
-- Override returns text even if some characters cannot be transliterated.
-- If noKhandaTa is set, then "ৎ" will not be contextually substituted for "ত্", which is suitable (e.g.) for Sanskrit transliteration.
function export.tr(text, lang, sc, override, noKhandaTa)
local UTF8_char = "*"
local Beng = require("Module:scripts").getByCode("Beng")
text = mw.ustring.toNFD(text)
for digraph, replacement in pairs(twoChars) do
text = string.gsub(text, digraph, replacement)
end
text = string.gsub(text, "^य", "য")
text = string.gsub(text, "्य", "্য")
text = string.gsub(text, UTF8_char, oneChar)
-- Khanda Ta is not used in Sanskrit.
if not noKhandaTa and lang ~= "sa" then
text = mw.ustring.gsub(text, "ত্()", "ৎ%1")
text = string.gsub(text, "ত্$", "ৎ")
end
text = mw.ustring.toNFC(text)
local reducedText = mw.ustring.gsub(mw.ustring.gsub(text, "<.->", ""), "+", "")
if (mw.ustring.len(reducedText) == Beng:countCharacters(reducedText) and not mw.ustring.find(text, "়়")) or override then
return text
else
return nil
end
end
return export