No edit summary |
No edit summary |
||
Line 10: | Line 10: | ||
if category then | if category then | ||
local link = 'Category:'.. category .. '/' .. flagData.name | local link = 'Category:'.. category .. '/' .. flagData.name | ||
return '<span class="flag">[[' .. flagData.img .. '|' .. flagData.name .. '|link=' .. link .. '|]]</span>' | return '<span class="flag">[[' .. flagData.img .. '|' .. flagData.name .. '|link=' .. link .. '|20px]]</span>' | ||
else | else | ||
return '<span class="flag">[[' .. flagData.img .. '|' .. flagData.name .. ']]</span>' | return '<span class="flag">[[' .. flagData.img .. '|' .. flagData.name .. '|20px]]</span>' | ||
end | end | ||
else | else |
Revision as of 07:09, 10 October 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]
if category then
local link = 'Category:'.. category .. '/' .. flagData.name
return '<span class="flag">[[' .. flagData.img .. '|' .. flagData.name .. '|link=' .. link .. '|20px]]</span>'
else
return '<span class="flag">[[' .. flagData.img .. '|' .. flagData.name .. '|20px]]</span>'
end
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 (flagName == nil or 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