Module:Flag
|
|
This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
|
|
This template is used on many pages, and changes to it will be widely noticed. Please test any changes in the template's /sandbox or /testcases subpages, or in a user subpage, and consider discussing changes at the talk page before implementing them. |
Lua error in Module:Lua_banner at line 113: attempt to index field 'edit' (a nil value). Lua-native alternative to popular flag templates. Can be used to reduce post-expand include size of pages with lots of templates, since it avoids calling multilevel templates.
Usage
[সম্পাদনা কৰক]Generic flag templates
[সম্পাদনা কৰক]- {{flag}} → {{#invoke:flag|}}
- {{flag country}} → সাঁচ:Ml
- {{flag decoration}} (or {{flagdeco}}) → সাঁচ:Ml (or সাঁচ:Ml)
- {{flag icon}} → সাঁচ:Ml
- {{flag link}} → সাঁচ:Ml
- {{flag+link}} → সাঁচ:Ml
- {{flag list}} → সাঁচ:Ml
Sports flag templates
[সম্পাদনা কৰক]- {{flag athlete}} → সাঁচ:Ml
- {{flag medalist}} → সাঁচ:Ml
- {{flag team}} → সাঁচ:Ml
- {{flag IOC}} → সাঁচ:Ml
- {{flag IOC 2}} → সাঁচ:Ml
- {{flag IOC athlete}} → সাঁচ:Ml
- {{fb}} → সাঁচ:Ml
- {{fba}} → সাঁচ:Ml
- {{fb-rt}} → সাঁচ:Ml
- {{fbicon}} → সাঁচ:Ml
- {{fbaicon}} → সাঁচ:Ml
- {{ru}} → সাঁচ:Ml
Examples
[সম্পাদনা কৰক]! colspan=3| Template !! colspan=3| Module
|-
! Code !! Output !! PEIS !! Code !! Output !! PEIS
|-
| {{flag|CHN}} ||
চীন || 443b || সাঁচ:Mlx || Lua error in package.lua at line 80: module 'Module:CountryData/cacheB' not found. || 128b
|-
| {{flag country|CHN}} || সাঁচ:Flag country || 577b || সাঁচ:Mlx || Lua error in package.lua at line 80: module 'Module:CountryData/cacheB' not found. || 128b
|-
| {{flag decoration|CHN}}/{{flag deco|CHN}} || সাঁচ:Flag deco || 452b || সাঁচ:Mlx/সাঁচ:Mlx || Lua error in package.lua at line 80: module 'Module:CountryData/cacheB' not found. || 107b
|-
| {{flag icon|CHN}} ||
|| 548b || সাঁচ:Mlx || Lua error in package.lua at line 80: module 'Module:CountryData/cacheB' not found. || 117b
|-
| {{flag link|CHN|at the 2004 Summer Olympics}} || সাঁচ:Flag link || 497b || সাঁচ:Mlx || Lua error in package.lua at line 80: module 'Module:CountryData/cacheB' not found. || 198b
|-
| {{flag+link|History of|CHN}} || সাঁচ:Flag+link || 663b || সাঁচ:Mlx || Lua error in package.lua at line 80: module 'Module:CountryData/cacheB' not found. || 139b
|-
| {{flag list|SWI}} || সাঁচ:Flag list || 685b || সাঁচ:Mlx || Lua error in package.lua at line 80: module 'Module:CountryData/cacheB' not found. || 254b
|-
| {{flag team|GBR}} || সাঁচ:Flag team || 804b || সাঁচ:Mlx ||
গ্ৰেট ব্ৰিটেইন (GBR) || 193b
|-
| {{flag athlete|Andy Murray|GBR}} || সাঁচ:Flag athlete || 617b || সাঁচ:Mlx ||
Andy Murray (GBR) || 210b
|-
| {{flag medalist|Andy Murray|GBR}} || সাঁচ:Flag medalist || 469b || সাঁচ:Mlx || Andy Murray
গ্ৰেট ব্ৰিটেইন || 129b
|-
| {{flag IOC|CAN|1924 Winter|1}} || সাঁচ:Flag IOC || 326b || সাঁচ:Mlx ||
Canada (1) || 163b
|-
| {{flag IOC 2|HKG|1954 Asian Games|1}} || সাঁচ:Flag IOC 2 || 368b || সাঁচ:Mlx ||
Hong Kong (1) || 184b
|-
| {{flag IOC athlete|Mark Spitz|USA|1972 Summer}} || সাঁচ:Flag IOC athlete || 346b || সাঁচ:Mlx ||
Mark Spitz (USA) || 178b
|-
| {{fb|CHN}} ||
চীন || 560b || সাঁচ:Mlx ||
চীন || 151b
|-
| {{fb-rt|CHN}} || গণচীন
|| 482b || সাঁচ:Mlx || চীন
|| 151b
|-
| {{fbicon|CHN}} ||
|| 444b || সাঁচ:Mlx ||
|| 163b
|-
| {{fba|CHN}} || সাঁচ:Fba || 625b || সাঁচ:Mlx || Lua error in package.lua at line 80: module 'Module:Fba/list' not found. || 149b
|-
| {{fbaicon|CHN}} || সাঁচ:Fbaicon || 500b || সাঁচ:Mlx || Lua error in package.lua at line 80: module 'Module:Fba/list' not found. || 159b
|-
| {{ru|CHN}} || সাঁচ:Ru || 646b || সাঁচ:Mlx ||
চীন || 210b
|}
Caveats
[সম্পাদনা কৰক]When used inside a template, parameters from that template are passed to the module. This can be useful in some situations, but can lead to conflicts (for example, if the parent template has a parameter |country= that is unrelated to the flag it is supposed to display). To prevent this behavior, add the |frameonly= parameter to the module call, e.g. সাঁচ:Mlx.
local margs = require('Module:Arguments')
local function _main(frame, name, mode, key)
local categories = {
['Flag icon'] = '[[Category:Flag icons missing country data templates]]{{Preview warning|unrecognized country in Template:flag icon}}',
['Flag decoration'] = '[[Category:Flag decoration missing country data templates]]',
}
local yesno = require('Module:Yesno')
--Get input arguments
local args = margs.getArgs(frame, {
frameOnly = ((frame.args.frameonly or '') ~= ''), valueFunc =
function(argkey,value)
if value then
value = mw.text.trim(value)
--Change empty string to nil for all args except 'image' and 'border'
if argkey=="image" or argkey=="border" or value~="" then
return value
end
end
return nil
end
} )
local preftext, sufftext = "", ""
if name == 'Flag+link' then
args.pref = args[1]
elseif name == 'Flag athlete' then
args.preftext = args[1]
args[2] = args.code or args[2] or ""
args.variant = args.variant or args[3]
elseif name == 'Flag medalist' then
preftext = (args[1] or "") .. "<br/>"
args[2] = args.code or args[2] or ""
args.variant = args.variant or args[3]
elseif name == 'Flag link' then
args.suff = args[2]
args[2] = args[1] or ""
args.variant = args.variant or args[3]
elseif key ~= nil then
args.variant = args.variant or args[1]
args[2] = key
else
sports = {
['3x3'] = '3x3',
bb = 'bb',
fb = 'fb',
['fb-rt'] = 'fb',
fbicon = 'fb',
ru = 'ru',
fba = 'fba',
fbaicon = 'fba'
}
if sports[name]then
args.avar = args[1] and sports[name] or nil
if name == 'fb' and yesno(args.align) == true then
args.align='c'
elseif sports[name] == 'fba' then
if args[1] then
local list = require("Module:Fba/list")
local old = ((args.old or "") ~= "") and "_old" or ""
local country = args[1]
local fba = list.fbas[country .. old]
if not fba then -- look for aliases
local countryTable = require('Module:CountryData').getcachedtable(frame, country)
if countryTable and countryTable.alias then
country = countryTable.alias
fba = list.fbas[country .. old]
end
end
if args.name == "code" then
args.name = list.codes[country] or country
elseif args.name == "full" then
args.name = fba
end
if fba then
mode = string.gsub(mode, "p", "c")
args.link = fba
end
args.altlink = args.old
elseif args.name == "code" or args.name == "full" then
args.name = ""
end
end
elseif name == "Flag team" and (args.code or args[1]) then
sufftext = ' <span style="font-size:90%;">('..(args.code or args[1])..')</span>'
end
args.variant = args.variant or args[2]
args[2] = args[1] or ""
end
args[1] = mode .. (args.opts or '')
args.missingcategory = categories[name]
args.noredlink = args.noredlink or 'notext'
if args.placeholder and yesno(args.placeholder) ~= true then
args[1] = args[1] .. 'o'
end
check = ''
if name == 'Flag icon' and mw.title.getCurrentTitle().namespace == 0 then
local unknown = '[[Category:Pages using ' .. mw.ustring.lower(name) ..
' template with unknown parameters|_VALUE_' .. frame:getParent():getTitle() .. ']]'
local opts = {
unknown=unknown,
preview='Page using [[Template:' .. name .. ']] with unknown parameter "_VALUE_"',
ignoreblank='y',
'1','2','variant','image','size','sz','border','align','al','width',
'w','alt','ilink','noredlink','missingcategory','name','clink','link',
'pref','suff','plink','the','section','altvar','avar','age','nalign',
'nal','text','nodata','opts','placeholder','getParent','frameonly'
}
check = require('Module:Check for unknown parameters')._check(opts,args)
end
return preftext .. require('Module:Flagg').luaMain(frame,args) .. sufftext .. check
end
local p = {
[''] = function (frame) return _main(frame, 'Flag', 'unc' ) end,
decoration = function (frame) return _main(frame, 'Flag decoration', 'uxx' ) end,
icon = function (frame) return _main(frame, 'Flag icon', 'cxxl' ) end,
link = function (frame) return _main(frame, 'Flag link', 'unpe' ) end,
['+link'] = function (frame) return _main(frame, 'Flag+link', 'unpefo') end,
country = function (frame) return _main(frame, 'Flag country', 'unce' ) end,
list = function (frame) return _main(frame, 'Flag list', 'usc' ) end,
team = function (frame) return _main(frame, 'Flag team', 'unce' ) end,
athlete = function (frame) return _main(frame, 'Flag athlete', 'unape' ) end,
medalist = function (frame) return _main(frame, 'Flag medalist', 'unce' ) end,
['3x3'] = function (frame) return _main(frame, '3x3', 'unpe' ) end,
bb = function (frame) return _main(frame, 'bb', 'unpe' ) end,
fb = function (frame) return _main(frame, 'fb', 'unpe' ) end,
fba = function (frame) return _main(frame, 'fba', 'unpe' ) end,
['fb-rt'] = function (frame) return _main(frame, 'fb-rt', 'unpre' ) end,
fbicon = function (frame) return _main(frame, 'fbicon', 'pxxl' ) end,
fbaicon = function (frame) return _main(frame, 'fbaicon', 'pxxl' ) end,
ru = function (frame) return _main(frame, 'ru', 'unpe' ) end,
IOC = function (frame) return require('Module:Country_alias').flagIOC(frame:newChild{ title = 'Template:Flag IOC' }) end,
IOC2 = function (frame) return require('Module:Country_alias').flagXYZ(frame:newChild{ title = 'Template:Flag IOC 2', args = {name = margs.getArgs(frame).name or '', type = 'name'} }) end,
IOCathlete = function (frame) return require('Module:Country_alias').flagXYZ(frame:newChild{ title = 'Template:Flag IOC athlete', args = {type = 'athlete-O'} }) end,
}
p['deco'] = p.decoration
p['IOC 2'] = p.IOC2
p['IOC athlete'] = p.IOCathlete
return setmetatable (p, {['__index'] = -- returns table p with the metatable __index set so that, if the table KEY isn't recognized, it returns
function (_, key) -- this anonymous function called as function(p, KEY)
return function (frame) return _main(frame, 'Flag', 'unc', key) end -- which interprets the module call as {{flag|KEY}} and passes it to _main()
end
})