ᱢᱳᱰᱩᱞ:Numeral converter

ᱣᱤᱠᱤᱯᱤᱰᱤᱭᱟ, ᱨᱟᱲᱟ ᱜᱮᱭᱟᱱ ᱯᱩᱛᱷᱤ ᱠᱷᱚᱱ

Documentation for this module may be created at ᱢᱳᱰᱩᱞ: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_cordination(text)
  text = tostring(text)
  text = mw.ustring.gsub(text, "ᱠᱚᱸᱭᱮ", "N")
  text = mw.ustring.gsub(text, "ᱥᱟᱢᱟᱝ", "E")
  text = mw.ustring.gsub(text, "ᱮᱛᱚᱢ", "S")
  text = mw.ustring.gsub(text, "ᱯᱟᱪᱮ", "W")
  return text
end

function p.convert(lang, text, signs, virgule)
  text = tostring(text)
  signs = signs or nil
  virgule= virgule or nil

  if lang == "bn" or lang == "as" or lang == "bpy" or lang == "glk" 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 == "bn" or lang == "as" or lang == "bpy" 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