Module:Flags
Appearance
All the logics of Template:Flags are handled here. This module works together with Module:Flags/MasterData and Module:Flags/LocaleData, where the flags data is maintained.
Features
Functionality implemented:
- Full name in English or the locale language: "Andorra". Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found.
- 2 letter code - link points to full name: "AD" Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found.
- 3 letter code - link points to full name: "AND" Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found.
- Nepal and Ohio flags are shown without border.
- When a name is not found in the list, attempts to offer a Commons image and a link e.g. "Berlin" or "WHO". Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found. Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found.
- Size as in "size=44px" or "size=40x44px" can be defined in any position. Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found.
- Nepal, Switzerland and Vatican City have a default size of 20x17px (for the rest it's 20x22px):
Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found. Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found.
- Variants for historical flags "1901" Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found. or "variant=1901" (for compatibility reasons) Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found.
- Variants for labeled flags: "naval", "air force" and any other specified at FlagTranslations: "civil" Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found. - "naval-RMAS" Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found.
- Variant / label flags not found in FlagTranslations return the Flag of None but still point to the right article: "whatever"
- "quatsch" Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found.
- Redirects (different names pointing to a same flag) are supported: "GB" Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found. - "UK" Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found.
- Full Commons filenames can be defined in tables when they don't follow the "Flag of " syntax: "File:Flag Belgium brussels" Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found.
- Localization: "Illes Balears" Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found. - "中華人民共和國" Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found.
- Localization + variants: "Afganistan" + "1901" Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found. - "Regne Unit" + "civil" Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found.
- Flags listed only in FlagTranslations always link to the local language article: parameter "Native Peoples of Colombia" Lua error in package.lua at line 80: module 'Module:Sandbox/QuimGil/FlagTranslations' not found. links to "Pueblos Indígenas de Colombia"
Roadmap
- Performance testing.
- Extensive testing with copies of real pages, also for non-Latin scripts and Right-to-left languages.
- Cover the rest of functionality offered by other flag templates.
- Allow editors to define the year of the event, leaving to the template the task of finding the right flag.
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"] = "",
}
-- 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)
-- 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
-- Search in the frequentFlags table.
for english,locale in pairs(frequentFlags) do
if territory.args[1] == locale or territory.args[1] == english then commonsName = english link = locale end
end
-- If still not found, search in the translations.t table.
if commonsName == nil then
local translations = require "Module:Sandbox/QuimGil/FlagTranslations"
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 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