Movie ideas Wiki:WikiProject Flag Template

This WikiProject is responsible for the template system used to create flag icons, with or without associated wikilinks. This project is only concerned with the implementation of these templates.
 * See Project:WikiProject Heraldry and vexillology for issues regarding the flag images themselves.
 * See Project:Manual of Style (flags) for guidelines about flag icon usage.

Template:Flagicon
Produces a small image of the named flag. The image has a link to the article about the country associated with the flag.
 * Example:  → 🇯🇵
 * Example:  → 🇯🇵

Template:Flag
Produces a small image of the named flag, plus a wikilink to the associated article. The icon image does not have a link (unlike ) so that screen readers do not render the name twice.
 * Example:  → 🇬🇧 United Kingdom

Template:Flagu
Similar to, but the associated country name is unlinked. This template should be used in articles with Project:OVERLINK concerns (e.g. when the same flag is used many times in a single table).
 * Example:  →

Template:Flagcountry
Similar to, but always uses the preferred display text for the wikilinked article. Useful when the input parameter can be a country code, or is a long-form country name because it links to a different article, such as for a historical country.
 * → undefined       → 🇧🇷 brazil

Compare with, which always uses the first parameter as display name (unless when overridden with  ):
 * → Kingdom of Italy
 * → 🇧🇷 BRA

Template:Flagdeco
Displays a flag of the named parameter in "icon" size, currently 23×15 pixels plus a one pixel border. This template is very similar to Template:Flagicon, except the image is not linked to an article, i.e. it is "purely decorative" per World Wide Web Consortium (W3C) Web Content Accessibility Guidelines (WCAG). This template can be used when the article text immediately adjacent to the icon provides the associated link for the flag.


 * Comparison example:
 * → 🇺🇳


 * Usage examples:
 * → 🇺🇸 List of presidents of the United States
 * → 🇫🇷 French First Republic

"Shortcut" flag templates
Many countries also have individual flag templates, named using standard three letter country codes so as to offer "shortcut" alternatives to the standard templates. This is a mixed blessing; some country codes (like "USA") are widely known and the corresponding shortcut templates (i.e. ) offer convenience, but some country codes are relatively obscure, so wiki markup would likely be clearer if the country names were spelled out in full. Also, the shortcut templates do not offer the ability to use historical flag variants (described below), and are therefore less flexible.
 * Example:  → 🇧🇪 (equivalent to  )

See Project:Inline templates linking country articles for a complete list.

List
Besides the ones mentioned above, many other flag templates exist. This (probably incomplete) list excludes the military (see ) and sports templates (see ). See each template's documentation for more details.

The following templates do not technically use the flag template system, but are used similarly:

Flag names
The first (positional) parameter for these templates specifies the country (or other entity) to be used for the flag image. These actually identify additional templates that individually store information specific to that country. For example, the image name and main article name used by  (to produce 🇳🇴 Norway) is stored in Template:Country data Norway. The complete set of these "country data" templates is found in Category:Country data templates.

Note that there are country data templates for many entities that are not considered countries, such as international organizations or sub-national entities. The use of "country" in these template names is only because the original implementation of the flag template system was built upon Template:Country – a better name might have been "flag data", but it is likely too late for that change now.

Some examples of non-country flag templates are:
 * → 🇺🇳 United Nations
 * → 🇪🇺 European Union
 * → Catalonia
 * → Bern

Many country data templates also exist for historical nations, and these can be used to produce the historical flags with wikilinks to the appropriate articles. Some examples are:
 * → Austria-Hungary
 * → Nazi Germany
 * → Soviet Union
 * → Yugoslavia

Alias names
For added convenience, many flags can be identified by an alias name, typically a three-letter country code. For example, instead of, you could simply use   to produce 🇫🇷.

Alias names are available for almost every nation listed in ISO 3166-1 alpha-3, the list of IOC country codes, and the list of FIFA country codes. For example,  (ISO) and   (IOC and FIFA) both produce 🇩🇪. A small handful of other well-known abbreviations are also available (such as,  , and  ).

Alias names are implemented as redirects in the template namespace. For example, Template:Country data VEN is a redirect to Template:Country data Venezuela. The complete set of these redirects is listed in Category:Country data redirects, and the available alias redirect(s) for a given country data template (if any) are also documented on that template's page.

When using country code aliases, template  will display this value for the wikilink's display text. For example:
 * → 🇺🇸 USA
 * → UK
 * → 🇨🇳 CHN

Note that in each case, the target wikilink points to the correct article name (i.e. United States, United Kingdom, and People's Republic of China, respectively) but the display text matches the input parameter to template. This may be the desired effect, such as in column headings of a large table, but if the full name is wanted, then use Template:Flagcountry instead:


 * → 🇺🇸 united states
 * → undefined
 * → 🇨🇳 china

Alias names have a second purpose, which is to provide alternative display text for target wikilinks. For example, the main article linked by Template:Country data East Germany is East Germany, but Template:Country data German Democratic Republic is a redirect alias. Therefore, you can use  for  German Democratic Republic. Again, note that the target article name for the generated wikilink is still East Germany.

Flag variants
Many countries have had different flag variations at various periods in their history. The flag template system can accommodate this by storing multiple flag variants inside country data templates. A specific flag variant is selected by specifying an additional parameter to any of the standard flag templates. This parameter is usually given as the second positional parameter to the template, but may also be given as the  named parameter.

Examples
 * → 🇩🇪 Germany
 * → 🇩🇪 Germany
 * → 🇧🇩 bangladesh
 * → 🇧🇩
 * → 🇨🇦 canada
 * → 🇨🇦

The set of available flag variants (if any) for a specific country data template are documented on the country data template page itself. Each variant is identified by a short text label, such as  or   in the examples above. Usually, the label identifies the year in which the flag was introduced, but this is not a mandatory style convention.

Size
The default size for all flag icons created by these templates is 23x15px, with a one pixel border. That is, the icon will be no more than 23 pixels wide, and no more than 15 pixels tall. These dimensions were carefully chosen to generate the best results when flagicons are used in a bulleted list with the default browser text size. Some countries (mostly those with square or near-square flags) have different default sizes.

In certain situations, it might be desirable to use a larger (or smaller) size, and this is enabled with the  named parameter, available with all standard templates.


 * Examples:
 * → MON
 * → 🇧🇩
 * → 🇧🇪 Belgium

Name
The display text of the target wikilink is usually automatically generated, but can always be over-ridden with the  parameter.


 * Examples:
 * → 🇰🇷 South Korea (this name is used in several sports)
 * → ROC (China from 1912 to 1949)

Template:Navy
Displays the naval ensign of the named country (identified as the  variant in the corresponding country data template) plus a wikilink to the main article for the country's navy. Note that the naval ensign for many countries is the same as the national flag. Also note that the Project:SHIPS and Project:MILHIST conventions are to use naval ensigns, not naval jacks when identifying ships with flag icons.

Examples

Template:Naval
Displays the navy's flag of the named country (identified as the  variant in the corresponding country data template) plus a wikilink to the main article for the country's navy. Note that this is the navy flag, which differs from the naval ensign, which for many countries is the same as the national flag. If the navy does not have a flag, the jack is used instead. Also note that the Project:SHIPS and Project:MILHIST conventions are to use naval ensigns, not navy flags when identifying ships with flag icons.

Examples

Template:Coast guard
Displays a country's coast guard flag (the  variant), or alternatively their racing stripe, and a wikilink to the country's coast guard.

Examples

Template:Army
Displays a country's army or war flag (the  variant) and a wikilink to the country's army.

Examples

Template:Air force
Displays a country's air force flag (the  variant) and a wikilink to the country's air force.

Examples

National sport team flag templates
One of the most common instances of flag icon usage on Wikipedia is for national sport teams. Several sets of sport-specific templates have been developed to also use this flag template system and some have variant forms (see individual templates' documentation):
 * Template:bandy for bandy
 * Template:bb for baseball
 * Template:bd for badminton
 * Template:bk for basketball
 * Template:cr for cricket
 * Template:davis and Template:fed for tennis (Davis Cup and Fed Cup)
 * Template:fb for association football (soccer)
 * Template:fh for field hockey
 * Template:hb for handball
 * Template:ih for ice hockey
 * Template:iih for inline hockey
 * Template:kd for kabaddi
 * Template:korf for korfball
 * Template:nb for netball
 * Template:rl for rugby league
 * Template:ru for rugby union
 * Template:ru7 for rugby sevens
 * Template:sb for softball
 * Template:speedway for motorcycle speedway
 * Template:squ for squash
 * Template:svb for sitting volleyball
 * Template:vb for volleyball
 * Template:wp for water polo

These templates have intentionally been given terse names because they tend to be used many, many times on individual pages for match results. They completely supersede a set of previously used national team-specific templates. For example,  replaced ,   replaced replaced, etc.

There are often several template variations available for a given sport:
 * with a "w" suffix, links to women's national team articles instead
 * with a "-rt" suffix, renders the flag icon to the right of the nation's name instead of to the left. This formatting style is often used in match results
 * with a -big" suffix, renders the flag icon in larger size and the team name underneath the flag. This formatting style is often used in tables of tournament results.

For example, for football, the following templates are used:

User preference to disable display of flag icons
Users that do not like flag icons can disable them with a preference setting. A CSS class is used within the internal formatting template, and the class setting can be changed from a user's personal CSS file (skin-specific, cross-skin, or global).

Flag icon image rendering is disabled by:

.flagicon { display: none; }

Implementation
Three types of templates are used by the flag template system, each with a different function:
 * 1) User-transcluded templates
 * 2) Country data templates (internal)
 * 3) Formatting templates (internal)

For example,, uses:
 * 1) Template:Flag, to accept input parameters, such as the country name (mandatory) and the optional flag variant, size, and wikilink display name.
 * 2) Template:Country data Spain, to supply the image name and article name
 * 3) Template:Flag/core, to actually render the image icon and wikilink

This system architecture means that:
 * all country-specific data is contained within individual country data templates, improving maintainability
 * the formatting wikicode is centralized in a very small number of templates, ensuring consistency

How it works
There are three steps in each flag template invocation. In the previous example of, the templates expand as follows:

First,  expands to invoke , and ensure that all user-specified parameters are set. The first parameter to the country data template is actually the name of the formatting template. This is the mechanism by which the same country data template can be used with multiple different formatting templates. Therefore, the first step of expansion results in:

If the  (or second positional parameter), the , and/or   parameters were specified in the user invocation, these would be set to the desired value. For example,  would expand to:

Next, the country data template expands to invoke the formatting template, plus add all the country-specific parameters. Going back to the simpler example of, the second expansion results in:

Lastly, the formatting template is expanded to produce: &amp;nbsp; Spain

Basic country data template structure
The structure of all country data templates follows a standard pattern, which is extended to include additional parameters only when necessary. The empty boilerplate for all country data templates is as follows:

There are two essential values that must be specified: The invocation of  on the first line is used to automatically generate the template documentation, as described below. The  and   statements ensure that any user-specified size and/or name values are passed through from the outer template (,  , etc.) to the inner formatting template. Omission of these lines from the country data template would cause the size and name functionality to be disabled.
 * 1) The  value identifies the name of the main article associated with the flag.
 * 2) The  value identifies the image name of the default flag.

Adding flag variants
Additional flag variants are specified by individual  statements. The unique label for the variant is the suffix of the parameter name, as  (don't forget the hyphen). For example, Template:Country data Mexico has several flag variants, one of which is specified by: Therefore, when  is transcluded, Image:Flag of Mexico (1934-1968).png is rendered. The selection of the flag variant is coded in the formatting templates.
 * flag alias-1934 = Flag of Mexico (1934-1968).png

Country data templates with at least one flag variant (in addition to the default) must also have the following line: Similar to the  and   parameters as described above, this statement is required to pass the variant value (e.g.  ) from the outer flag template to the inner formatting template. Omission of this line will cause the flag variant selection to fail.
 * variant =

Disabling image border
If some flags are non-standard in shape and a 1px border is undesirable (for example for Nepal), then the border for the main flag may be defeated by adding the parameter
 * border =

To remove the border for certain variant flags only, use the pattern border-variant, replacing  with the respective variant label. For example:
 * border-1976 =
 * border-colonial =

Nothing should be added after the equal sign(s). See Template:Country data Poland for examples of this usage.

Due to the coding of the flag templates, disabling the border for the main flag also automatically disables it for all flag variants. If the main flag should not have a border but any of the variants should, the respective border-variant parameters must be explicitly set to "border" to re-enable the 1px border:
 * border-1976 = border

Changing the wikilink display text
The best results are obtained when the template name matches the article wikilink (as specified by the  value). For example, Template:Country data Russia contains, which results in a target wikilink to Russia.

However, there are instances where the main article name contains a disambiguation string. For example, Template:Country data Georgia contains. Therefore,  results in  Georgia. Note that the wikilink is Georgia (country), but the display string is "Georgia", as expected.

In these instances, an additional statement is needed to support Template:Flagcountry properly. The  parameter should be set to the desired text string, such as. In effect, the resultant wikilink will be generated as, or   in this specific example.

Changing the page being linked to
The templates flaglink and flag+link append and prepend text to the link target, respectively. For example, to link to the education system in a table comparing different countries' educational outcomes, use Which results in.

For link targets that do not start or end with the country name, use the flagdeco template (which returns an unlinked flagicon without text) followed by a standard wikilink: 🇫🇮 Finland Which would look like this: 🇫🇮 Finland.

National sport team template parameters
Any country data template that will be used with a national team template must include an additional "pass-through" parameter: This parameter is used to form the suffix of the associated wikilink. For example, Template:cr appends "national cricket team" to the country name ( value), and this process is enabled by the   parameter.
 * altlink =

In most cases, the flag and display name for national teams corresponds to the same flag and display name normally used for the nation. However, in some instances these can be over-ridden by additional parameters within the country data template. The default wikilink can also be changed in cases where the common naming convention is not used.

Some examples:
 * South Korea is referred to as "Korea Republic" by FIFA. Therefore, Template:Country data South Korea includes   so that   produces 🇰🇷 south korea
 * In many sports, all-Ireland teams compete with athletes from both the Republic of Ireland and Northern Ireland, and often under unique flags for each sport. Template:Country data Ireland includes unique flags for several sports teams, such as , so that   produces
 * The New Zealand netball team is described at the Silver Ferns article, so to avoid the redirect at New Zealand national netball team, Template:Country data New Zealand contains  so that   produces New Zealand

In each of these examples, the over-ride parameter (, , or  ) is identified by a unique per-sport variable that is passed from the appropriate sport team template. For example, Template:fb includes. Therefore, any country data template that utilizes one or more team sport over-ride parameters must also include:
 * altvar =

Template documentation
Country data templates "self-document" themselves through Template:Country showdata. Recall that the first line of each country data template is an invocation to a formatting template, defaulting to  if that parameter is missing: For simple country data templates, nothing further needs to be done to document them. If any flag variants, redirect aliases, etc. are used with the template, they are documented by adding parameters specifically for use by. These extra parameters are enclosed in a  section as they should not be present for any other invocation of the country data template.

See Template:Country showdata/doc for more information about how to document country data templates.

Alternatives to avoid Wikipedia's Post-expand include size limit
Pages with many flag icons may come close to or exceed Wikipedia's post-expand include size limit. In these cases consider using modules or module-wrapper templates instead:[
 * Module:Flagg is a Scribunto module that reads existing country data templates and can produce a wide variety of outputs to replicate most existing flag templates. It can be invoked directly or used via Flagg (although the latter doubles the post-expand include size). See the documentation at Template:Flagg/doc for usage.
 * Module:Flag is a wrapper for Module:Flagg that provides shortcuts to replace several common flag templates:

Internal project templates

 * WikiProject Flag Template – banner for talk pages of template and flag-related project pages