Модуль:Country alias/пісочниця
![]()
Цей модуль впроваджує сім'ю шаблонів {{country alias}} та {{КраїнаОІ}}. Щодо документації використання, див. сторінки відповідних шаблонів.
ВикористанняШаблон:Country aliasЦей модуль використовується шаблоном {{country alias}}, щоб повертати назву країни або прапор країни на основі поєднання трибуквеного коду країни (обов'язково), року (необов'язково) та змагання, в якому брали участь (необов'язково).
Шаблон:КраїнаОІЦей модуль використовується шаблоном {{flagIOC}}, щоб повертати оформлений прапор країни, назву країни та кількість атлетів (необов'язково), наявних на певному виді Олімпійських ігор.
Шаблон:КраїнаОІ2 та варіантиЦей модуль використовується сімейством шаблонів {{flagIOC2}} (окрім КраїнаОІ, описаного вище), щоб повертати різні оформлені поєднання прапорів країни, назв країн, кількості та/або імен атлетів наявних на певних Іграх.
-- 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 names have different names/flags based on sport/year
Great Britain (and N.I.) GBR, GBR_WCA (latter added to add text in parens)
Hong Kong HKG, HKG_CGF (latter added to keep colonial flag)
Individual Olympic Athletes IOA, IOA_2000 (IOA changed to Independent Olympic Athletes in 2012)
Russian Athletes OAR (2018), ROC_2020 (2020 Summer, 2022 Winter)
SWZ Swaziland became Eswatini after the 2018 Commonwealth Games
MKD Macedonia became North Macedonia in 2019
ART No "Athlete" before Refugee Team @ 2017 AIMAG
D.R. of the Congo Was Zaire (ZAI) and Congo-Kinshasa (COK_COD)
The following countries have multiple aliases due to CGF/IOC/FINA/IAAF/etc differences, or deprecated uses
Anguilla AIA, ANG_CGF
Antigua and Barbuda ANT, ATG
Bahrain BHN, BHR, BRN
Curaçao CUR, CUW
East Timor TLS, TMP
Falkand Islands FAI, FLK
Faroe Islands FAR, FRO
Guernsey GGY, GUE
Iran IRI, IRN
Ireland IRE, IRL - IRE is *only* for CGF apps
Jersey JER, JEY
Lebanon LBN, LIB
Montserrat MNT, MSR
Nicaragua NCA, NIC
Norfolk Island NFI, NFK
Oman OMA, OMN
Refugee Olympic Team ROA, ROT, EOR
Romania ROM, ROU
Saint Helena SHE, SHN
Saint Vincent and the Grenadines SVG, VIN
Sarawak SAR, SWK
Singapore SGP, SIN
South Africa RSA, SAF
Tonga TGA, TON
Trinidad and Tobago TRI, TTO
Turks and Caicos Islands TCA, TCI, TKS
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, t = true, ['так'] = true, ['т'] = true, ['+'] = true, [1] = true, })[parameter]
end
local data = mw.loadData('Module:Country alias/data')
local function getAlias(args)
-- Return alias parameter, possibly modified for exceptional cases.
local alias = stripToNil(args.alias)
local games = stripToNil(args.games)
games = games and (data.gamesAliases[games] or games) or 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 == 'ANG' then
if games == 'Іграх Співдружності' then
alias = 'ANG_CGF'
end
elseif alias == 'ART' then
if games == 'Asian Indoor and Martial Arts Games' then
alias = 'ART_AIMAG'
end
elseif alias == 'GBR' then
if games == 'Чемпіонаті світу з легкої атлетики' or games == 'Чемпіонаті Європи з легкої атлетики' then
alias = 'GBR_WCA'
elseif games == 'Чемпіонаті Європи' then
if year == 2018 then
alias = 'GBR_WCA'
end
end
elseif alias == 'HKG' then
if games == 'Іграх Співдружності' then
alias = 'HKG_CGF'
end
elseif alias == 'IOA' then
if year == 2000 then
alias = 'IOA_2000'
end
elseif alias == 'MAL' or alias == 'MAS' then
if year and year < 1963 then
alias = 'MAL'
else
alias = 'MAS'
end
elseif alias == 'SWZ' then
if fullName then
if year and year >= 2018 and fullName ~= 'Іграх Співдружності 2018' then
alias = 'SWZ_YO2018'
end
elseif year and year >= 2018 and games ~= 'Іграх Співдружності' then
alias = 'SWZ_YO2018'
else
alias = 'SWZ_YO2018'
end
elseif alias == 'MKD' then
if year and year < 2019 then
alias = 'MKD'
else
alias = 'MKD_2019'
end
elseif alias == 'VNM' then
if year and year <= 1954 then
alias = 'VIE'
end
elseif alias == 'RUS' then
if year and year==2020 then
if games=='літніх Олімпійських іграх' then
alias = 'ROC_2020'
elseif games=='літніх Паралімпійських іграх' then
alias = 'RPC'
end
elseif year and year==2022 and games=='зимових Олімпійських іграх' then
alias = 'ROC_2020'
end
elseif alias == 'ROC' then
if year and year==1960 and games=='літніх Олімпійських іграх' then
alias = 'ROC_Formosa'
elseif year and ( year==1964 or year==1968 ) and games=='літніх Олімпійських іграх' then
alias = 'ROC_Taiwan'
elseif year and year==2020 and games=='літніх Олімпійських іграх' then
alias = 'ROC_2020'
elseif year and year==2022 and games=='зимових Олімпійських іграх' then
alias = 'ROC_2020'
elseif year and year==2020 and games=='літніх Паралімпійських іграх' then
alias = 'RPC'
else
local pageName = mw.title.getCurrentTitle().text
if pageName == 'Олімпійський комітет Росії на Олімпійських іграх' then
alias = 'ROC_2020'
end
end
elseif alias == 'YUG' or alias == 'SCG' then
if year and year > 1992 and year < 2004 and games ~= 'літніх Паралімпійських іграх' 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[data.gamesAliases[games] or 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 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('Недійсний псевдонім країни: ' .. tostring(alias))
end
if yes(args.flag) then
return getFlag(args, country) or quit('Не визначено прапор для ' .. alias)
else
return country.name or quit('Не визначено назву для ' .. alias)
end
end
local function flagIOC(frame)
-- Implement {{flagIOC}} which previously called this module three times.
-- Returns <flag> <country link> <year> <add olimpics> <no flag> <alternative name> <athletes> <number of men> <number of women>, with third—nine values optional
local args = frame:getParent().args
local code = stripToNil(args[1]) or error('Параметр 1 шаблону КраїнаОІ повинен бути кодом країни')
local gamesType = stripToNil(args.gamesType)
local games = stripToNil(args[2])
local year = stripToNil(args[3])
local addOlimpics = yes(args[4])
local hideFlag = yes(args[5])
local alternativeName = stripToNil(args[6])
local season
if games and not year then
year = games:match('^%d+')
season = games:gsub('^%d+ ?', '')
end
local athletes = stripToNil(args[7])
local aMen = stripToNil(args[8])
local aWomen = stripToNil(args[9])
if aMen then
athletes = athletes .. ': чоловіків — ' .. aMen .. '; жінок — ' .. aWomen
end
games = games and ((data.gamesAliases[season or games] or games) .. ' Олімпійських іграх' .. (year and (' ' .. year) or '')) or 'Олімпійських іграх'
local parms = {
alias = code,
fullName = games,
year = year,
games = games:gsub('%s*%d+$', ''),
}
local fullName = alternativeName or countryAlias(parms)
parms.flag = true
local dispName = fullName
if fullName == 'ROC' then
fullName = 'Олімпійський комітет Росії'
end
local returnText = (hideFlag and '' or '[[File:{flag}|22x20px|border|alt=|link=]] ') .. '[[{name} на {games}'.. (addOlimpics and '' or '|{dispName}')..']]{athletes}'
return (returnText: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('Параметр 1 повинен бути кодом країни')
games = stripToNil(args[2]) or ''
athletes = stripToNil(args[3])
elseif dispType == 'athlete' or dispType == 'medalist' then
athletes = stripToNil(args[1]) or error('Параметр 1 повинен бути назвою(-ами) атлета(-ів)')
code = stripToNil(args[2]) or error('Параметр 2 повинен бути кодом країни')
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 = 'Олімпійський комітет Росії'
dispName = 'ROC'
if dispType == 'team' then dispType = 'name' end
end
local link = '[[{name} на {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,
}
|
Portal di Ensiklopedia Dunia