Mòideal:languages/doc
This is the documentation page for Mòideal:languages
Uses Lua: |
Related pages |
---|
(deasbaireachd⧼tpt-languages-separator⧽ ⧼tpt-languages-separator⧽eachdraidh⧼tpt-languages-separator⧽ceanglaichean⧼tpt-languages-separator⧽doc⧼tpt-languages-separator⧽bogsa-gainmhich⧼tpt-languages-separator⧽cùisean deuchainn)
Editing of this module by new or unregistered users is currently disabled. See the protection policy and protection log for more details. If you cannot edit this module and you wish to make a change, you can submit an edit request, discuss changes on the talk page, request unprotection, log in, or create an account. |
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This module is used to retrieve and manage Wiktionary's various languages and the information associated with them. See {{enUicl|Languages]] for more information.
This module provides access to other modules. To access the information from within a template, see Mòideal:languages/templates.
The information itself is stored in the various data modules that are subpages of this module. They are listed in Roinn-seòrsa:Language data modules. These modules should not be used directly by any other module, the data should only be accessed through the functions provided by Mòideal:languages.
Finding and retrieving languages
The module exports a number of functions that are used to find languages.
getByCode
getByCode(code)
Finds the language whose code matches the one provided. If it exists, it returns a Language
object representing the language. Otherwise, it returns nil
.
getByCanonicalName
getByCanonicalName(name)
Finds the language whose canonical name (the name used to represent that language on Wiktionary) matches the one provided. If it exists, it returns a Language
object representing the language. Otherwise, it returns nil
. The canonical name of languages should always be unique (it is an error for two languages on Wiktionary to share the same canonical name), so this is guaranteed to give at most one result.
findByName
findByName(name, inexact)
- This function is expensive
Finds languages which have the provided name among their list of possible names (including their canonical name). It returns a table containing Language
objects for the languages found, or an empty table if none were found.
The inexact
parameter can be given as true
to perform a substring search of the name instead of an exact match. The result will then contain all languages that have the provided name as part of one of their possible names.
This function searches through the whole database of languages, and is therefore relatively resource-intensive. It should be used sparingly.
getAll
getAll()
- This function is expensive
Returns a table containing Language
objects for all languages, sorted by code.
This function searches through the whole database of languages, and is therefore relatively resource-intensive. It should be used sparingly.
Language objects
A Language
object is returned from one of the functions above. It is a Lua representation of a language and the data associated with it. It has a number of methods that can be called on it, using the :
syntax. For example:
local m_languages = require("Mòideal:languages")
local lang = m_languages.getByCode("fr")
local name = lang:getCanonicalName()
-- "name" will now be "French"
Language:getCode
:getCode()
Returns the language code of the language. Example: "fr"
for French.
Language:getCanonicalName
:getCanonicalName()
Returns the canonical name of the language. This is the name used to represent that language on Wiktionary, and is guaranteed to be unique to that language alone. Example: "French"
for French.
Language:getAllNames
:getAllNames()
Returns a table of all names that the language is known by, including the canonical name. The names are not guaranteed to be unique, sometimes more than one language is known by the same name. Example: {"French", "Modern French"}
for French.
Language:getType
:getType()
Returns the type of language, which can be "regular"
, "reconstructed"
or "appendix-constructed"
.
Language:getWikimediaLanguages
:getWikimediaLanguages()
Returns a table containing WikimediaLanguage
objects (see Mòideal:wikimedia languages), which represent languages and their codes as they are used in Wikimedia projects for interwiki linking and such. More than one object may be returned, as a single Wiktionary language may correspond to multiple Wikimedia languages. For example, Wiktionary's single code sh
(Serbo-Croatian) maps to four Wikimedia codes: sh
(Serbo-Croatian), bs
(Bosnian), hr
(Croatian) and sr
(Serbian).
The code for the Wikimedia language is retrieved from the wikimedia_codes
property in the data modules. If that property is not present, the code of the current language is used. If none of the available codes is actually a valid Wikimedia code, an empty table is returned.
Language:getScripts
:getScripts()
Returns a table of Script
objects for all scripts that the language is written in. See Mòideal:scripts.
Language:getFamily
:getFamily()
Returns a Family
object for the language family that the language belongs to. See Mòideal:families.
Language:getAncestors
:getAncestors()
Returns a table of Language
objects for all languages that this language is directly descended from. Generally this is only a single language, but creoles, pidgins and mixed languages can have multiple ancestors.
Language:getCategoryName
:getCategoryName()
Returns the name of the main category of that language. Example: "French language"
for French, whose category is at Roinn-seòrsa:French language.
Language:makeEntryName
:makeEntryName(term)
Converts the given term into the form used in the names of entries. This removes diacritical marks from the term if they are not considered part of the normal written form of the language, and which therefore are not permitted in page names. It also removes certain punctuation characters like final question marks or periods which are never present in page names. Example for Latin: "amō"
→ "amo"
(macron is removed).
The replacements made by this function are defined by the entry_name
setting for each language in the data modules.
Language:makeSortKey
:makeSortKey(term)
Creates a sort key for the given, following the rules appropriate for the language. This removes diacritical marks from the term if they are not considered significant for sorting, and may perform some other changes. Any initial hyphen is also removed, and anything parentheses is removed as well.
The replacements made by this function are defined by the sort_key
setting for each language in the data modules.
Language:transliterate
:transliterate(text, sc, module_override)
Transliterates the text from the given script into the Latin script (see {{enUicl|Transliteration and romanization]]). The language must have the translit_module
property for this to work; if it is not present, nil
is returned.
The sc
parameter is handled by the transliteration module, and how it is handled is specific to that module. Some transliteration modules may tolerate nil
as the script, others require it to be one of the possible scripts that the module can transliterate, and will show an error if it's not one of them. For this reason, the sc
parameter should always be provided when writing non-language-specific code.
The module_override
parameter is used to override the default module that is used to provide the transliteration. This is useful in cases where you need to demonstrate a particular module in use, but there is no default module yet, or you want to demonstrate an alternative version of a transliteration module before making it official. It should not be used in real modules or templates, only for testing. All uses of this parameter are tracked by Teamplaid:tracking/module_override.
Language:getRawData
:getRawData()
- This function is not for use in entries or other content pages.
Returns a blob of data about the language. The format of this blob is undocumented, and perhaps unstable; it's intended for things like the module's own unit-tests, which are "close friends" with the module and will be kept up-to-date as the format changes.