Module:language utilities
This module provides access to Module:languages from templates, so that they can make use of the information stored there.
Usage
កែប្រែlookup_language
កែប្រែThe function lookup_language
queries information about a language code. It is invoked as follows:
{{#invoke:language utilities|lookup_language|(language code)|(item to look up)}} {{#invoke:language utilities|lookup_language|(language code)|(item to look up)|(index)}}
- The language code should be one of the codes that is defined in Module:languages. If it is missing or does not exist, the result will be a script error.
- The item is the name of one of the pieces of data that is stored for a language, such as
names
orscripts
. If no item has been provided, the result will be a script error. However, if the name of a nonexistent item is given, the result will be an empty string. - The index is used for items that are lists, such as
names
orscripts
, and selects which item in the list to return. On items that are single strings, likefamily
, it has no effect. If no index is given, the default will be 1 (the first subitem). 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 default (canonical) name of the language whose code is en
:
{{#invoke:language utilities|lookup_language|en|names}}
- Result:
Script error: The function "lookup_language" does not exist.
To request its second name, if any:
{{#invoke:language utilities|lookup_language|en|names|2}}
- Result:
Script error: The function "lookup_language" does not exist.
To request its family:
{{#invoke:language utilities|lookup_language|en|family}}
- Result:
Script error: The function "lookup_language" does not exist.
language_exists
កែប្រែThis function allows you you check whether a language code exists and is valid. 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.
It is invoked as follows:
{{#invoke:language utilities|language_exists|(language code)}}
This will return "1" if the language code exists, and the empty string "" if it does not.
local export = {}
export.language_exists = require("Module:languages/templates").exists
export.lookup_language = require("Module:languages/templates").lookup
export.family_exists = require("Module:families/templates").exists
export.lookup_family = require("Module:families/templates").lookup
return export