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-Bhks-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 char = {
= "𑰎", = "𑰏", = "𑰐", = "𑰑", = "𑰒", = "𑰓", = "𑰔", = "𑰕", = "𑰖", = "𑰗", = "𑰘", = "𑰙", = "𑰚", = "𑰛", = "𑰜", = "𑰝", = "𑰞", = "𑰟", = "𑰠", = "𑰡", = "𑰢", = "𑰣", = "𑰤", = "𑰥", = "𑰦", = "𑰧", = "𑰨", = "𑰩", = "𑰪", = "𑰫", = "𑰬", = "𑰭", = "𑰮",
= "𑰀", = "𑰁", = "𑰂", = "𑰃", = "𑰄", = "𑰅", = "𑰆", = "𑰇", = "𑰈", = "𑰊", = "𑰋", = "𑰌", = "𑰍",
= "𑰯", = "𑰰", = "𑰱", = "𑰲", = "𑰳", = "𑰴", = "𑰵", = "𑰶", = "𑰸", = "𑰹", = "𑰺", = "𑰻", = "𑰿",
= "𑰽", = "𑰾", = "𑰼", = "𑱀", = "𑰌𑰼", = "𑱁", = "𑱂",
= "𑱐", = "𑱑", = "𑱒", = "𑱓", = "𑱔", = "𑱕", = "𑱖", = "𑱗", = "𑱘", = "𑱙"
}
-- Override returns text even if some characters cannot be transliterated.
function export.tr(text, lang, sc, override)
local UTF8_char = "*"
local Bhks = require("Module:scripts").getByCode("Bhks")
text = string.gsub(text, UTF8_char, char)
text = mw.ustring.gsub(text, "() ()", "%1𑱃%2")
local reducedText = mw.ustring.gsub(mw.ustring.gsub(text, "<.->", ""), "+", "")
if mw.ustring.len(reducedText) == Bhks:countCharacters(reducedText) or override then
return text
else
return nil
end
end
return export