Module:Countries/doc
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
This is the documentation page for Module:Countries
This module implements templates that output a "Countries of" navigation box.
Module:Countries is the main module. Data for each supported region is defined in a submodule. It may also be used to create navigation box for other types of regions (not just lists of countries in a continent), this main module could be used as well to render a list of administrative or electoral subdivisions in any country or region, or for a list of teams in a sport competition, or for a list of named elements in a chemical classification).
Example of module for the list of countries of Africa
[edit]For example, Module:Countries/Africa specifies the all text displayed and the countries listed for Africa.
That module is then used to render the navigation box requested by template {{Countries of Africa}}, which displays its results with:
{{#invoke:Countries|main|Africa}}
The first unnamed parameter (Africa
) identifies the submodule defining the countries in Africa. The parameter is case sensitive, it can be the full name of the data module, but if there's no colon indicated in this value, the full page name of the data module will be based on a common prefix prepended to this parameter.
Pages using the module with an invalid parameter are added to the tracking Category:Countries template with invalid parameters. The tracking category is also added if the list of countries selected by the user's language has a country code that is not defined in the infos
table (or countries
table, but not both). For testing, the parameter |nocat=yes
can be used in the template to suppress the category.
Codes used in lists of items can be arbitrarily chosen, but should remain short (they may include digits, and their lettercase is significant, but they must not contain any space). For administrative units these codes should preferably be formed starting by a capitalized ISO 3166 country or territory code (if possible); for international sports teams/delegations, these codes should be based on standard IOC codes instead; for chemical elements these codes could be standardized codes as well like C
or H
for carbon or hydrogen. If needed, additional letters, digits or hyphens may be used to specify a precision or disambiguation.
Usually, these codes will not be longer than 8 ASCII characters (including extensions) and should be language-neutral, and independant of possible changes of official or translated names. Items in the data module just list the default name or optional aliases used in Wikimedia Commons categories, frequently but not alwyas in English; actual names and translations displayed in the generated navigation box (when templates are not used with |all=1
) are taken from Wikidata items associated to each data item with their qid='Qnnn',
property.
The translated names from Wikidata may be automatically sorted (however the automatic sort is language-neutral and may be very crude for some languages, it is based on the NFKD normalization of the Unicode-encoded names from Wikidata, where combining characters and format controls have then been removed from the text used for the primary and secondary key; then primary characters (forced to lowercase) are sorted in binary order. This works for all common alphabets, abjads, abugidas, or even for syllabaries and the Hangul alphabet used in Korean (thanks to the supported NFKD decomposition). However, this does not work with a few scripts whose primary lowercase characters have codepoints that could not be fully assigned by Unicode in ascending binary order (e.g. for the sinographic script used in Chinese, but also for some alphabets whose base lowercase letters were encoded with additional blocks, out of the binary sequential order, and for which the automatic sort key generator cannot replace them by other suitable primary letters in the main alphabetic sequence). For such case, or if a language sorts differently than the default UCA order, the sort order can be customized for specific languages and the automatic sort order (normally used by default for all languages whose sort order is not customized) will not be used. Supporting an automatic sort for Chinese is challenging (it would require the support by Mediawiki, accessible from Scribunto, to generate UCA collation keys for each language from the ICU library, which for now only provides support for case transforms and standard normalizations; fully implementing UCA for sorting in pure Lua would require to maintain large datatables that would slow down the module each time it's used, even for just the language-neutral order using the standard DUCET).
Codes for data items are normally used only internally by this module, but may be displayed (using a builtin default presentation) using a |showcode=1
parameter in templates calling the modules. If these codes are not appropriate and one wans to display other codes, items in each list can specify a note='[CUSTOM-CODE]',
property in the data module: this custom note will be shown just after each displayed wikilink (see an example in Module:Most populous cities of the world, where codes used in the main list of cities are not used but custimized by truncating them to only their leading country code).
Data items for each code can also associate a mark='MARK',
specifying a very brief footnote call, displayed in superscript immediately after each generated wikilink (but before the code or note); the footnote will be generated by an additional formatted section (that contains no list of codes). The datamodule specify how to format these sections and can apply conditional displays (only when one of the items actually generate a visible wikilink in a specified section, whose name appear in the condition encoded after each formating string).
Changes
[edit]Changes should be performed in the appropriate sandbox module and tested using the corresponding sandbox template. For example, a change to the text displayed or the countries listed for Africa would be made in Module:Countries/Africa/sandbox.
{{Countries of Africa/sandbox}} displays its results with:
{{#invoke:Countries/sandbox|main|Africa}}
Use this sandbox template to test changes to the sandbox module for Africa.
Currently supported specializations for list of countries, territories or subdivisions of an area
[edit]The specific modules and their sandboxes defined for list of countries, territories or subdivisions of an area are implemented as the following subpages of the main module, and their associated templates (see Module:Convert/tester).
The sandbox versions of modules should be identical, except temporarily for testing changes (rendered with the sandbox template, in their comparative test cases)
Summary information about each item
[edit]See Module talk:Countries/show for a summary of all information about specific items in lists, including links to the item at Wikidata. If there appears to be an error in the name for a item, find the item in this list, then use the link to the item to check what changes may have occurred at Wikidata.
History
[edit]- Report at phab:T171392 July 2017 (Lua out-of-memory problems resulting in "Error: 503, Service Unavailable").
- Problem discussed at en:WP:VPT August 2017.
- Module started September 2017 based on data and logic copied from Template:Countries of Europe to implement that template.
- Use Module:Redirect to parse soft category redirects in their content. July 2020.