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:39, 4 June 2013 (BACK! Dropping the idea of local table. Having all the flags data in an external module seems to be fine with no big difference.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

-- Loading the flag translations module --
local translations = require "Module:Sandbox/QuimGil/FlagTranslations"

-- Assigning the parameter to a flag and a link
function p.flag(territory)
    border = "border|"
-- No border for Nepal or Ohio
    if territory.args[1] == "Nepal" or territory.args[1] == "Ohio" then border = "" end
-- Searching in the translation table.
    for english,locale in pairs(translations.t) do 
    if territory.args[1] == locale or territory.args[1] == english then commonsName = english link = locale end
    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