پودمان:Country alias

توضیحات پودمان

این پودمان، الگوی {{نام مستعار کشور}} و الگوهای خانوادهٔ {{flagIOC2}} را پیاده‌سازی می‌کند. برای مستندان کاربرد این الگوها، صفحهٔ خود الگوها را ببینید.

استفاده

الگو:نام مستعار کشور

الگوی {{نام مستعار کشور}} از این پودمان برای برگرداندن نام کشور یا پرچم کشور بر پایه ترکیبی از شناسهٔ سه‌حرفی کشور (الزامی)، سال (اختیاری) و بازی‌های ورزشی مورد نظر (اختیاری) استفاده می‌کند.

{{#invoke:Country alias|main|alias=|flag=|games=|year=}}

الگو:FlagIOC

الگوی {{flagIOC}}، برای برگرداندن پرچم قالب‌بندی‌شدهٔ کشور، نام کشور و تعداد ورزشکاران حاضر (اختیاری) در یک نسخهٔ مشخص از بازی‌های المپیک، از این پودمان استفاده می‌کند.

{{#invoke:Country alias|flagIOC|alias=|flag=|games=|year=|athletes=}}

الگو:FlagIOC2 و اعضای خانوادهٔ آن

خانوادهٔ الگوهای {{flagIOC2}} (به‌جز flagIOC که در بالا توضیح داده‌شد) برای برگرداندن ترکیب‌های قالب‌بندی‌شدهٔ مختلف از پرچم کشور، نام کشور، تعداد ورزشکاران حاضر و/یا نام ورزشکاران حاضر در یک دوره بازی‌های مشخص، از این پودمان استفاده می‌کند.

{{#invoke:Country alias|flagXYZ|alias=|flag=|games=|year=|athletes=|type=}}

-- 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 AIMAGThe 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    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, TKSOddity that needs to be revisited    French Polynesia                 PYF, TAH - TAH has been converted to Tahiti per SILENCE]]local num_con = require('Module:Numeral converter').convertlocal 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' thentext = mw.ustring.match(text, '(%S.-)%s*$')endreturn textendlocal function yes(parameter)-- Return true if parameter should be interpreted as "yes".return ({ y = true, yes = true, on = true, [true] = true })[parameter]endlocal function getAlias(args)-- Return alias parameter, possibly modified for exceptional cases.local alias = stripToNil(args.alias)local games = stripToNil(args.games)local year = mw.getContentLanguage():parseFormattedNumber(args.year)local fullName = stripToNil(args.fullName)if fullName thenyear = mw.getContentLanguage():parseFormattedNumber(mw.ustring.match(fullName, '%d+$'))  -- ignore args.yearendif alias == 'ANG' thenif games == 'بازی‌های کشورهای همسود' thenalias = 'ANG_CGF'endelseif alias == 'ART' thenif games == 'بازی‌های آسیایی داخل سالن و هنرهای رزمی' thenalias = 'ART_AIMAG'endelseif alias == 'GBR' thenif games == 'مسابقات جهانی دو و میدانی' or games == 'مسابقات قهرمانی دو و میدانی اروپا' thenalias = 'GBR_WCA'elseif games == 'مسابقات اروپا' thenif year == 2018 thenalias = 'GBR_WCA'endendelseif alias == 'HKG' thenif games == 'بازی‌های کشورهای همسود' thenalias = 'HKG_CGF'endelseif alias == 'IOA' thenif year == 2000 thenalias = 'IOA_2000'endelseif alias == 'MAL' thenif year and year > 1963 thenalias = 'MAS'endelseif alias == 'SWZ' thenif fullName thenif year and year >= 2018 and fullName ~= 'بازی‌های کشورهای همسود ۲۰۱۸' thenalias = 'SWZ_YO2018'endelseif year and year >= 2018 and games ~= 'بازی‌های کشورهای همسود' thenalias = 'SWZ_YO2018'elsealias = 'SWZ_YO2018'endelseif alias == 'MKD' thenif year and year < 2019 thenalias = 'MKD'elsealias = 'MKD_2019'endelseif alias == 'VNM' thenif year and year <= 1954 thenalias = 'VIE'endelseif alias == 'ROC' or alias == 'RUS' thenif year and year==2020 and games=='بازی‌های المپیک تابستانی' thenalias = 'ROC_2020'elseif year and year==2022 and games=='بازی‌های المپیک زمستانی' thenalias = 'ROC_2020'elseif year and year==2020 and games=='بازی‌های پارالمپیک تابستانی' thenalias = 'RPC'endendreturn aliasendlocal function getFlag(args, country)-- Return name of flag selected from country data (nil if none defined).local year = mw.getContentLanguage():parseFormattedNumber(args.year)local games = stripToNil(args.games)if games thenlocal gdata = country[games]if gdata thenif type(gdata) == 'string' thenreturn gdataendif gdata[year] thenreturn gdata[year]endendendfor _, item in ipairs(country) doif type(item) == 'string' thenreturn itemendif year and year <= item[1] thenreturn item[2]endendendlocal 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)endif not country thenreturn quit('نام مستعار کشور نامعتبر: ' .. tostring(alias))endif yes(args.flag) thenreturn getFlag(args, country) or quit('پرچمی برای ' .. alias .. ' تعریف نشده‌است')elsereturn country.name or quit('نامی برای ' .. alias .. ' تعریف نشده‌است')endendlocal function flagIOC(frame)-- Implement {{flagIOC}} which previously called this module three times.-- Returns <flag> <country link> <athletes>, with the third value optionallocal args = frame:getParent().argslocal 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) or 'بازی‌های المپیک'local parms = {alias = code,fullName = games,year = mw.getContentLanguage():parseFormattedNumber(mw.ustring.match(games, '%d+$')),games = mw.ustring.gsub(games, '%d+$', ''),}local fullName = countryAlias(parms)parms.flag = truereturn (('[[File:{flag}|22x20px|border|alt=|link=]]&nbsp;[[{name} در {games}|{name}]]{athletes}'):gsub('{(%w+)}', {athletes = athletes and('&nbsp;<span style="font-size:90%;">(' .. athletes .. ')</span>') or'',flag = countryAlias(parms),games = games,name = fullName,}))endlocal 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().argslocal dispType = stripToNil(frame.args['type']) or stripToNil(frame.args['نوع'])local code=''local games=''local athletes=''if dispType == 'name' or dispType == 'نام' or dispType == 'team' or dispType == 'تیم' thencode = stripToNil(args[1]) or error('پارامتر اول باید شامل شناسهٔ کشور باشد')games = stripToNil(args[2]) or error('پارامتر دوم باید شامل نام یک رقابت باشد')athletes = stripToNil(args[3])elseif dispType == 'athlete' or dispType == 'ورزشکار' or dispType == 'medalist' or dispType == 'مدال‌آور' thenathletes = stripToNil(args[1]) or error('پارامتر اول باید شامل نام(های) ورزشکار(ها) باشد')code = stripToNil(args[2]) or error('پارامتر دوم باید شامل شناسهٔ کشور باشد')games = stripToNil(args[3]) or error('پارامتر دوم باید شامل نام یک رقابت باشد')endlocal dispName = stripToNil(args.name) or stripToNil(args['نام'])local parms = {alias = code,fullName = games,year = mw.getContentLanguage():parseFormattedNumber(mw.ustring.match(games, '%d+$')),games = mw.ustring.gsub(games, ' ?%d+$', ''),}local fullName = countryAlias(parms)parms.flag = trueif dispType == 'name' or dispType == 'نام' thenreturn (('[[File:{flag}|22x20px|border|alt=|link=]]&nbsp;[[{name} در {games}|{dispName}]]{athletes}'):gsub('{(%w+)}', {athletes = athletes and('&nbsp;<span style="font-size:90%;">(' .. athletes .. ')</span>') or'',flag = countryAlias(parms),games = games,name = fullName,dispName = dispName or fullName,}))elseif dispType == 'team' or dispType == 'تیم' thenreturn (('[[File:{flag}|22x20px|border|alt=|link=]]&nbsp;[[{name} در {games}|{dispName}]]{alias}'):gsub('{(%w+)}', {alias = ('&nbsp;<span style="font-size:90%;">(' .. code .. ')</span>'),flag = countryAlias(parms),games = games,name = fullName,dispName = dispName or fullName,}))elseif dispType == 'athlete' or dispType == 'ورزشکار' thenreturn (('[[File:{flag}|22x20px|border|alt=|link=]]&nbsp;{athletes}&nbsp;<span style="font-size:90%;">([[{name} در {games}|{dispName}]])</span>'):gsub('{(%w+)}', {athletes = athletes,flag = countryAlias(parms),games = games,name = fullName,dispName = code,}))elseif dispType == 'medalist' or dispType == 'مدال‌آور' thenreturn (('{athletes}<br>[[File:{flag}|23x15px|border|alt=|link=]]&nbsp;[[{name} در {games}|{dispName}]]'):gsub('{(%w+)}', {athletes = athletes,flag = countryAlias(parms),games = games,name = fullName,dispName = dispName or fullName,}))endendlocal function main(frame)return countryAlias(frame.args)endreturn {flagIOC = flagIOC,flagXYZ = flagXYZ,main = main,}