Module:Country alias
Documentation for this module may be created at Module:Country alias/doc
-- This module returns the country name or the flag name for a country,
-- based on the three-letter IOC/CGA/FINA alias.
--[[
The following country code is used for multiple countries:
ANG (workaround: added ANG_CGF for use with Commonwealth Games)
The following countries have different names/flags based on sport/year
ABL Abovian Union for 15th Olympic cycle and 17th Winter, Aboveland and Nykipiflugpuu in 16th cycle and 18th Winter
APX The Apoxian Federation in 8th Summer to ?, then Apox
ARI Ariddia became Ariddian Isles from 2nd Summer to 4th Summer Olympics, then Ariddia from 5th cycle onwards
BCO Baranxtu became Baranxtu, Cikoutimi, and Otea from 3rd Summer
COM Commerce Heights became Capitalizt SLANI from 2nd Winter
EQS Equestrian States from 8th Summer to ?, then Equestria
LEN Liverpool England became Liventia from 4th Summer Olympics
QUE Quebec and Shingoryeo posts as The Royal Kingdom of Quebec before 15th Summer Olympics.
TSA The Sarian, New Saria (13th Summer-14th Winter) then reverts from 14th Summer.
VIL Vilita; used for Vilita and Turori in 7th Winter
VKL The Greater Vakolicci Haven, competes as Vakolicci Haven and Celeria from (13th Winter-14th Winter), then reverts
The following codes have been used by different countries:
ALB Albertasby in 6th Summer, also used by Alice Bay
AMN Amnarei-asud (11th Summer), also used by A m e n r i a
ANT Antrium, used by Antoletia from 8th Winter
AST Asteran, then Astyrian region from 11th Winter, then Asteran from 15th Summer.
AZC Dummy for Az-cz because Lua cannot accept A-C as a country code; Azulcena in 6th Winter Olympics
EST Estope, Estelar (11th Winter)
FSM Nation of FSM, then The Holy FSM Empire (11th Winter)
HAN Daehanjeiguk in 5th Winter Olympics, used by Hannasea later
JES Jesselton, then Jestoria (11th Winter)
OIS Oiseaui, then Oisinistan (11th Winter)
PAC Pacitalia in 1st Summer, The Pacificana Islands in 9th Winter
PRX Prux, People's Repbulic of Xabia (14th Winter)
XAN Xanonia in 5th Winter Olympics, subsequently used by Xanneria.
RCN Reçueçn, used by RCN Unified Team in 16th Winter Olympics.
SRT Tretrid, used by San Rosito from 15th Winter Olympics
STR Streleheim in 5th Summer Olympics, later used by StrayaRoos
MEG Meguroko in 6th Winter Olympics, also used by Megistos
LCO LancasterCounty, Llama City One in 6th Winter
CAM Candelaria And Marquez, used by Camwood in 6th Summer
IND Inis na Dún in 7th Summer, also claimed by Indo-Malaysia
SCT Sanctaria in 9th Summer, then Schottia, except Scotatrove in 15th Summer
SRB New Serbia (until 7th Summer), The Serbian Empire (10th Summer onwards)
TRL Trellin (11th Summer), Trolleborg (14th Summer)
VIN Virginia Nova, Vinalia from 16th Winter
VLS Valinor Lands, Velstrania (12th Summer)
Real examples:
SWZ Swaziland became Eswatini after the 2018 Commonwealth Games
MKD Macedonia became North Macedonia in 2019
The following countries have multiple aliases due to organizational differences, code changes, or deprecated uses
Albertasby ABT, ALB
Allamunic States FAS, ALS, ACS
Asteran KAS, AST
Bulgislavia RRB, PRB
Camwood CAM, CMD, CMW
Dotivija and Raspotochje DOT, DRU
Edward City USE, EDC
Farfadillis FDS, FFD
Ferkas CKA, CKF
Kannap KAN, KNP
Kernansquillec KER, KRN
Malabra MAB, MLB
New Gelderland NGL, NGD
Schottia SCT, SHA
The Sarian SAR, TSA
Vilita and Turori VIL, VLT
Wentland WEN, WLD
Zwangzug ZGZ, ZWZ
Oddity that needs to be revisited
French Polynesia PYF, TAH - TAH has been converted to Tahiti per SILENCE
]]
local function stripToNil(text)
-- If text is a string, return its trimmed content, or nil if empty.
-- Otherwise return text (which may, for example, be nil).
if type(text) == 'string' then
text = text:match('(%S.-)%s*$')
end
return text
end
local function yes(parameter)
-- Return true if parameter should be interpreted as "yes".
return ({ y = true, yes = true, on = true, [true] = true })[parameter]
end
local function getAlias(args)
-- Return alias parameter, possibly modified for exceptional cases.
local alias = stripToNil(args.alias)
local games = stripToNil(args.games)
local year = tonumber(args.year)
local fullName = stripToNil(args.fullName)
if fullName then
year = tonumber(fullName:match('^%d+')) -- ignore args.year
end
if alias == 'LEN' then
if year and year >3 then
alias = 'LEN'
else
alias = 'LEN_YO1'
end
elseif alias == 'ARI' then
if fullName then
if year and year >= 2 and year <= 4 and fullName ~= '2nd Winter Olympics' then
alias = 'ARI_YO2'
else
alias = 'ARI'
end
end
elseif alias == 'COM' then
if year and year <= 1 then
alias = 'COM_CH'
end
elseif alias == 'BCO' then
if year and year >= 3 then
alias = 'BCO_3SO'
else
alias = 'BCO'
end
elseif alias == 'ANT' then
if year and year >= 8 then
alias = 'ANT_8WO'
else
alias = 'ANT'
end
elseif alias == 'IND' then
if year and year == 7 then
alias = 'IND_7SO'
else
alias = 'IND'
end
elseif alias == 'PAC' then
if year and year == 9 then
alias = 'PAC_9WO'
else
alias = 'IND'
end
elseif alias == 'MEG' then
if year and year <= 6 then
alias = 'MEG_6WO'
else
alias = 'MEG'
end
elseif alias == 'HAN' then
if year and year <= 5 then
alias = 'HAN_5WO'
else
alias = 'HAN'
end
elseif alias == 'XAN' then
if year and year <= 5 then
alias = 'XAN_5WO'
else
alias = 'XAN'
end
elseif alias == 'STR' then
if year and year <= 5 then
alias = 'STR_5SO'
else
alias = 'STR'
end
elseif alias == 'AZC' then
if year and year <= 6 then
alias = 'AZC_6WO'
else
alias = 'AZC'
end
elseif alias == 'LCO' then
if year and year <= 6 then
alias = 'LCO_6WO'
else
alias = 'LCO'
end
elseif alias == 'ALB' then
if year and year <= 6 and fullName ~= '6th Winter Olympics' then
alias = 'ABT'
else
alias = 'ALB'
end
elseif alias == 'CAM' then
if year and year >= 6 then
alias = 'CAM_Camwood'
else
alias = 'CAM'
end
elseif alias == 'VIL' then
if year and year >= 7 then
alias = 'VLT'
else
alias = 'VIL'
end
elseif alias == 'EQS' then
if year and year <= 8 then
alias = 'EQS_8SO'
end
elseif alias == 'APX' then
if year and year <= 8 then
alias = 'APX_8SO'
end
elseif alias == 'SCT' then
if year and year == 9 then
alias = 'SCT_9SO'
elseif year and year == 15 then
alias = 'SCT_15SO'
end
elseif alias == 'EST' then
if year and year >= 11 then
alias = 'EST_11WO'
end
elseif alias == 'FSM' then
if year and year >= 11 then
alias = 'FSM_11WO'
end
elseif alias == 'AST' then
if year and year >= 11 and year < 15 then
alias = 'AST_Astyria'
end
elseif alias == 'JES' then
if year and year >= 11 then
alias = 'JES_11WO'
end
elseif alias == 'OIS' then
if year and year >= 11 then
alias = 'OIS_11WO'
end
elseif alias == 'SRB' then
if year and year > 7 then
alias = 'SRB_Empire'
end
elseif alias == 'KWP' then
if year and year <= 17 then
alias = 'KWP_WEST'
else
alias = 'KWP'
end
elseif alias == 'VLS' then
if year and year >= 12 then
alias = 'VLS_12SO'
end
elseif alias == 'TSA' then
if year and year == 13 then
alias = 'TSA_13SO'
end
elseif alias == 'VKL' then
if year and year == 13 then
alias = 'VKL_13SO'
else
alias = 'VKL'
end
elseif alias == 'PRX' then
if year and year >= 14 then
alias = 'PRX_14WO'
else
alias = 'PRX'
end
elseif alias == 'TRL' then
if year and year >= 14 then
alias = 'TRL_14SO'
end
elseif alias == 'SRT' then
if year and year >= 15 then
alias = 'SRT_15WO'
end
elseif alias == 'RCN' then
if year and year == 16 then
alias = 'RCN_16WO'
end
elseif alias == 'ABL' then
if year and year == 16 then
alias = 'ABL_16WO'
elseif year and year == 18 and fullName ~= '18th Winter Olympics' then
alias = 'ABL_16WO'
else
alias = 'ABL'
end
elseif alias == 'VIN' then
if year and year >= 16 then
alias = 'VIN_16WO'
end
--[[ real examples
elseif alias == 'RUS' then
if year and year==2020 then
if games=='Summer Olympics' then
alias = 'ROC_2020'
elseif games=='Summer Paralympics' then
alias = 'RPC'
end
elseif year and year==2022 and games=='Winter Olympics' then
alias = 'ROC_2020'
end
elseif alias == 'ROC' then
if year and year==1960 and games=='Summer Olympics' then
alias = 'ROC_Formosa'
elseif year and ( year==1964 or year==1968 ) and games=='Summer Olympics' then
alias = 'ROC_Taiwan'
elseif year and year==2020 and games=='Summer Olympics' then
alias = 'ROC_2020'
elseif year and year==2022 and games=='Winter Olympics' then
alias = 'ROC_2020'
elseif year and year==2020 and games=='Summer Paralympics' then
alias = 'RPC'
else
local pageName = mw.title.getCurrentTitle().text
if pageName == 'Russian Olympic Committee athletes at the Olympics' then
alias = 'ROC_2020'
end
end
elseif alias == 'YUG' or alias == 'SCG' then
if year and year > 1992 and year < 2004 and games ~= 'Summer Paralympics' then
alias = 'FR_YUG'
end
elseif alias == 'ZAI' or alias == 'COD' then
if year and year < 1971 then
alias = 'COK_COD'
elseif year and year <= 1996 then
alias = 'ZAI'
else
alias = 'COD'
end
elseif alias == 'COK' then
if year and year == 1968 then
alias = 'COK_COD'
else
alias = 'COK'
end ]]--
end
return alias
end
local function getFlag(args, country)
-- Return name of flag selected from country data (nil if none defined).
local year = tonumber(args.year)
local games = stripToNil(args.games)
if games then
local gdata = country[games]
if gdata then
if type(gdata) == 'string' then
return gdata
end
if gdata[year] then
return gdata[year]
end
if type(gdata[1]) == 'string' then
return gdata[1]
end
end
end
for _, item in ipairs(country) do
if type(item) == 'string' then
return item
end
if year and year <= item[1] then
return item[2]
end
end
end
local data = mw.loadData('Module:Country alias/data')
local function countryAlias(args)
local alias = getAlias(args)
local country = data.countries[alias] or data.countries[data.countryAliases[alias]]
local function quit(message)
return args.error or error(message)
end
if not country then
return quit('Invalid country alias: ' .. tostring(alias))
end
if yes(args.flag) then
return getFlag(args, country) or quit('No flag defined for ' .. alias)
else
return country.name or quit('No name defined for ' .. alias)
end
end
local function flagIOC(frame)
-- Implement {{flagIOC}} which previously called this module three times.
-- Returns <flag> <country link> <athletes>, with the third value optional
local args = frame:getParent().args
local code = stripToNil(args[1]) or error('flagIOC parameter 1 should be a country code')
local games = stripToNil(args[2])
local athletes = stripToNil(args[3])
games = games and (games .. ' Olympics') or 'Olympics'
local parms = {
alias = code,
fullName = games,
year = games:match('^%d+'),
games = games:gsub('^%d+ ?', ''),
}
local fullName = countryAlias(parms)
parms.flag = true
local dispName = fullName
if fullName == 'ROC' then
fullName = 'Russian Olympic Committee athletes'
end
return (('[[File:{flag}|22x20px|border|alt=|link=]] [[{name} at the {games}|{dispName}]]{athletes}')
:gsub('{(%w+)}', {
athletes = athletes and
(' <span style="font-size:90%;">(' .. athletes .. ')</span>') or
'',
flag = countryAlias(parms),
games = games,
name = fullName,
dispName = dispName,
}))
end
local function flagXYZ(frame)
-- Implement {{flagIOC2}} and its variants which previously called this module three times.
-- Returns one of four possible outputs:
-- from flagIOC2: <flag> <country link> <athletes>, with the third value optional
-- from flagIOC2team: <flag> <country link> <country alias>
-- from flagIOC2athlete: <flag> <athlete(s)> <country alias/link>
-- from flagIOC2medalist: <athlete(s)><br><flag> <country link>
local args = frame:getParent().args
local dispType = stripToNil(frame.args['type'])
local code=''
local games=''
local athletes=''
if dispType == 'athlete-O' then
-- Implement [[Template:FlagIOCathlete]].
dispType = 'athlete'
args[3] = (args[3] or '') .. ' Olympics'
end
if dispType == 'name' or dispType == 'team' then
code = stripToNil(args[1]) or error('Parameter 1 should be a country code')
games = stripToNil(args[2]) or ''
athletes = stripToNil(args[3])
elseif dispType == 'athlete' or dispType == 'medalist' then
athletes = stripToNil(args[1]) or error('Parameter 1 should be the name(s) of the athlete(s)')
code = stripToNil(args[2]) or error('Parameter 2 should be a country code')
games = stripToNil(args[3]) or ''
end
local parms = {
alias = code,
fullName = games,
year = games:match('^%d+'),
games = games:gsub('^%d+ ?', ''),
}
local fullName = countryAlias(parms)
parms.flag = true
local dispName = stripToNil(args.name)
if fullName == 'ROC' then
fullName = 'Russian Olympic Committee athletes'
dispName = 'ROC'
if dispType == 'team' then dispType = 'name' end
end
local link = '[[{name} at the {games}|{dispName}]]'
if (games == '') then
link = (dispType == 'athlete') and '<abbr title="{name}">{dispName}</abbr>' or '[[{name}|{dispName}]]'
end
if dispType == 'name' then
return (('[[File:{flag}|22x20px|border|alt=|link=]] '..link..'{athletes}')
:gsub('{(%w+)}', {
athletes = athletes and
(' <span style="font-size:90%;">(' .. athletes .. ')</span>') or
'',
flag = countryAlias(parms),
games = games,
name = fullName,
dispName = dispName or fullName,
}))
elseif dispType == 'team' then
return (('[[File:{flag}|22x20px|border|alt=|link=]] '..link..'{alias}')
:gsub('{(%w+)}', {
alias = (' <span style="font-size:90%;">(' .. code .. ')</span>'),
flag = countryAlias(parms),
games = games,
name = fullName,
dispName = dispName or fullName,
}))
elseif dispType == 'athlete' then
return (('[[File:{flag}|22x20px|border|alt=|link=]] {athletes} <span style="font-size:90%;">('..link..')</span>')
:gsub('{(%w+)}', {
athletes = athletes,
flag = countryAlias(parms),
games = games,
name = fullName,
dispName = code,
}))
elseif dispType == 'medalist' then
return (('{athletes}<br>[[File:{flag}|23x15px|border|alt=|link=]] '..link..'')
:gsub('{(%w+)}', {
athletes = athletes,
flag = countryAlias(parms),
games = games,
name = fullName,
dispName = dispName or fullName,
}))
end
end
local function main(frame)
return countryAlias(frame.args)
end
return {
flagIOC = flagIOC,
flagXYZ = flagXYZ,
main = main,
}