Module:Countries/Oceania/sandbox
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
This documentation is transcluded from Module:Countries/Africa/doc.
The countries and text displayed for a particular region are defined in a subpage of Module:Countries. For example, Module:Countries/Africa lists the countries in Africa and defines text such as "Countries of Africa" that is displayed if the user's language is en, and "Staaten in Afrika" if it is de. Country names are obtained from Wikidata.
How to create data modules
[edit]Translated section titles
[edit]Each section under titles
defines text that depends on the current user's language. The procedures that apply to {{Fallback}} are used to determine which language should be used.
TODO: Standard titles should be defined in one module so they do not need to be duplicated for each countries submodule. Only items listed in each section are translated once from Wikidata labels. This may require adding also Wikidata entries for them (or locating existing Wikidata items for their topic), and being able to select their plural form when needed.
Pattern or ordered list of subpatterns
[edit]Module:Countries/Africa defines pattern
twice. The first is a pattern for the text that is normally displayed by {{Countries of Africa}}, while the second applies when the parameter |simple=yes
is used.
Each occurrence of {name}
in the pattern is replaced with appropriate text. The names used for Africa when simple does not apply are:
Name | Description |
---|---|
{lang} |
User's language from {{Int:Lang}} such as "en" or "de".
|
{dir} |
Direction "ltr" or "rtl" selected using lang. |
{colon} |
Equivalent of ": " from {{Colon|lang={{Int:Lang}}}} ; do not insert any space after it.
|
{maintitle} |
Title from titles.main selected using lang.
|
{othertitle} |
Title from titles.other selected using lang.
|
{mainlist} |
List of country codes from lists.main selected using lang.
|
{otherlist} |
List of country codes from lists.other selected using lang.
|
{partlylist} |
List of country codes from lists.partly used to render a note only (this list is not sorted by languages as it is not displayed, but it provides the condition for which the note will be added, i.e. when one of the other lists includes a country which is displayed with an extra mark calling for this note).
|
You can specify patterns in various ways, the simplest one being a single string containing all the layout wikitext and {name}
placeholders described above. This will only generate a static list with a single layout.
But you can also split the pattern into multiple "conditional supatterns" (all of them containing arbitrary wikitext or {name}
placeholders), and put them in an ordered table, in the order in which they must appear on the result. This allows some fragments of the layout to be removed (for example dropping the section title if the list after it in the same section is empty, or dropping the static separators between sections).
Each "conditional subpattern" is represented either:
- as a simple string like
'subpattern with {name} placeholders'
when there's no condition (this unconditional pattern will be always added to the result), or - as an ordered table, where:
- first element is a string for the subpattern, and
- the other elements represent an union of several (non-exclusive) "conditions"
- for example,
{ 'subpattern with {name} placeholders', condition1, condition2, ... }
- (if any one of the listed conditions evaluates to true (OR), the conditional subpattern will be used).
Each "condition" listed in a array after the initial subpattern may itself be represented either:
- as a simple string for "simple conditions", or
- as an ordered table of "subconditions", i.e. a conjunction of several (non-exclusive) simple conditions
- for example,
{ 'subpattern with {name} placeholders', { subcondition1, subcondition2, ... }, ... }
- (if any one of the subconditions evaluates to false (AND), the conditional subpattern will NOT be used according to this condition, but may be used if other conditions part of the union allow it).
- for example,
Each "simple condition" is used to evaluate tests based on names of variables (usable in placeholders of patterns or subpatterns). A simple condition is represented by a string and can currently take one the following forms:
'name'
: the simple condition is true if the variable with that name is non-empty (i.e. the subpattern{name}
would be replaced by an actual text);'!name'
: the simple condition is true if the variable with that name is empty (i.e. the subpattern{name}
would be replaced by nothing);
The variable names used in simple conditions don't need to be present within the "conditional subpattern" string to which the condition applies (indicated at start of the table describing the conditional subpattern). This means for example that a subpattern continaining only static wikitext and no {name}
placeholder, can be conditional. This is useful notably
- to generate static wikitext (for example breaks or punctuation or other presentational elements), that will be present in the result only if other conditional patterns actually generate text (depending on their own placeholders).
- to suppress every layout elements surrounding the inner content, when there's nothing useful to display: the result can then be entirely empty.
Simple presentation in a single section
[edit]If the template that invokes the module has |simple=yes
, the simple
section is used.
simple.pattern
replacespattern
simple.sections
specifies which sections fromtitles
andlists
will be processed.
In Module:Countries/Africa, simple.sections
has
main = { EH = true, },
The fact that main
is defined means that titles.main
and lists.main
will be used. The fact that other
is not defined means that titles.other
and lists.other
will be ignored.
EH = true
is used when simple does not apply. When the template is used normally (without |simple=yes
), the country identified by EH
is ignored. That is done because EH is included in the other
section. However, with |simple=yes
, EH
will appear in the main
section.
The simple version can also use a single pattern, or multiple conditional subpatterns like previously.
Orderable lists of items, one for each section
[edit]Each section under lists
defines the list of country codes that will be used to display country names. Similarly to titles
, the list depends on the current user's language.
Countries are listed in the order specified. If the default order is unsatisfactory for a particular language, an entry for the language can be added. The entry should include all the country codes in a suitable order.
For example, lists.main
may include the following (...
replaces some text omitted for simplicity).
main = { english = 'automatic', default = 'automatic sorted', en = 'automatic sorted', mk = 'DZ AO BJ BW BF BI CM CAVE CF TD KM CI ... SADR EH ZM ZW', automatic = 'DZ AO BJ BW BF BI CM CAVE CF TD KM CD ... UG EH ZM ZW', },
Each country code such as DZ
is defined under countries
. All lists should contain the same codes, only ordered differently depending on language; every localized list (keyed by language code) should then have exactly the same length as the one given for the 'automatic'
list (which is required), or should be one of 'automatic sorted'
or 'automatic'
.
The following keys have special meaning when used before =
.
automatic |
Must be defined if any other parameter is set to 'automatic' or 'automatic sorted' . The listed codes should be ordered according to the English names, so that they don't need sorting (see below).
|
default |
The fallback entry used if the user's language is not defined ({{Fallback}} falls back to en if it is defined and no more applicable entry is defined).
|
english |
The entry used if the user's language is en . This is an optimization to avoid the overhead of automatic processing for a commonly used language.
|
The following values have special meaning when used after =
.
'automatic' |
This entry will use the list of country codes defined in the automatic = '...' parameter.
|
'automatic sorted' |
Same as 'automatic' but (unless option all is set) the country names will be reordered using a crude sorting algorithm.
|
A module is not able to properly collate names for a language other than en
. However, Module:Countries can satisfactorily collates some names that use letters with diacritics which sort after their equivalent letters.
The collation (performed only when the option all
is not set when calling the main function Module:Countries) is based on a function, defined in Module:MakeSortKey, creating sort keys from a translated label and the target language code (this language code could be later used to tailor the collation according to sorting rules for specific languages, but for now the sort order is locale-neutral). Generally, this sorting works for most languages, but the localisation may be needed to take into account ignorable prefixes, or for complex scripts that still have no support for a basic collation order.
Definitions of each list item
[edit]Several examples from a countries table follow:
countries = { CI = { 'Ivory Coast', "Côte d'Ivoire", qid = 'Q1008', }, DZ = { 'Algeria', qid = 'Q262', }, EG = { 'Egypt', qid = 'Q79', mark = '‡', }, GM = { 'Gambia', qid = 'Q1005', the = true, }, XBRTW = { 'Bir Tawil', qid = 'Q620634', }, }
CI
, DZ
, EG
, and GM
are country codes that identify a particular country. Where available, ISO 3166-2 codes are used, but any code can be used as they only have a meaning within the module (you should use a private extension, starting by "X", of ISO 3166-1 if the territory is part of another recognized country but has no ISO 3166-2 code, or use one of the prefixes reserved in ISO 3166-1 for private use, like "AA", "QM" to "QZ", "X", or "ZZ").
- Note that Module:Countries is generic and is not restricted for listing only countries, it can process any list of up to 200 known items; the key defined as
countries = {...}
above can be alternatively namedinfos = {...}
with the same content for list items.
The country names Algeria
and Gambia
are the titles of pages which should exist at Commons, and where the category page generally also exists. English names should be used but need to match names used in titles of titles in Commons. If several alternative names are used in Commons to refer to the same country in related page titles (such as "Côte d'Ivoire"), you may list these alternate names.
The qid
codes identify the corresponding item at Wikidata. It allows translating the displayed label in the user's language (when option all
is not set to render the box). For example,
- d:Q262 on Wikidata is associated to Algeria on Commons, and will also be used to get the translated label for other related pages like Category:Algeria
- d:Q1005 on Wikidata is associated to Gambia on Commons, and will also be used to get the translated label for other related pages like Category:Gambia
If the |all=yes
option is not set to render the box, or if qid
is not defined, or if qid
is not found in Wikidata, or Wikidata does not define a label for it, then the first name listed in the data defining the country (normally in English and used in page titles in Commons) will be used as a default (untranslated) label.
Normally, a link is shown in the rendered bulleted lists only if the page exists.
But when rendering the list with |all=yes
option, all possible page titles will be listed, without testing their existence, and without translating the displayed labels (this will frequently generate red links, but it allows the maintenance of page names on Commons, to find those that redirect to unexpected pages, or to facilitate the creation of missing pages with coherent titles that will be found and used when the |all=yes
option will be removed to hide all possible aliases from the list and to get translated and sorted labels).
The entry for Gambia illustrates use of the optional the
in country's data, whose effect is that the Gambia is tested for existence before Gambia: if a page exists in Commons using the
in its title, this page will be selected as the target of the link.
The wikitext for each link has the following form:
[[PrefixTitleSuffix|<bdi>Label</bdi>]]
Prefix | Consists of the specified prefix and separator (or space). |
Title | The name specified in the countries table, possibly prefixed by the (only if the data defining a country code includes the = true ).
|
Suffix | Consists of the specified separator (or space) and suffix. |
bdi | bidirectional isolation in HTML |
Label | The label from Wikidata for the specified qid in the current user's language.
|
The entry for Egypt illustrates use of the optional mark
in country's data, whose effect is that a superscripted mark will be added after the label. This is used as a note call, which will be rendered at bottom of the table. If you use such marks, you should create a conditional section (such as "partly") which lists all concerned codes (in arbitrary code order); this list will not be rendered, but will appear conditionally if any one of the listed codes is displayed from the other lists.
Related modules and templates
[edit]This list (currently maintained in Module:Convert/tester) is partial but contains the most frequently used modules. It autodetects differences between the normal modules and templates and their sandbox version, and list their associated testcases and talk pages (when they exist).
It also shows that the main module is not necessarily used for listing countries (or territories), it could be used as well to create navigation boxes for lists of cities, chemical elements, and so on, provided that these lists are bounded, wellknown and stable over years (and not overlong) : if a list contains more than 200 items, consider generated separate modules and navbox for sublists using some criteria). New data modules also don't necessarily have to be created and named as subpages of Module:Countries.
The sandbox versions of modules should be identical, except temporarily for testing changes (rendered with the sandbox template, in their comparative test cases)
How to make changes and preview them using sandboxes
[edit]For example, {{Countries of Africa/sandbox}}
displays:
Limited recognition: Ambazonia · Azawad · Puntland · Sahrawi Arab Democratic Republic · Somaliland – Other areas: Bir Tawil · Canary Islands · Ceuta · Madeira · Mayotte · Melilla · Réunion · Saint Helena, Ascension and Tristan da Cunha · Scattered Islands in the Indian Ocean · Western Sahara
‡: partly located in Africa
If the user's language is en, Module:Countries/Africa/sandbox could be edited and
en = 'Countries of Africa',
changed to
en = 'African countries',
Do not save the change. Instead, under "Preview page with this template" enter the title of this page
Module:Countries/Africa/doc
then click "Show preview". That will display this documentation page including the output from the above {{Countries of Africa/sandbox}} template. The output will start with "African countries" instead of "Countries of Africa". In the same manner, other changes could be made and previewed before saving the changes. Close the current browser window without saving the changes to discard them (or get back to a previous page using the button of the browser navigating in the session history).
Before updating the main data module, changes should be made in the sandbox data module and tested with the sandbox template.
Code
--[=[
Data defining countries for {{#invoke:Countries|main|Oceania}}.
Output is pattern after making these substitutes:
{lang} User's language from {{int:lang}} such as 'en' or 'de'.
{dir} Language direction 'ltr' or 'rtl'.
{colon} Language equivalent of ": " from {{colon|lang}}.
{XYZtitle} Title for lang from XYZ section of defined titles.
{XYZlist} List of countries for lang from XYZ section of defined lists.
XYZ must be alphanumeric [A-Za-z0-9] but are generally lowercase only.
]=]
return {
titles = {
main = {
default = 'Countries of Oceania',
ar = 'بلدان أوقيانوسيا',
['be-tarask'] = 'Краіны Акіяніі',
bn = 'ওশেনিয়ার দেশসমূহ',
ca = 'Països d’Oceania',
cs = 'Státy Oceánie',
de = 'Staaten in Ozeanien',
en = 'Countries of Oceania',
es = 'Países de Oceanía',
fa = 'کشورهای اقیانوسیه',
fi = 'Oseanian valtiot',
fr = 'Pays d’Océanie',
he = 'ארצות אוקיאניה',
hi = 'ओशिनिया के देश',
id = 'Negara-negara Oceania',
it = 'Paesi dell’Oceania',
ja = 'オセアニアの国',
ko = '오세아니아 국가',
mk = 'Земји во Океанија',
ml = 'ഓഷ്യാനിയയിലെ രാജ്യങ്ങൾ',
nb = 'Land i Oseania',
nl = 'Landen van Oceanië',
nn = 'Land i Oseania',
no = 'Land i Oseania',
pl = 'Kraje Oceanii',
pt = 'Países da Oceania',
ru = 'Страны Океании',
sh = 'Države Oceanije',
si = 'ඕෂනියා රටවල්',
sl = 'Države Oceanije',
sr = 'Државе у Океанији',
['sr-latn'] = 'Države u Okeaniji',
sv = 'Länder i Oceanien',
th = 'ประเทศในโอเชียเนีย',
tok = 'ma mute pi ma Osejanija',
uk = 'Країни Океанії',
ur = 'اوکنیا ممالک',
vi = 'Các nước Châu Đại Dương',
['zh-hans'] = '大洋洲国家',
['zh-hant'] = '大洋洲國家',
},
other = {
default = 'Other areas',
ar = 'أقاليم أخرى',
['be-tarask'] = 'Іншыя тэрыторыі',
bn = 'অন্যান্য অঞ্চল',
ca = 'Altres territoris',
cs = 'Jiná území',
de = 'Weitere Gebiete',
en = 'Other areas',
es = 'Otros territorios',
fa = 'سرزمین های دیگر',
fi = 'Muut alueet',
fr = 'Autres territoires',
he = 'טריטוריות אחרות',
hi = 'अन्य क्षेत्र',
id = 'Wilayah lain',
it = 'Altri territori',
ja = 'その他の地域',
ko = '기타 지역',
mk = 'Други подрачја',
ml = 'മറ്റ് പ്രദേശങ്ങൾ',
nb = 'Andre områder',
nl = 'Andere gebieden',
nn = 'Andre område',
no = 'Andre områder',
pl = 'Inne terytoria',
pt = 'Outros territórios',
ru = 'Другие территории',
si = 'වෙනත් ප්රදේශ',
sl = 'Druga območja',
sr = 'Друге територије',
['sr-latn'] = 'Druge teritorije',
sv = 'Övriga territorier',
th = 'ดินแดนอื่น ๆ',
uk = 'Інші території',
ur = 'دیگر علاقوں',
vi = 'Các lãnh thổ khác',
['zh-hans'] = '其他地区',
['zh-hant'] = '其他地區',
},
part = {
default = 'Partly',
['be-tarask'] = 'Часткова',
ca = 'Parcialment',
cs = 'Částečně',
en = 'Partly',
es = 'Parcialmente',
fi = 'Osittain',
fr = 'En partie',
ml = 'ഭാഗികം',
nb = 'Delvis',
nn = 'Delvis',
no = 'Delvis',
ru = 'Частично',
sl = 'Delno',
sr = 'Делимично',
['sr-latn'] = 'Delimično',
sv = 'Delvis',
uk = 'Частково',
['zh-hans'] = '部分',
['zh-hant'] = '部分',
},
},
pattern = {
{ '<div lang="{lang}" dir="{dir}" class="catlinks" ' ..
' style="clear:none;display:table;box-sizing:border-box;font-size:88%;line-height:normal;margin:2px 0;padding:2px"><div style="display:table-cell>',
'mainlist',
'otherlist',
'partlist',
},
{ '<em>{maintitle}{colon}</em>',
{ 'maintitle', 'mainlist', },
},
'{mainlist}',
{ '<br />',
{ 'mainlist', 'otherlist', },
{ 'mainlist', 'partlist', },
},
{ '<em>{othertitle}{colon}</em>',
{ 'othertitle', 'otherlist', },
},
'{otherlist}',
{ ' – ',
{ 'otherlist', 'partlist', },
},
{ '<em>{parttitle}{colon}</em>',
{ 'parttitle', 'partlist', },
},
'{partlist}',
{ '</div></div>',
'mainlist',
'otherlist',
'partlist',
},
},
simple = {
pattern = {
{ '<div lang="{lang}" dir="{dir}" class="catlinks"' ..
' style="clear:none;display:table;box-sizing:border-box;font-size:88%;line-height:normal;margin:2px 0;padding:2px"><div style="display:table-cell>',
'mainlist',
},
{ '<em>{maintitle}{colon}</em>',
{ 'maintitle', 'mainlist', },
},
'{mainlist}',
{ '</div></div>',
'mainlist',
},
},
sections = {
-- List of sections to be displayed if simple=yes.
-- Each value is a table identifying any country code that is added to that section only if simple=yes.
main = {
AS = true,
CC = true,
CK = true,
GU = true,
MP = true,
NF = true,
NU = true,
PN = true,
FROVS = true,
TK = true,
UKBOT = true,
UM = true,
USHI = true,
},
},
},
lists = {
-- List of countries in an order suitable for display in the specified language.
main = {
-- Don't add keys from other sections, except when they are only displayed with simple=yes (see above).
default = 'automatic sorted', -- currently unused because en is defined
en = 'automatic sorted', -- this applies with uselang=XX where XX is not defined here
english = 'automatic', -- this applies with uselang=en
automatic = 'AS AU UKBOT CK FJ FM USHI KI MH NR NZ NU NF MP PW FROVS PG WS SB TO TV UM VU',
fr = 'AS AU UKBOT CK FM FJ USHI MH KI NR NZ NU NF MP PW FROVS PG SB WS TO TV UM VU',
['zh-hans'] = 'AU PG MP FROVS FJ KI CK MH UM AS FM NR NU NF PW WS SB TO TV VU USHI NZ UKBOT',
['zh-hant'] = 'AU PG MP PW TO FROVS FJ KI CK MH UM AS FM NU NZ NR NF WS SB TV VU USHI UKBOT',
['zh-hk'] = 'AU PG MP PW FROVS FJ KI CK MH UM AS FM NR NU NZ NF WS SB TO TV VU USHI UKBOT',
},
other = {
default = 'automatic sorted', -- currently unused because en is defined
en = 'automatic sorted',
english = 'automatic', -- this applies with uselang=en
automatic = 'AS CP CC CK PF GU USHI NC NU NF MP PN TK WF',
fr = 'GU USHI CP CC CK MP NU NF NC PN PF AS TK WF',
['zh-hans'] = 'MP PF GU CC CP CK AS NU NF WF TK USHI NC PN',
['zh-hant'] = 'MP PF GU CC CP CK AS NU NF WF TK USHI NC PN',
},
part = {
default = 'automatic sorted', -- currently unused because en is defined
en = 'automatic sorted',
english = 'automatic', -- this applies with uselang=en
automatic = 'UKBOT FROVS ID TF UM',
fr = 'FROVS UM ID TF UKBOT',
['zh-hans'] = 'FROVS TF ID UM UKBOT',
['zh-hant'] = 'FROVS TF ID UM UKBOT',
},
},
countries = {
-- Keys are arbitrarily but conveniently chosen as capital codes from ISO3166-1 (2 letters) or ISO3166-2 (without separator),
-- or extensions for specific regions. They must just match keys used in lists above, and have no other meaning outside this module.
AS = { 'American Samoa', qid = 'Q16641', },
AU = { 'Australia', qid = 'Q408', subst = { ['by state'] = 'by state or territory', }, },
CC = { 'Cocos (Keeling) Islands', qid = 'Q36004', the = true, },
CK = { 'Cook Islands', qid = 'Q26988', the = true, },
CP = { 'Clipperton Island', qid = 'Q161258', },
FJ = { 'Fiji', qid = 'Q712', },
FM = { 'Federated States of Micronesia',
qid = 'Q702', the = true, },
FROVS = { 'Overseas France', qid = 'Q203396', },
GU = { 'Guam', qid = 'Q16635', },
ID = { 'Indonesia', qid = 'Q252', },
KI = { 'Kiribati', qid = 'Q710', },
MH = { 'Marshall Islands', qid = 'Q709', the = true, },
MP = { 'Northern Mariana Islands',
qid = 'Q16644', the = true, },
NC = { 'New Caledonia', qid = 'Q33788', },
NF = { 'Norfolk Island', qid = 'Q31057', },
NR = { 'Nauru', qid = 'Q697', },
NU = { 'Niue', qid = 'Q34020', },
NZ = { 'New Zealand', qid = 'Q664', },
PF = { 'French Polynesia', qid = 'Q30971', },
PG = { 'Papua New Guinea', qid = 'Q691', },
PN = { 'Pitcairn Islands', qid = 'Q35672', the = true, },
PW = { 'Palau', qid = 'Q695', },
SB = { 'Solomon Islands', qid = 'Q685', the = true, },
TF = { 'French Southern and Antarctic Lands',
qid = 'Q129003', the = true, },
TK = { 'Tokelau', qid = 'Q36823', },
TO = { 'Tonga', qid = 'Q678', },
TV = { 'Tuvalu', qid = 'Q672', },
UKBOT = { 'British Overseas Territories', 'British overseas territories',
qid = 'Q46395', the = true, },
UM = { 'United States Minor Outlying Islands',
qid = 'Q16645', the = true, },
USHI = { 'Hawaii', qid = 'Q782', },
VU = { 'Vanuatu', qid = 'Q686', },
WF = { 'Wallis and Futuna', qid = 'Q35555', },
WS = { 'Samoa', qid = 'Q683', },
},
}