(Created page with "local MasterData = mw.loadData('Module:Flags/MasterData') local Template = require('Module:Template') local Logic = require('Module:Logic') local Table = require('Module:Table') local String = require('Module:StringUtils') local FnUtil = require('Module:FnUtil') local Class = require('Module:Class') local Flags = {} -- Returns a flag --[[ supported args are: flag - country name, flag code, or alias of the Flag shouldLink - boolean that decides if the flag should link...") |
No edit summary |
||
Line 1: | Line 1: | ||
local MasterData = mw.loadData('Module:Flags/MasterData') | local MasterData = mw.loadData('Module:Flags/MasterData') | ||
local Flags = {} | local Flags = {} | ||
function Flags.icon(flagString, category) | |||
function Flags. | |||
local flagKey = Flags._convertToKey(flagString) | |||
if flagKey then | if flagKey then | ||
local flagData = MasterData.data[flagKey] | local flagData = MasterData.data[flagKey] | ||
local link = 'Category:'.. category .. '/' .. flagData.name | |||
return '<span class="flag">[[' .. flagData.img .. | |||
'|' .. flagData.name .. '|link=' .. link .. '|]]</span>' | |||
else | |||
'|' .. flagData.name .. '|link=' .. link | |||
else | |||
mw.log('Unknown flag: ', flagName) | mw.log('Unknown flag: ', flagName) | ||
return | return false | ||
end | end | ||
end | end | ||
Line 88: | Line 34: | ||
end | end | ||
function Flags._convertToKey(flagName) | function Flags._convertToKey(flagName) | ||
flagName = flagName:gsub(' ', ''):lower() | flagName = flagName:gsub(' ', ''):lower() | ||
Line 153: | Line 43: | ||
end | end | ||
return Flags | |||
return |
Revision as of 07:13, 25 August 2022
Documentation for this module may be created at Module:Flags/doc
local MasterData = mw.loadData('Module:Flags/MasterData')
local Flags = {}
function Flags.icon(flagString, category)
local flagKey = Flags._convertToKey(flagString)
if flagKey then
local flagData = MasterData.data[flagKey]
local link = 'Category:'.. category .. '/' .. flagData.name
return '<span class="flag">[[' .. flagData.img ..
'|' .. flagData.name .. '|link=' .. link .. '|]]</span>'
else
mw.log('Unknown flag: ', flagName)
return false
end
end
-- Converts a country name, flag code, or alias to a standardized country name
function Flags.CountryName(flagName)
if String.isEmpty(flagName) then
return ''
end
local flagKey = Flags._convertToKey(flagName)
if flagKey then
return MasterData.data[flagKey].name
else
mw.log('Unknown flag: ', flagName)
return mw.text.trim(mw.text.split(Template.safeExpand(mw.getCurrentFrame(), 'Flag/' .. flagName), '|', true)[2] or '')
end
end
function Flags._convertToKey(flagName)
flagName = flagName:gsub(' ', ''):lower()
return MasterData.twoLetter[flagName]
or MasterData.threeLetter[flagName]
or MasterData.aliases[flagName]
or (MasterData.data[flagName] and flagName)
end
return Flags