မာတိကာသို့ ခုန်သွားရန်

မဝ်ဂျူ:Flagg

နူ ဝဳကဳပဳဒဳယာ

Lua error in မဝ်ဂျူ:Lua_banner at line 113: attempt to index field 'edit' (a nil value).

{{Flagg}} (flag general) is a flag template with variable output format. Using Lua instead of the standard mechanism, it allows overriding the image name and link target, and works even if a country data template for an entity does not exist (without using any expensive functions).

The template is not intended to fully supersede any specific flag templates it can simulate (see below), but can be useful for formats for which no template exists, or if its additional options are needed.

Aliases (alternatives) for each parameter or value are given in square brackets.

Format (first unnamed parameter)

[ပလေဝ်ဒါန် တမ်ကၞက်]

The first parameter is an alphabetic code specifying the output format. The first letter concerns the image, the second the separator, and the third the country name. The parameter is fully case-insensitive.

If any position in the parameter value is missing or has a character not corresponding to an option below, the options marked as default will be used; e.g. a first parameter equal to i, i** or izz will be read as isc.

Image (first letter)

Letter Meaning Description Example
u unlinked Image is not linked (default). {{flagg|uxx|France}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
c country Image links to country/entity page. {{flagg|cxx|France}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
p [f] prefix/suffix Image links to country name with prefixed and/or suffixed text (default "Flag of ..."), set using |pref= and |suff= (see below). {{flagg|pxx|France}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
i image page Image links to file description page; use this for non-public-domain images, for which attribution is required. {{flagg|ixx|France}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
d data template Image links to the used country data template, for use in discussion/documentation. Automatically adds redirect=no if link is a redirect. {{flagg|dxx|France}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
x X mark No image is displayed. If the second letter is anything other than x, and o is not set, an unlinked transparent image is actually used to preserve the spacing. {{flagg|xnx|France}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.

Separator (second letter)

Letter Meaning Description Example
s span box The flag image is put in a fixed-width <span> tag, meaning the country names are aligned in vertical lists; see documentation of {{Flaglist}} (default). {{flagg|usu|Niger}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
n non-breaking space A non-breaking space (&nbsp;) is used, like in most flag templates, including {{flag}}. Note that &nbsp; does not actually prevent wrapping between image and text in all browsers; use w as described below if needed. {{flagg|unu|Niger}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
l line break A line break (<br/>) is used as separator. {{flagg|ulu|Niger}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
t table cell A table cell separator (two pipes) is used. {{flagg|utu|Niger}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
x X mark No separator is used. {{flagg|uxu|Niger}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.

Name (third letter)

Letter Meaning Description Example
c country The country name links to the main country/entity page (default). {{flagg|xxc|Chile}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
p prefix/suffix The country name links to the country page with prefixed or suffixed text (default "Flag of ..."), set using |pref= and |suff= (see below). {{flagg|xxp|Chile}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
f full prefix/suffix Same as p, except that the prefix and/or suffix is/are displayed. {{flagg|xxf|Chile}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
b both country and prefix/suffix Combined country link and prefix/suffix link: country name links to country page, while prefix and/or suffix link(s) to prefixed/suffixed title. {{flagg|xxb|Chile}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
u unlinked (cf. {{flagu}}) The country name is displayed as plain text, without link. {{flagg|xxu|Chile}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
d data template Country name is linked to the used country data template, for use in discussion/documentation. Automatically adds redirect=no if a redirect is used. {{flagg|xxd|Chile}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
x X mark No text is displayed. {{flagg|xxx|Chile}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.

Some additional options can be enabled by appending the following letters to the three-letter code in any order:

Letter Description Example
a Adds the country name (the "name" parameter, or if unset the second unnamed parameter) as alt text and mouseover for the image. If |alt= is used for a custom alt/mouseover text, this does not need to be separately set. {{flagg|uxxa|Pakistan}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
b Blanks the text portion if a flag is not found. {{flagg|uncb|Xanadu}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
Compare with:
{{flagg|unc|Xanadu}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
e Uses the name set in the country data template (rather than the first parameter) as display name, like in {{flagcountry}} (i.e. expands abbreviated forms). {{flagg|unue|PAK}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
l Adds the link name (as defined by the "image" parameter) as alt text and mouseover for the image. If |alt= is used for a custom alt/mouseover text, this does not need to be separately set. {{flagg|cxxl|PAK}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
Compare with:
{{flagg|cxxa|PAK}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
o Omits the image and spacing in case the image is an invisible placeholder, i.e., only include the spacing if a flag is displayed. Useful for inline/standalone usages or horizontal lists, where name alignment is not needed. {{flagg|unuo|Pakistan|image=}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
Compare with:
{{flagg|unu|Pakistan|image=}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
r Reverses the order of the elements, putting the image to the right of the name; cf. {{flagright}}. Doesn't affect the order of letters in the format code. {{flagg|uncr|Pakistan}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
w Avoids wrapping by adding <span class="nowrap">...</span> around the output. {{flagg|unuw|Pakistan}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.

Entity (second unnamed parameter)

[ပလေဝ်ဒါန် တမ်ကၞက်]

The second parameter is the country or entity name. The template attempts to read the flag and link data from "Template:Country data country"; if that does not exist, the same parameter will be used as default country link and no automatic image will be displayed. The parameter also defines the default displayed country name, if the e option above is not used.

|variant= [third unnamed parameter]
Specifies a variant flag image, as defined and documented in each entity's data template. For example, {{flagg|ixx|Germany|naval}}Lua error in package.lua at line 80: module 'Module:CountryData' not found. uses the "naval" variant of Template:Country data Germany.
|image=
Custom image name, with or without the "File:" namespace prefix. Can be used if the wanted image is not available as variant for the entity (you can alternatively request it be added at the respective data template's talk page), or if no data template exists. Set to "none" ["blank", empty string] to use an unlinked transparent image (functionally identical to the x format).
|size= [|sz=]
Sets the image size; default is 23×15 pixels (larger for some entities). You can use an explicit size in pixels (e.g. 30x20px; the "px" suffix is optional) or one of the relative sizes "xs" (half the default dimensions), "s", "m", "l" and "xl" (twice the default size).
|border=
By default, the flag icon includes a border, except if it is disabled in the entity's country data template. |border= can be set to "yes" ["y", "1"] to force a border when excluded by default, or "no" ["n", "0", empty string] to prevent one.
|align= [|al=]
Set to "left" ["l"], "center" ["centre", "c", "middle", "m"] or "right" ["r"] to set the alignment of the image for the span box (s) and table cell (t) formats. For t, the default is center; for s, it is right-aligned if r is set, else left-aligned.
|width= [|w=]
Sets the width of the span box surrounding the image for the span box (s) format, in pixels, without the "px" suffix. The default is calculated by Module:Flaglist and depends on the image size.
|alt=
Sets alt text and mouseover text for the flag image, if it is for information rather than just decoration. If the wanted text is equal to the entity name, use the a option described above.
|ilink=
Overrides the link target of the image (only use if none of the image formats above allow linking to the desired page).
|noredlink=no
Displays a red link to the missing country data template instead of a placeholder image. Defaults to "yes" (no red link displayed).
|missingcategory=category name
Adds the page to category name if the image if the country data is missing.
|name=
Changes the displayed country name. Note that with the f format, this includes the prefix and/or suffix.
|clink= [|link=]
Overwrites the link to the country article; this is also used to construct the prefix/suffix link for the f, p and b options.
|pref=, |suff=, |plink=
|pref= and |suff= set the prefix and suffix to use for the prefix/suffix links (format letters f, p and b). The default, if neither is specified, is "Flag of" as prefix (cf. {{flagof}}) and no suffix. |plink= can be used to override the combined link.
|the=
Set to "yes" ["y", "1"] to include the article "the" before the country name in the prefix/suffix links. Example: {{flagg|usf|Philippines|the=1}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.. Use |pthe= if the link needs "the" but the name doesn't, and |nthe= if the name needs it but the link doesn't.
|section=
Links to a section of the linked article without displaying the section name. If both a country link and a prefix/suffix link are used, use |csection= for a section of the country article, and |psection= for a section of the prefixed/suffixed article.
|altvar= [|avar=], |age=
Enables using one of a set of standard suffixes for linking to sports teams and militaries. The altvar and suffix data is loaded from Module:Flagg/Altvar data. The possible parameter values are the base names of the corresponding specialized templates; alias values from full sports names exist (see examples below and data page). For some entities this also changes the image to a variant specific to a sport or military branch; for example, {{flagg|usp|Ireland|avar=ru}}Lua error in package.lua at line 80: module 'Module:Flagg/Altvar data' not found. uses the IRFU flag to represent the Irish rugby union team. For youth teams in some sports (see the data page), the age limit must be additionally set using |age=.
|nalign= [|nal=]
Sets the alignment of the text in table cell format (t). The default is left; the possible values are the same as for |align=.
|text=
Overrides the entire text; only use when necessary for any nonstandard formats. Alternatively, you can set the third letter of the format parameter to x (no text) and add custom text outside the template.
|nodata=y
Overrides attempts to use the corresponding ထာမ်ပလိက်:Tld template, which is useful when the corresponding data template doesn't exist.

Formats:

  • {{flagg|usc|Fiji}}Lua error in package.lua at line 80: module 'Module:CountryData' not found. (default format)
  • {{flagg||Fiji}}Lua error in package.lua at line 80: module 'Module:CountryData' not found. (default format)
  • {{flagg|pnbr|Fiji}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • <span style="display:inline-block;text-align:center;">ထာမ်ပလိက်:((flagg|ilf|Fiji|sz=xlထာမ်ပလိက်:))</span>Lua error in package.lua at line 80: module 'Module:CountryData' not found.

Table format & alignment:

{{flagg|utu|Jamaica}} Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flagg|utur|Jamaica}} Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flagg|utu|Jamaica|al=l|nal=l}} Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flagg|utu|Jamaica|al=c|nal=c}} Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flagg|utu|Jamaica|al=r|nal=r}} Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|usu|Switzerland}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|usu|Switzerland|al=l}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|usu|Switzerland|al=c}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|usu|Switzerland|al=r}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.

Standard image & name parameters:

  • {{flagg|isc|Myanmar}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|isc|Myanmar|border=}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|isc|Myanmar|1974}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|isc|Myanmar|variant=1974}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|isc|Myanmar|name=Burma|variant=1974}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|isc|Burma|variant=1974}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|isc|Myanmar|sz=30}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|isc|Myanmar|size=30}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|isc|Myanmar|size=30px}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|isc|Myanmar|size=30x18px}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|isc|Myanmar|size=xs}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|isc|Myanmar|size=xl}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|isc|Myanmar|width=30|size=xs}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|isc|Myanmar|image=}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • ထာမ်ပလိက်:((flagg|isc|Myanmar|image=Flag of None.svgထာမ်ပလိက်:))Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • ထာမ်ပလိက်:((flagg|isc|Myanmar|image=File:Flag of None.svgထာမ်ပလိက်:))Lua error in package.lua at line 80: module 'Module:CountryData' not found.

Links and altvars:

  • {{flagg|psp|Egypt}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|psf|Egypt}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|psb|Egypt}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|psb|Philippines|the=1}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|csc|Egypt|section=History}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|csb|Egypt|csection=History}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|psb|Egypt|psection=Kingdom of Egypt (1922–1953)|variant=1922}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|psb|Egypt|plink=List of Egyptian flags}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|psf|Egypt|pref=History of}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|psp|Egypt|suff=at the Olympics}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
  • {{flagg|psp|Egypt|avar=fb}}Lua error in package.lua at line 80: module 'Module:Flagg/Altvar data' not found.
  • {{flagg|psp|Egypt|avar=football}}Lua error in package.lua at line 80: module 'Module:Flagg/Altvar data' not found.
  • {{flagg|psp|Egypt|avar=fbu|age=20}}Lua error in package.lua at line 80: module 'Module:Flagg/Altvar data' not found.
  • {{flagg|psf|Egypt|avar=navy}}Lua error in package.lua at line 80: module 'Module:Flagg/Altvar data' not found.

Non-existing data template:

  • {{flagg|isc|Belfast|nodata=1}}Lua error in package.lua at line 80: module 'Module:Flaglist' not found.
  • {{flagg|isc|Belfast|image=Flag of Belfast.svg|nodata=1}}Lua error in package.lua at line 80: module 'Module:Flaglist' not found.

Comparison with other templates

[ပလေဝ်ဒါန် တမ်ကၞက်]

These "specialized" templates predate Flagg, and while most do not have options for custom links and images, they are probably faster because they only do two transclusions without invoking Lua.

Template Corresponding {{flagg}} syntax Example
{{flag|country}} {{flagg|uncb|country}} {{flag|China}} China
{{flagg|unc|China}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flagbig|country}} {{flagg|ulc|country|sz=l}} {{flagbig|China}}ထာမ်ပလိက်:Flagbig
{{flagg|ulc|China|sz=l}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flagc|country}} {{flagg|inc|country}} {{flagc|China}}ထာမ်ပလိက်:Flagc
{{flagg|inc|China}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flagcountry|country}} {{flagg|unce|country}} {{flagcountry|CHN}}ထာမ်ပလိက်:Country data CHN
{{flagg|unce|CHN}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flagdeco|country}} {{flagg|uxxo|country}} {{flagdeco|China}}
{{flagg|uxx|China}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flagicon|country}} {{flagg|cxxlo|country}} {{flagicon|China}}China
{{flagg|cxxlo|China}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flagicon image|image}} {{flagg|uxx|image=image}} {{flagicon image|Flag of China.svg}}
{{flagg|uxx|image=Flag of China.svg}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flaglink|country|suffix}} {{flagg|unp|country|suff=suffix}} {{flaglink|China|at the Hopman Cup}}ထာမ်ပလိက်:Flaglink
{{flagg|unp|China|suff=at the Hopman Cup}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flag+link|prefix|country}} {{flagg|unp|country|pref=prefix}} (no existence check) {{flag+link|Agriculture in|China}}Script error: No such module "flag". China
{{flagg|unp|China|pref=Agriculture in}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flaglist|country}} {{flagg|usc|country}} {{flaglist|China}}ထာမ်ပလိက်:Flaglist
{{flagg|usc|China}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flagof|country}} {{flagg|unp|country|sz=l}} {{flagof|China}}ထာမ်ပလိက်:Flagof
{{flagg|unp|China|sz=l}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flagright|country}} {{flagg|uncr|country}} {{flagright|China}}ထာမ်ပလိက်:Flagright
{{flagg|uncr|China}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{flagu|country}} {{flagg|unu|country}} {{flagu|China}} China
{{flagg|unu|China}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{noflag|country}} {{flagg|xnu|country}} {{noflag|China}} China
{{flagg|xnu|China}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.
{{noflag|[[country]]}} {{flagg|xnc|country}} {{noflag|[[China]]}} China
{{flagg|xnc|China}}Lua error in package.lua at line 80: module 'Module:CountryData' not found.

The football templates are used as examples here; other sports that have separate templates work correspondingly.

Template Corresponding {{flagg}} syntax Example
{{fb|country}} {{flagg|unpe|country|avar=fb}} {{fb|China}}ထာမ်ပလိက်:Flaglink/core
{{flagg|unpe|China|avar=fb}}Lua error in package.lua at line 80: module 'Module:Flagg/Altvar data' not found.
{{fb|country|align=1}} {{flagg|uspe|country|avar=fb|al=c}} {{fb|China|align=1}}ထာမ်ပလိက်:Flaglink/aligned
{{flagg|uspe|China|avar=fb|al=c}}Lua error in package.lua at line 80: module 'Module:Flagg/Altvar data' not found.
{{fb-big|country}} {{flagg|ulpe|country|avar=fb|sz=l}} {{fb-big|China}}ထာမ်ပလိက်:Fb-big
{{flagg|ulpe|China|avar=fb|sz=l}}Lua error in package.lua at line 80: module 'Module:Flagg/Altvar data' not found.
{{fb-rt|country}} {{flagg|unpre|country|avar=fb}} {{fb-rt|China}}ထာမ်ပလိက်:Fb-rt
{{flagg|unpre|China|avar=fb}}Lua error in package.lua at line 80: module 'Module:Flagg/Altvar data' not found.
{{fbu|age|country}} {{flagg|unpe|country|avar=fbu|age=age}} {{fbu|17|China}}ထာမ်ပလိက်:Fbu
{{flagg|unpe|China|avar=fbu|age=17}}Lua error in package.lua at line 80: module 'Module:Flagg/Altvar data' not found.
{{fbw|country}} {{flagg|unpe|country|avar=fbw}} {{fbw|China}}ထာမ်ပလိက်:Fbw
{{flagg|unpe|China|avar=fbw}}Lua error in package.lua at line 80: module 'Module:Flagg/Altvar data' not found.
{{fbwu|age|country}} {{flagg|unpe|country|avar=fbwu|age=age}} {{fbwu|17|China}}ထာမ်ပလိက်:Fbwu
{{flagg|unpe|China|avar=fbwu|age=17}}Lua error in package.lua at line 80: module 'Module:Flagg/Altvar data' not found.
{{army|country}} {{flagg|unfe|country|avar=army}} (no automatic name override) {{army|China}} People's Liberation Army Ground Force
{{flagg|unfe|China|avar=army}}Lua error in package.lua at line 80: module 'Module:Flagg/Altvar data' not found.
{{navy|country}} {{flagg|unfe|country|avar=navy}} (no automatic name override) {{navy|China}} People's Liberation Army Navy
{{flagg|unfe|China|avar=navy}}Lua error in package.lua at line 80: module 'Module:Flagg/Altvar data' not found.
{{air force|country}} {{flagg|unfe|country|avar=air force}} (no automatic name override) {{air force|China}} People's Liberation Army Air Force
{{flagg|unfe|China|avar=air force}}Lua error in package.lua at line 80: module 'Module:Flagg/Altvar data' not found.
  • User:SiBr4/Flagg tests — extensive tests of the template's functions, which may also serve as additional examples

local p = {}

function p.main(frame)

--Get input arguments
local args = require('Module:Arguments').getArgs(frame,{valueFunc =
  function(key,value)
    if value then
      value = mw.text.trim(value)
      --Change empty string to nil for all args except 'image' and 'border'
      if key=="image" or key=="border" or value~="" then
        return value
      end
    end
    return nil
  end
})

--Call main function
return p.luaMain(frame,args)

end

function p.luaMain(frame,args)

function emp2nil(x)
  if x=="" then return nil else return x end
end
function space2emp(x)
  if string.find(x,"^%s*$") then return "" else return x end
end
function nopx(x)
  if x~=nil and (string.find(x,"^%d+$") or string.find(x,"^%d+px$")) then return string.gsub(x,"^(.*)px","%1") else return nil end
end

--Country & mode parameters
local mode = string.lower(args[1] or "usc")
local mi = string.sub(mode,1,1)
local ms = string.sub(mode,2,2)
local mn = string.sub(mode,3,3)
local me = string.sub(mode,4,-1)

local country = args[2] or ""
local avar = args["avar"] or args["altvar"]
local clink = args["clink"] or args["link"]

--Get country data & altvar data
local data, alink, amap, asuf
if avar then
  local age = args["age"] or ""
  local aalias
  amap, aalias = require("Module:Flagg/Altvar data").alttable(age)
  avar = string.gsub(string.lower(avar or ""),"[ \-]","")
  avar = aalias[avar] or avar
  if not amap[avar] then error("Unknown avar") end
  local apar = {altvar=amap[avar].altvar;mw=amap[avar].mw;age=amap[avar].age;variant=args["variant"] or args[3]}
  data = require("Module:CountryData").gettable(frame,country,apar)
  asuf = amap[avar].altlink
  alink = data["link alias-"..amap[avar].altvar] or (clink or data["shortname alias"] or data.alias or country).." "..asuf
else
  data = (args["nodata"] and {}) or require("Module:CountryData").gettable(frame,country,{variant=args["variant"] or args[3]})
  avar = ""
  amap = {[""]={altvar=""}}
end

--Name and link parameters
clink = clink or data.alias or country

local pref = args["pref"]
local suff = args["suff"] or asuf
if not pref and not suff then --Default prefix
  pref = "Flag of"
end
local yn_map = {[""]=0; ["0"]=0; ["no"]=0; ["n"]=0; ["1"]=1; ["yes"]=1; ["y"]=1}
local fthe = (args["pthe"] and yn_map[args["pthe"]]~=0) or (args["the"] and yn_map[args["the"]]~=0)
local nthe = (args["nthe"] and yn_map[args["nthe"]]~=0) or (args["the"] and yn_map[args["the"]]~=0)
fthe = fthe and (pref and "t" or "T").."he " or ""
nthe = nthe and (pref and "t" or "T").."he " or ""
local flink = args["plink"] or args["flink"] or alink
              or clink=="" and "" or space2emp((pref or "").." ")..fthe..clink..space2emp(" "..(suff or ""))
local fsec = args["psection"] or args["section"]
local csec = args["csection"] or args["section"]
fsec = fsec and "#"..fsec or ""
csec = csec and "#"..csec or ""

local name = args["name"]
if not name then
  local cname = string.find(me,"e") and (data["name alias-"..amap[avar].altvar] or data["shortname alias"] or data.alias) or country
  if mn == "f" then
    name = cname=="" and "" or space2emp((pref or "").." ")..nthe..cname..space2emp(" "..(suff or ""))
  else
    name = cname
  end
end

--Image parameters
local pimage = args["image"]
local placeholder = "Flag placeholder.svg"
local variant = args["variant"] or args[3] or ""
local image_map = {[""]=placeholder; ["none"]=placeholder; ["blank"]=placeholder}
if pimage then --Remove namespace
  pimage = string.gsub(pimage,"^[Ff][Ii][Ll][Ee]:","")
  pimage = string.gsub(pimage,"^[Ii][Mm][Aa][Gg][Ee]:","")
end
local iname = image_map[pimage] or pimage

local size = args["size"] or args["sz"]
local size_map = {xs="12x8px"; s="17x11px"; m="23x15px"; l="32x21px"; xl="46x30px"}
if size==nil or string.find(size,"^%d*x?%d+px$") then
  --valid EIS size (..px, x..px or ..x..px) or unset
elseif string.find(size,"^%d*x?%d+$") then --EIS size without "px" suffix
  size=size.."px"
else --size from map, or invalid value
  size = size_map[size] or nil
end
local border = args["border"]

if iname then
  size = size or "23x15px"
  if yn_map[border]==0 then border = "" else border = "|border" end
else
  iname = data["flag alias-"..amap[avar].altvar.."-"..variant] or data["flag alias-"..variant] or data["flag alias-"..amap[avar].altvar] or data["flag alias"] or placeholder
  size = size or emp2nil(data.size) or "23x15px"
  if border then
    if yn_map[border]==0 then border = "" else border = "|border" end
  else
    local autoborder = data["border-"..variant] or data["border-"..amap[avar].altvar] or data.border
    if autoborder and autoborder~="border" then border = "" else border = "|border" end
  end
end

local am = ""
if args["alt"] or string.find(me,"a") then
  am = args["alt"] or args["name"] or country
  am = am.."|"..am
end

--Build display name
local text = args["text"]
if not text then
  if mn=="x" then --no text
    text = ""
  elseif mn=="p" or mn=="f" then --prefix/suffix link
    text = flink=="" and name or "[["..flink..fsec.."|"..name.."]]"
  elseif mn=="b" then --both prefix/suffix and normal country link
  	local preflink = pref and (flink=="" and pref.." " or "[["..flink..fsec.."|"..pref.."]] ") or ""
  	local sufflink = suff and (flink=="" and " "..suff or " [["..flink..fsec.."|"..suff.."]]") or ""
  	local namelink = (name=="" and "" or nthe)..(clink=="" and name or "[["..clink..csec.."|"..name.."]]")
    text = preflink..namelink..sufflink
  elseif mn=="d" then --data template
    --check if redirect
    if require('Module:Redirect').luaIsRedirect("Template:Country data "..country) then
      text = "<span class=\"plainlinks\">["..mw.title.new("Template:Country data "..country):fullUrl("redirect=no").." "..name.."]</span>"
    else
      text = "[[Template:Country data "..country.."|"..name.."]]"
    end
  elseif mn=="u" then --unlinked
    text = name
  else --country link (default)
    text = clink=="" and name or "[["..clink..csec.."|"..name.."]]"
  end
end

--Build image
local ilink = args["ilink"]
if not ilink then
  if mi=="x" or (iname==placeholder and pimage~=placeholder) then --no image/invisible image
    iname = placeholder
    border = ""
    ilink = "|link="
    am = ""
  elseif mi=="i" then --image page link
    ilink = ""
  elseif mi=="c" then --country link
    ilink = "|link="..clink..(clink=="" and "" or csec)
  elseif mi=="p" or mi=="f" then --prefix/suffix link
    ilink = "|link="..flink..(flink=="" and "" or fsec)
  elseif mi=="d" then --data template
    --check if redirect
    if require('Module:Redirect').luaIsRedirect("Template:Country data "..country) then
      ilink = "|link="..mw.title.new("Template:Country data "..country):fullUrl("redirect=no")
    else
      ilink = "|link=Template:Country data "..country
    end
  else --unlinked (default)
    ilink = "|link="
  end
end
if am == "" and string.find(me,"l") then
	am = mw.ustring.sub(ilink,7,-1)
end
local image = "[[File:"..iname.."|"..size..border..ilink.."|alt="..am.."]]"

if iname==placeholder then
	if require('Module:yesno')(args["noredlink"]) == false then
		iname = ''
		image = "[[:Template:Country data "..country.."]]"
	end
	if (args["missingcategory"] or '') ~= '' then
		image = image..args["missingcategory"]
	end
	if string.find(me,"b") then
		text = ''
	end
end

--Combine image and name with separator
local align = args["align"] or args["al"]
local nalign = args["nalign"] or args["nal"]
local align_map = {left="left", l="left", center="center", centre="center", c="center", middle="center", m="center", right="right", r="right"}
local out
if string.find(me,"r") then
  --image right of name
  if (ms=="x" and mi=="x") or (string.find(me,"o") and iname==placeholder and pimage~=placeholder) then --name only
    out = text
  elseif ms=="x" then --no separator
    out = text.."<span class=\"flagicon\">"..image.."</span>"
  elseif ms=="n" then --non-breaking space
    out = text.."<span class=\"flagicon\">&nbsp;"..image.."</span>"
  elseif ms=="l" then --line break
    out = text.."<span class=\"flagicon\"><br/>"..image.."</span>"
  elseif ms=="t" then --table cell
    out = "style=\"text-align:"..(align_map[nalign] or "left").."\"|"..text.."||style=\"text-align:"..(align_map[align] or "center")..";\"|<span class=\"flagicon\">"..image.."</span>"
  else --fixed-width span box (default)
    local width = args["width"] or args["w"] or require("Module:Flaglist").luawidth(size)
    out = text.."&nbsp;<span class=\"flagicon\" style=\"display:inline-block;width:"..width.."px;text-align:"..(align_map[align] or "right")..";\">"..image.."</span>"
  end
 else --image left of name
  if (ms=="x" and mi=="x") or (string.find(me,"o") and iname==placeholder and pimage~=placeholder) then --name only
    out = text
  elseif ms=="x" then --no separator
    out = "<span class=\"flagicon\">"..image.."</span>"..text
  elseif ms=="n" then --non-breaking space
    out = "<span class=\"flagicon\">"..image.."&nbsp;</span>"..text
  elseif ms=="l" then --line break
    out = "<span class=\"flagicon\">"..image.."<br/></span>"..text
  elseif ms=="t" then --table cell
    out = "style=\"text-align:"..(align_map[align] or "center")..";\"|<span class=\"flagicon\">"..image.."</span>||style=\"text-align:"..(align_map[nalign] or "left").."\"|"..text
  else --fixed-width span box (default)
    local width = nopx(args["width"] or args["w"]) or require("Module:Flaglist").luawidth(size)
    out = "<span class=\"flagicon\" style=\"display:inline-block;width:"..width.."px;text-align:"..(align_map[align] or "left")..";\">"..image.."</span>&nbsp;"..text
  end
end
if string.find(me,"w") then --avoid wrapping
  out = "<span class=\"nowrap\">"..out.."</span>"
end

--Tracking categories
local cat = ""
if pimage and not image_map[pimage] and country~="" and data["flag alias"] and not args.demo then
  cat = "[[Category:Pages using Flagg with specified image instead of data template image]]"
end

return out..cat

end

return p