Wikipedia:Lua/Modul/ISO3166/en
Wikipedia: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 resultA2orA3orNUMorA4- 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 orwikidataor~
{{#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: ().
- 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
falseif not recognized - ISO3166.fetch( alert )
- (internal) Retrieval of mw.loadData(), extend library object
- alert –
truefor abort byerror()- Default:
false– empty table
- Default:
- alert –
- ISO3166.failsafe( atleast )
-
- atleast
optional
nil or minimum version orwikidataor~for synchronisation
- atleast
- returns: Version ID as string or
false
Internal sub modules
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
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:ISO3166into 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.
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.