Modul:languages
Bearbeitungsstand: Es sind alle Namen für die Sprachen geändert, die wir bisher schon in den alten Vorlagen als Bezeichnung verwendet haben. Darüberhinaus sind nur wenige bisher mit einer plattdeutschen Bezeichnung versehen.
Dieses Modul enthält Definitionen und Metadaten für alle Sprachkode im Wöörbook. Siehe Wiktionary:Spraken für nähere Informationen.
This module must not be imported using require
. Instead, it is imported like this:
local m_languages = mw.loadData("Module:languages")
This ensures that the data is only loaded once per page, rather than once for every module invocation like normal.
To access this data from templates, use Module:language utilities.
Required values
ännernEvery entry in the table must contain the following properties:
names
- A list of all the names that this language is known by. The first name listed is always the "canonical" name, which is used in Wiktionary entries and category names. The list should include not only synonyms for the language, but also names that refer to language varieties that are subsumed under the same grouping. For example, while "Flemish" is not synonymous with "Dutch", Flemish is considered a part of Dutch, so the name is listed there.
type
- The type of language (which affects how it is handled on Wiktionary). Possible values are:
regular
- This language is attested according to WT:CFI and therefore permitted in the main namespace. There may also be reconstructed terms for the language, which are placed in the Appendix namespace and must be prefixed with * to indicate a reconstruction. Most languages should use this.reconstructed
- This language is not attested according to CFI, and therefore is allowed only in the Appendix namespace. All terms in this language are reconstructed, and must be prefixed with *.appendix-constructed
- This language is attested but does not meet the additional requirements set out for constructed languages (WT:CFI#Constructed languages). Its entries must therefore be in the Appendix namespace, but they are not reconstructed and therefore should not have * prefixed in links.
scripts
- A list of script codes, see Wiktionary:Scripts. These represent all the scripts (writing systems) that this language employs, which are used on the main category of the language. If you do not know the script, use "None".
- Most templates and modules will use a default script when no script is specified for them, but the script codes are interpreted in two different ways:
- Templates and modules that use
detect_script
in Module:utilities will try to detect the script (based on the characters in the text), using the list of scripts as a list of possible scripts to try to detect. If the script cannot be detected, the first listed script is used by default. - All other templates and modules will generally use the first script listed as the default script.
- Templates and modules that use
family
- The code for the family that the language belongs to. See Wiktionary:Families. If you do not know the family, use "qfa-und".
Optional values
ännernThe following properties are used for text substitution; they replace or remove certain (sets of) characters or sets of characters. They all work similar, and are all optional. The search and replacement patterns are those used by the standard mw.ustring.gsub
function. They resemble regular expressions; see search/replace patterns for more information.
If present, each of these properties must be a table that contains two tables, one named from
and one named to
. These two tables are organised pairwise: each element in from
is a pattern to identify which characters in the term to replace, while the corresponding element in to
defines what to replace them with. If the replacement is not present or if it is false
or nil
, it defaults to an empty replacement, meaning that the matching characters are removed altogether. This means that the from
list can be longer than the to
list, and an empty replacement will be assumed for any elements in from
that have no counterpart in to
.
At the top of the module, there is a list of combining characters with names. These are provided for convenience and readability, as combining characters generally do not display property inside the module code (although they do not affect the actual operation of the module).
entry_name
- Defines replacements to create the entry name from the displayed form of a term. This can be used to remove certain diacritical marks according to the customs or standard practice of the language. For example, it is used to remove accent marks from Russian words, or macrons from Latin or Old English words, as these are not used in the normal written form of these languages. This is used by
remove_diacritics
in Module:links. sort_key
- Defines replacements to create a category sort key from the page name. The purpose is to remove any characters that are ignored in sorting, and to replace similar characters with identical ones if the sorting rules for that language do not distinguish them. For example, in German, the characters "ä" and "a" are considered equivalent for sorting, and are both treated as "a". The page name is converted to lowercase before applying the replacements, so you should not add uppercase letters to the "from" lists. This is used by
format_categories
in Module:utilities.
These are other optional values:
genders
- A list of gender specifications that are valid for the language. These are given in the format of Module:gender and number. This value acts as a restriction, so that if it is left out, all genders are considered valid. If the language has no genders, meaning that no gender is valid for that language, specify an empty list,
genders = {}
. Keep in mind that the word "gender" is used loosely in the sense of Wiktionary's implementation: it includes not just actual grammatical gender, but also grammatical number, noun classes and even verbal aspects. Thus, a language such as Russian will need to list not only the noun genders, but also the "impf" and "pf" codes for verbs, otherwise these will be rejected. translit_module
- The name of a module that is used to generate transliterations of terms, without the Module: prefix. This module must export a function named
tr
that is defined as follows:tr(text, lang, sc)
- The three parameters are the text to be transliterated, the language code, and the script code. The function can ignore the language and script codes, but they are provided for cases when a language has more than one script, or when a single function is used to transliterate multiple languages sharing the same script.
local export = {}
local Language = {}
function Language:getCode()
return self._code
end
function Language:getCanonicalName()
return self._rawData.names[1]
end
function Language:getKoppnaam()
return self._rawData.koppnaam[1]
end
function Language:getAllNames()
return self._rawData.names
end
function Language:getOtherNames()
if not self._otherNames then
self._otherNames = {}
for i, val in ipairs(self._rawData.names) do
if i > 1 then
table.insert(self._otherNames, val)
end
end
end
return self._otherNames
end
function Language:getType()
return self._rawData.type
end
function Language:getWikimediaLanguages()
if not self._wikimediaLanguageObjects then
local m_wikimedia_languages = require("Module:wikimedia languages")
self._wikimediaLanguageObjects = {}
local wikimedia_codes = self._rawData.wikimedia_codes or {self._code}
for _, wlangcode in ipairs(wikimedia_codes) do
table.insert(self._wikimediaLanguageObjects, m_wikimedia_languages.getByCode(wlangcode))
end
end
return self._wikimediaLanguageObjects
end
function Language:getScripts()
if not self._scriptObjects then
local m_scripts = require("Module:scripts")
self._scriptObjects = {}
for _, sc in ipairs(self._rawData.scripts) do
table.insert(self._scriptObjects, m_scripts.getByCode(sc))
end
end
return self._scriptObjects
end
function Language:getFamily()
if not self._familyObject then
local m_families = require("Module:families")
self._familyObject = m_families.getByCode(self._rawData.family) or export.getByCode(self._rawData.family)
end
return self._familyObject
end
function Language:getAncestors()
if not self._ancestorObjects then
self._ancestorObjects = {}
for _, ancestor in ipairs(self._rawData.ancestors or {}) do
table.insert(self._ancestorObjects, export.getByCode(ancestor))
end
end
return self._ancestorObjects
end
function Language:getAncestorChain()
if not self._ancestorChain then
self._ancestorChain = {}
local step = #self:getAncestors() == 1 and self:getAncestors()[1] or nil
while step do
table.insert(self._ancestorChain, 1, step)
step = #step:getAncestors() == 1 and step:getAncestors()[1] or nil
end
end
return self._ancestorChain
end
function Language:getCategoryName()
local name = self._rawData.names[1]
-- If the name already has "language" in it, don't add it.
if name:find("[Ll]anguage$") then
return name
else
return name -- .. " language"
end
end
function Language:makeEntryName(text)
text = mw.ustring.gsub(text, "^[¿¡]", "")
text = mw.ustring.gsub(text, "[؟?!;՛՜ ՞ ՟?!।॥။၊་།]$", "")
if self._rawData.entry_name then
for i, from in ipairs(self._rawData.entry_name.from) do
local to = self._rawData.entry_name.to[i] or ""
text = mw.ustring.gsub(text, from, to)
end
end
return text
end
function Language:makeSortKey(name)
name = mw.ustring.lower(name)
-- Remove initial hyphens and *
name = mw.ustring.gsub(name, "^[-־ـ*]+(.)",
"%1")
-- Remove anything in parentheses, as long as they are either preceded or followed by something
name = mw.ustring.gsub(name, "(.)%([^()]+%)", "%1")
name = mw.ustring.gsub(name, "%([^()]+%)(.)", "%1")
-- If there are language-specific rules to generate the key, use those
if self._rawData.sort_key then
for i, from in ipairs(self._rawData.sort_key.from) do
local to = self._rawData.sort_key.to[i] or ""
name = mw.ustring.gsub(name, from, to)
end
end
return mw.ustring.upper(name)
end
function Language:transliterate(text, sc)
if not self._rawData.translit_module or not text then
return nil
end
return require("Module:" .. self._rawData.translit_module).tr(text, self:getCode(), sc and sc:getCode() or nil)
end
-- Do NOT use this method!
-- All uses should be pre-approved on the talk page!
function Language:getRawData()
return self._rawData
end
Language.__index = Language
local function getRawLanguageData(code)
local stable = mw.loadData("Module:languages/stable")[code]
if stable then
return stable
end
local len = string.len(code)
if code:find("^[a-z][a-z]$") then
return mw.loadData("Module:languages/data2")[code]
elseif code:find("^[a-z][a-z][a-z]$") then
local pre = code:sub(1, 1)
return mw.loadData("Module:languages/data3/" .. pre)[code]
elseif code:find("^[a-z-]+$") then
return mw.loadData("Module:languages/datax")[code]
else
return nil
end
end
-- The object cache implements memoisation, and is used to avoid duplication
-- of objects. If you request the same language code twice, you should also get
-- the same object twice, not two different objects with identical data.
-- It might also speed things up a bit.
local object_cache = {}
function export.getByCode(code)
if object_cache[code] then
return object_cache[code]
end
local rawData = getRawLanguageData(code)
if not rawData then
return nil
end
local object = setmetatable({ _rawData = rawData, _code = code }, Language)
object_cache[code] = object
return object
end
function export.getByCanonicalName(name)
local code = mw.loadData("Module:languages/by name")[name]
if not code then
return nil
end
return export.getByCode(code)
end
function export.getAll()
mw.incrementExpensiveFunctionCount()
local m_data = mw.loadData("Module:languages/alldata")
local ret = {}
for code, data in pairs(m_data) do
-- This isn't the most efficient way to do it, but it works for now.
table.insert(ret, export.getByCode(code))
end
return ret
end
return export