Jump to content

Module:Flags

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by QuimGil (talk | contribs) at 03:14, 4 June 2013 (test). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

-- FIXME: include a short list of popular flags here (United States, China...) to avoid loading the module just for them
local frequentFlags = {
    
-- Frequent flags globally --
    ["China"] = "",
    ["United States"] = "",

-- Frequent flags in your wiki --
    ["England"] = "",
}

-- Function for assigning values to flags found in tables
function p.flagValues(territory)
    if territory.args[1] == locale or territory.args[1] == english then commonsName = english link = locale end
    end

-- Loading the flag translations module if the flags can't be found in frequentFlags
local translations = require "Module:Sandbox/QuimGil/FlagTranslations"

-- Assigning the parameter to a flag and a link
function p.flag(territory)
-- No border for Nepal or Ohio
-- FIXME: there should be a table of flags without border
    if territory.args[1] == "Nepal" or territory.args[1] == "Ohio" then 
        return '[[File:Flag_of_' .. territory.args[1] .. '.svg|link=' .. territory.args[1] .. '|22x20px]]' end
-- Searching in the translation table.
    for english,locale in pairs(translations.t) do p.flagValues(territory)
    end
-- In the absence of translation for an existing entry, links to the english/original name --
    if commonsName ~= nil and link == '' then link = commonsName end
-- Fallback to Commons when the parameter doesn't have a translation in the table. The flag doesn't have a link, then.    
--    if commonsName == nil then commonsName = territory.args[1] link = territory.args[1] end
    return '[[File:Flag_of_' .. commonsName .. '.svg|border|link=' .. link .. '|22x20px]]'
end
return p