Wikiup:Lua/Modul/ISO3166/en
Vorlagenprogrammierung | Diskussionen | Lua | Test | Unterseiten | |||
Modul | Deutsch | English
|
Modul: | Dokumentation |
ISO3166
– Module for conversion of territory code from ISO 3166 into one of the most current ones.
Historic countries are difficult to retrieve, since code assignment started about 1970 and they were partially reused for other targets later. Division of states does not point to current country, but unification. Only codes known to or reserved by ISO are covered, while other organisations like IOC often collide.
Functions for templates
- f
- Core functionality: convert code
- Parameters:
1
– code to be converted (mandatory)2
– requested format of resultA2
orA3
orNUM
orA4
- Default:
A3
3
– redirect into other territory1
– historic state- Default:
0
– current country
- failsafe
- Version ID (local):
2019-10-14
- Optional parameter:
1
– Minimum version orwikidata
or~
{{#invoke:ISO3166|failsafe}}
yields2019-10-14
- With a parameter as ISO date it is compared whether the current module satisfies this version or later.
{{#invoke:ISO3166|failsafe|2001-01-01}}
returns: »2019-10-14
«{{#invoke:ISO3166|failsafe|2099-01-01}}
returns: »« – (empty), if minimal version condition not matched
- If keyword is
wikidata
, result is version ID registered on Wikidata (2019-10-14
) or local if not found there. - If keyword is
~
, result is empty if local and Wikidata version are the same: (2019-10-14
).
- Returns:
- Empty, if minimal version condition not matched, or
~
and local version is synchronized. - Version ID if no parameter, or if
wikidata
, or local if not found there, or not synchronized.
- Empty, if minimal version condition not matched, or
Examples and test page
There are tests available to illustrate this in practice.
Use in another Lua module
All of the above functions can be called from other Lua modules. Use require()
; the following code checks for errors loading it:
local lucky, ISO3166 = pcall( require, "Module:ISO3166" )
if type( ISO3166 ) == "table" then
ISO3166 = ISO3166.ISO3166()
else
-- In the event of errors, ISO3166 is an error message.
return "<span class=\"error\">" .. ISO3166 .. "</span>"
end
Then there is available:
- ISO3166.f( access, alter, ancient )
-
- access – code to be converted, string
- alter – requested format of result, string, optional,
A3
- ancient – do not redirect into other territory, boolean, optional,
false
- returns: Code as string or
false
if not recognized - ISO3166.fetch( alert )
- (internal) Retrieval of mw.loadData(), extend library object
- alert –
true
for abort byerror()
- Default:
false
– empty table
- Default:
- alert –
- ISO3166.failsafe( atleast )
-
- atleast
optional
nil or minimum version orwikidata
or~
for synchronisation
- atleast
- returns: Version ID as string or
false
Internal sub modules
/loadData
Global data will be converted into a single mw.loadData() table once per rendered page if needed.
- Yields object with components:
codes
– map A2 → space separated sequencereverse
– map anything → A2failsafe
– serial ID
/maintain
Internal – code used as generator of commons:Data:ISO3166/reverse.tab data.
- ISO3166.factory()
- returns: JSON code, string
- ISO3166.failsafe( atleast )
Supports template invocations:
factory
– Test/maintainfailsafe
Global data
- commons:Data:ISO3166/codes.tab
- Assignment of A2 code on space separated list of related codes of the analogous territory.
- In the list the most significant A2 A3 NUM A4 code is to be mentioned first.
- Locally available as mw.loadData()-Module:ISO3166/loadData
- commons:Data:ISO3166/reverse.tab
- Assignment of all codes to the main A2 code.
- Assignment of the same A2 code does mean that this code is valid.
- Locally available as mw.loadData()-Module:ISO3166/loadData
- Generated by /maintain.
Data is centralized and immediately updated, available to all wikis.
Maintainenance
When changing an entry in commons:Data:ISO3166/codes.tab updating of commons:Data:ISO3166/reverse.tab is required by Test/maintain.
Installation on other WMF projects
Follow the steps:
- Copy main module
Module:ISO3166
into your project.- If possible keep the name
ISO3166
. - If another name is required due to conflict or naming convention or non-latin script then choose a different one.
- If possible keep the name
- Register this module at d:Q69799761.
- Copy the following sub module, and keep the chosen root name:
- Ready.
- Consider translation of doc page.
Usage
This is a general library; use it anywhere.
Dependencies
None.