Jump to content

Module:wikimedia language/doc

Neet di̱ Swánga̱lyiatwuki

This is the documentation page for Module:wikimedia language

This module is used to retrieve and manage Wikimedia languages.

Until phab: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 Wiktionary:Language treatment). This module aids in mapping between the two.

This module provides access for other modules. To access the information from within a template, see Module:wikimedia languages/templates.

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

[jhyuk]

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

getByCode

[jhyuk]

getByCode(code)

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

getByCodeWithFallback

[jhyuk]

getByCodeWithFallback(code)

This does the same as getByCode. However, if that function returns nil, 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 :getWikimediaLanguages() method of that language. If that method returns no elements, the function returns nil.

Language objects' getWikimediaLanguages method

[jhyuk]

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

Comparison

[jhyuk]

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

Code Module:languages
.getByCode
Module:languages
.getByCode():getWikimediaLanguages()
Module:wikimedia languages
.getByCode
Module:wikimedia languages
.getByCodeWithFallback
Notes
fr Lua error in package.lua at line 80: module 'Module:language-like' not found./Lua error in package.lua at line 80: module 'Module:language-like' not found. Lua error in package.lua at line 80: module 'Module:language-like' not found./Lua error in Module:wikimedia_languages/templates at line 28: The wikimedia language code '<strong class="error"><span class="scribunto-error mw-scribunto-error-f1e80178">Lua error in package.lua at line 80: module 'Module:language-like' not found.</span></strong>' is not valid.. fr/French fr/French Code used by both Wikimedia and Wiktionary.
bs nil (error) bs/Bosnian bs/Bosnian Code used only by Wikimedia, not Wiktionary.
sh Lua error in package.lua at line 80: module 'Module:language-like' not found./Lua error in package.lua at line 80: module 'Module:language-like' not found. Lua error in package.lua at line 80: module 'Module:language-like' not found./Lua error in Module:wikimedia_languages/templates at line 28: The wikimedia language code '<strong class="error"><span class="scribunto-error mw-scribunto-error-f1e80178">Lua error in package.lua at line 80: module 'Module:language-like' not found.</span></strong>' is not valid..
Lua error in package.lua at line 80: module 'Module:language-like' not found./Lua error in Module:wikimedia_languages/templates at line 28: The wikimedia language code '<strong class="error"><span class="scribunto-error mw-scribunto-error-f1e80178">Lua error in package.lua at line 80: module 'Module:language-like' not found.</span></strong>' is not valid..
Lua error in package.lua at line 80: module 'Module:language-like' not found./Lua error in Module:wikimedia_languages/templates at line 28: The wikimedia language code '<strong class="error"><span class="scribunto-error mw-scribunto-error-f1e80178">Lua error in package.lua at line 80: module 'Module:language-like' not found.</span></strong>' is not valid..
Lua error in package.lua at line 80: module 'Module:language-like' not found./Lua error in Module:wikimedia_languages/templates at line 28: The wikimedia language code '<strong class="error"><span class="scribunto-error mw-scribunto-error-f1e80178">Lua error in package.lua at line 80: module 'Module:language-like' not found.</span></strong>' is not valid..
sh/Serbo-Croatian sh/Serbo-Croatian Code used by both Wikimedia and Wiktionary.
Module:wikimedia languages returns sh as that is a valid Wikimedia code.
:getWikimediaLanguages() maps the code to multiple possible Wikimedia codes.
cmn Lua error in package.lua at line 80: module 'Module:language-like' not found./Lua error in package.lua at line 80: module 'Module:language-like' not found. Lua error in package.lua at line 80: module 'Module:language-like' not found./Lua error in package.lua at line 80: module 'Module:languages/errorGetBy' not found. nil zh/Chinese Code is used only by Wiktionary, not Wikimedia.
The code is mapped by :getWikimediaLanguages() to the equivalent Wikimedia code zh.
wym Lua error in package.lua at line 80: module 'Module:languages/data/3/w' not found./Lua error in package.lua at line 80: module 'Module:languages/data/3/w' not found. nil nil nil Code is used only by Wiktionary, not Wikimedia.
The code is not mapped onto another by :getWikimediaLanguages(), so nil is returned.

WikimediaLanguage objects

[jhyuk]

A WikimediaLanguage 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:

local m_wmlanguages = require("Module:wikimedia languages")
local lang = m_wmlanguages.getByCode("bs")
local name = lang:getCanonicalName()
-- "name" will now be "Bosnian"

Language:getCode

[jhyuk]

:getCode()

Returns the language code of the language. Example: "fr" for French.

Language:getCanonicalName

[jhyuk]

:getCanonicalName()

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

Language:getAllNames

[jhyuk]

: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

[jhyuk]

:getType()

Returns "Wikimedia".

Language:getWiktionaryLanguage

[jhyuk]

:getWiktionaryLanguage()

Returns a Language 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 :getWikimediaLanguages method in on Language objects, this only returns a single object. This is done so that the application of tags and script formatting is unambiguous.

Language:getRawData

[jhyuk]

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