Jump to content

ᥛᥨᥝᥱ ᥓᥧᥰ: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(lang, text, signs, virgule)
  text = tostring(text)
  signs = signs or nil
  virgule= virgule or nil

  if lang == "shn" 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 == "shn" 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