Module:wikimedia languages/documentation

This module is used to retrieve and manage Wikimedia languages.

Until T10217 is fixed there is a mis-match between the codes used by ISO 639, and those used by Wikimedia, for certain languages. There are also some languages that are recognised as distinct by Wikimedia, but are combined into other languages on Wiktionary (see Language treatment). This module aids in mapping between the two.

The information itself is stored in Module:wikimedia languages/data. This modules should not be used directly by any other module, the data should only be accessed through the functions provided by Module:wikimedia languages.

Finding and retrieving languages
The module exports a number of functions that are used to find languages.

getByCode
Finds the Wikimedia language whose code matches the one provided. If it exists, it returns a  object representing the language. Otherwise, it returns.

getByCodeWithFallback
This does the same as. However, if that function returns, then the regular language with that code is retrieved, if it exists. The function then returns the first element of the list returned by a call to the  method of that language. If that method returns no elements, the function returns.

Language objects' getWikimediaLanguages method
The  method is available on regular   objects (as returned by Module:languages). This method returns  objects that represent that language outside Wiktionary.

Comparison
The differences between the various ways of retrieving languages can be seen here, using some examples.

WikimediaLanguage objects
A  object is returned from one of the functions above. It is a Lua representation of a Wikimedia language and the data associated with it. It has a number of methods that can be called on it, using the  syntax. For example:

Language:getCode
Returns the language code of the language. Example:  for French.

Language:getCanonicalName
Returns the canonical name of the language. This is the name used to represent that language on Wiktionary. Example:  for French.

Language: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:  for French.

Language:getType
Returns "Wikimedia".

Language:getWiktionaryLanguage
Returns a  object (see Module:languages) that represents the Wiktionary-native language that is equivalent to this Wikimedia language. In most cases, this will be the same code and name as the original Wikimedia language, but a few of them differ.

Note that unlike the  method in on   objects, this only returns a single object. This is done so that the application of tags and script formatting is unambiguous.

Language: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.

af:Module:Wikimedia-tale