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-Mlym-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.
function export.tr(text, lang, sc, override)
local UTF8_char = "*"
local Mlym = require("Module:scripts").getByCode("Mlym")
text = mw.ustring.toNFD(text)
for digraph, replacement in pairs(twoChars) do
text = string.gsub(text, digraph, replacement)
end
text = string.gsub(text, UTF8_char, oneChar)
text = mw.ustring.toNFC(text)
local reducedText = mw.ustring.gsub(mw.ustring.gsub(text, "<.->", ""), "+", "")
if mw.ustring.len(reducedText) == Mlym:countCharacters(reducedText) or override then
return text
else
return nil
end
end
return export