پودمان:الگوی یکسان به زبان دیگر

    از ویکی‌نور

    توضیحات این پودمان می‌تواند در پودمان:الگوی یکسان به زبان دیگر/توضیحات قرار گیرد.

    -- این پودمان برای [[الگو:جعبه پیام الگوی یکسان انگلیسی و فارسی]] است.
    local messageBox = require("Module:Message box").main
    local getArgs = require("Module:Arguments").getArgs
    
    return {
      main = function(frame)
        local currentTitle, args
    
        currentTitle = mw.title.getCurrentTitle()
        args = getArgs(
        	frame, 
        	{
        		trim = true, 
        		removeBlanks = true,
        		parentOnly = true,
        		wrappers = "الگو:الگوی یکسان به زبان دیگر",
        		noOverwrite = true,
        		valueFunc = function(_, value)
        			return mw.ustring.gsub(value, "الگو:", "")
    			end
    		}
    	)
    
        -- 10 is template namespace
        if currentTitle:inNamespace(10) then
          if type(args[1]) ~= "nil" and mw.title.new(args[1], 10).exists then
            local text, templateIs, templateIn
    
            text = "این الگوی "
    
            if mw.ustring.match(currentTitle.text, "[a-zA-Z]") then
              templateIs = "انگلیسی"
              templateIn = "فارسی"
            else
              templateIs = "فارسی"
              templateIn = "انگلیسی"
            end
    
            text = text .. templateIs .. " [[الگو:" .. args[1] .. "|نمونهٔ " .. templateIn .."]] دارد که تمام پارامترهایش " .. templateIn .. " است."
    
            if templateIn == "فارسی" then
              text = text .. " توصیه می‌کنیم از الگوی فارسی استفاده کنید."
            end
    
            -- Add category into persian templates have similar template in English.
            if templateIs == "فارسی" then
              text = text .. "[[رده:دارای الگوی یکسان به زبان دیگر]]"
            end
    
            return messageBox("ombox", {text=text})
          else
            error("الگوی مقصد یا مشخص نشده‌است یا در فضای نام الگو قرار ندارد")
          end
        else
          error("الگوی {{الگوی|الگوی یکسان به زبان دیگر}} فقط در فضای نام الگو استفاده می‌شود")
        end
      end
    }