FANDOM


--[[<nowiki>
Description: Meta-module that returns a flag filename
Syntax :
]]--
local p ={}
local utility = require("Module:Utility")
local lang = require("Module:lang")
local defaultExtension = ".svg"
local defaultFileSize = "20x20px"
local strlower = string.lower
local mFileLink = require('Module:File link')
 
function p.main(frame)
   local args = utility.getArgs(frame)
   if args and args[1] then
      return p.getFlag(args[1],args[2] or "20x20px", args[3] )
   end
 
end
 
function p.getFlag(sLangCode, sSize, link)
    sLangCode = lang.getLangCode(sLangCode) or sLangCode
    local sLangName = lang.getLang(sLangCode)
    if (sLangName) then
        local sHeaderFlagLink = p.getFileLink('Flag-'
            .. strlower(sLangCode)..defaultExtension,sSize, link or sLangName,sLangName,sLangName)
        return sHeaderFlagLink
    end
end
 
function p.getFileLink(sFileName,sSize,sLink,sCaption,sAlt)
    local sFileLink = mFileLink.main{ 
        file = sFileName,
        size = sSize,link = sLink,
        caption = sCaption,
        alt=sAlt
    }
 
    return sFileLink
end
 
function p.makeFlags(arrayFlags, separator, size) 
    local filePrefix = "[[Flag-"
    local fileSuffix =  defaultExtension.."|".. (size or defaultFileSize) .. "|link=]]"
    separator = separator or " • "
    return  filePrefix .. table.concat(arrayFlags, fileSuffix .. separator..filePrefix ) .. fileSuffix
end
 
return p
--</nowiki>