مۆدیوول:Numeral converter2

لە ئینسایکڵۆپیدیای ئازادی ویکیپیدیاوە
بەڵگەدارکردنی مۆدیوول[دروست بکە]
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 these function directly in modules.

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

  if lang == "ckb" 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, "ISBN ", "")	
    --تبدیل نقطه به «٫» را به دلیل ایجاد مشکل در فارسی‌سازی برخی شناسه‌ها که نقطه دارند حذف کردم
    if type(signs) ~= "nil" then
      text = mw.ustring.gsub(text, "%.", "٫")
      --I did not convert % to ٪ because it may destroy the "percentage codes" entered into our module.
    end
  elseif lang == "fa" or lang == "ur" or lang == "mzn" 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٩]", "۹")
--    text = mw.ustring.gsub(text, "ISBN ", "")	
    --تبدیل نقطه به «٫» را به دلیل ایجاد مشکل در فارسی‌سازی برخی شناسه‌ها که نقطه دارند حذف کردم
    if type(signs) ~= "nil" then
      text = mw.ustring.gsub(text, "%.", "٫")
      --I did not convert % to ٪ because it may destroy the "percentage codes" entered into our module.
    end
  elseif lang == "en" 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, "٫", ".")
    text = mw.ustring.gsub(text, "٪", "%")
  end

  return text
end

return p