Module:languages/templates/doc
This is the documentation page for Module:languages/templates
This module provides access to Module:languages from templates, so that they can make use of the information stored there.
Usage
[baguhon]If you know a language's code (for example, "en") and you want to find out its canonical name, you can use this:
{{#invoke:languages/templates|getByCode|en|getCanonicalName}}
(returns "English")
If you know a language's canonical name (for example, "English") and you want to find out its code, use this:
{{#invoke:languages/templates|getByCanonicalName|English|getCode}}
(returns "en")
Both of these functions are subst:able (type {{subst:#invoke:
...).
This module provides access to Module:languages from templates, so that they can make use of the information stored there.
Usage
[baguhon]If you know a language's code (for example, "en") and you want to find out its canonical name, you can use this:
{{#invoke:languages/templates|getByCode|en|getCanonicalName}}
(returns "English")
If you know a language's canonical name (for example, "English") and you want to find out its code, use this:
{{#invoke:languages/templates|getByCanonicalName|English|getCode}}
(returns "en")
Both of these functions are subst:able (type {{subst:#invoke:
...).
Exported functions
[baguhon]exists
[baguhon]{{mw:Extension:Scribunto:#invoke|exists|language code}}
Check whether a language code exists and is valid. It will return "1" if the language code exists, and the empty string "" if it does not.
This is rarely needed, because a script error will result when someone uses a code that is not valid, so you do not need this just to check for errors. However, in case you need to decide different actions based on whether a certain parameter is a language code or something else, this function can be useful.
getByCode
[baguhon]{{mw:Extension:Scribunto:#invoke|getByCode|language code|item to look up|index}}
Queries information about a language code.
- The language code should be one of the codes that is defined in Module:languages data. If it is missing or does not exist, the result will be a script error.
- The item is the name of one of the functions of a language object, such as
getCanonicalName
orgetScripts
. If no item has been provided, the result will be a script error. - The index is optional, and is used for items that are lists, such as
getOtherNames
orgetScripts
. It selects which item in the list to return. On items that are single strings, likegetFamily
, it has no effect. If an index is given that is higher than the number of items in the list, the result will be an empty string.
For example, to request the canonical name of the language whose code is en
:
{{#invoke:languages/templates|getByCode|en|getCanonicalName}}
- Result:
Modernong Ingles
To request its second name, if any:
{{#invoke:languages/templates|getByCode|en|getOtherNames|1}}
- Result:
Modernong Ingles
To request its family:
{{#invoke:languages/templates|getByCode|en|getFamily}}
- Result:
gmw
getByCanonicalName
[baguhon]{{mw:Extension:Scribunto:#invoke|getByCanonicalName|language name}}
Gets the language code corresponding to a canonical name.
{{mw:Extension:Scribunto:#invoke|getByCanonicalName|English}}
- ↓
- en
getByName
[baguhon]{{mw:Extension:Scribunto:#invoke|getByName|language name}}
Like the above, except it will also accept other names for the language that are listed in the language's otherNames
field. For instance:
{{mw:Extension:Scribunto:#invoke|getByName|Modern English}}
- ↓
getCanonicalName
[baguhon]{{mw:Extension:Scribunto:#invoke|getCanonicalName|language code}}
Gets the canonical name for a language code if the language code is valid, or else returns an empty string. It uses a table that converts language code to canonical name, generated by Module:languages/code to canonical name. Requires more Lua memory than getByCode
(about 10 megabytes) for a single instance, but may require less memory on pages that call the function many times.
Unlike {{mw:Extension:Scribunto:#invoke|getByCode|<language_code>|getCanonicalName}}
, this function does does not yield a script error for an invalid language code.
{{mw:Extension:Scribunto:#invoke|getCanonicalName|en}}
{{mw:Extension:Scribunto:#invoke|getCanonicalName|invalid code}}
- ↓
English
See also
[baguhon]- Module:JSON data — for exporting all the data at once
See also
[baguhon]- Module:JSON data — for exporting all the data at once