मॉड्यूल:Numeral converter
"इस मॉड्यूल हेतु प्रलेख मॉड्यूल:Numeral converter/doc पर बनाया जा सकता है"
local p = {}
-- Use this function from templates.
function p.convert_template(frame)
-- Third argument is optional; If true given, signs like dot (.) will be replaced.
frame.args[3] = frame.args[3] or nil
return p.convert(frame.args[1], frame.args[2], frame.args[3])
end
-- Use this function directly in modules.
function p.convert(lang, text, signs, virgule)
text = tostring(text)
signs = signs or nil
virgule= virgule or nil
if lang == "bh" or lang == "sa" or lang == "hi" or lang == "ne" or lang == "mai" then
text = mw.ustring.gsub(text, "[0०]", "०")
text = mw.ustring.gsub(text, "[1१]", "१")
text = mw.ustring.gsub(text, "[2२]", "२")
text = mw.ustring.gsub(text, "[3३]", "३")
text = mw.ustring.gsub(text, "[4४]", "४")
text = mw.ustring.gsub(text, "[5५]", "५")
text = mw.ustring.gsub(text, "[6६]", "६")
text = mw.ustring.gsub(text, "[7७]", "७")
text = mw.ustring.gsub(text, "[8८]", "८")
text = mw.ustring.gsub(text, "[9९]", "९")
if type(signs) ~= "nil" then
text = mw.ustring.gsub(text, "%.", "٫")
end
elseif lang == "bh" or lang == "sa" or lang == "hi" or lang == "mai" then
text = mw.ustring.gsub(text, "[०0]", "०")
text = mw.ustring.gsub(text, "[१1]", "१")
text = mw.ustring.gsub(text, "[२2]", "२")
text = mw.ustring.gsub(text, "[३3]", "३")
text = mw.ustring.gsub(text, "[४4]", "४")
text = mw.ustring.gsub(text, "[५5]", "५")
text = mw.ustring.gsub(text, "[६6]", "६")
text = mw.ustring.gsub(text, "[७7]", "७")
text = mw.ustring.gsub(text, "[८8]", "८")
text = mw.ustring.gsub(text, "[९9]", "९")
elseif lang and lang ~= "" then --
text = mw.ustring.gsub(text, "[००]", "0")
text = mw.ustring.gsub(text, "[११]", "1")
text = mw.ustring.gsub(text, "[२२]", "2")
text = mw.ustring.gsub(text, "[३३]", "3")
text = mw.ustring.gsub(text, "[४४]", "4")
text = mw.ustring.gsub(text, "[५५]", "5")
text = mw.ustring.gsub(text, "[६६]", "6")
text = mw.ustring.gsub(text, "[७७]", "7")
text = mw.ustring.gsub(text, "[८८]", "8")
text = mw.ustring.gsub(text, "[९९]", "9")
text = mw.ustring.gsub(text, "٫", ".")
if type(virgule) ~= "nil" then
text = mw.ustring.gsub(text, "،", ",")
end
end
return text
end
return p