মডিউল:Numeral converter

উইকিঅভিধান, মুক্ত অভিধান থেকে
Jump to navigation Jump to search

এই মডিউলের জন্য মডিউল:Numeral converter/নথি-এ নথিপত্র তৈরি করা হয়ে থাকতে পারে

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 == "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