Zum Inhalt springen

Modul:families

Vun Wiktionary

Bearbeitungshinweis: Bisher nur teilweise plattdüütsche Bezeichnungen für die Sprachen.


This module contains definitions for all language family codes on Wiktionary. The entries are listed by their family code, which is usually an ISO-639 code, but there are also some exceptional codes. These are listed on Wiktionary:Families.

This module must not be importThis module is used to retrieve and manage Wiktionary's various language families and the information associated with them. See Wiktionary:Families for more information.

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

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

Finding and retrieving families

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

getByCode

getByCode(code)

Finds the family whose code matches the one provided. If it exists, it returns a Family object representing the family. Otherwise, it returns nil.

Family objects

A Family object is returned from one of the functions above. It is a Lua representation of a family 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_families = require("Module:families")
local fam = m_families.getByCode("ine")
local name = lang:getCanonicalName()
-- "name" will now be "Indo-European"

Family:getCode

:getCode()

Returns the family code of the family. Example: "ine" for the Indo-European languages.

Family:getCanonicalName

:getCanonicalName()

Returns the canonical name of the family. This is the name used to represent that language family on Wiktionary, and is guaranteed to be unique to that family alone. Example: "Indo-European" for the Indo-European languages.

Family:getAllNames

:getAllNames()

Returns a table of all names that the family is known by, including the canonical name. The names are not guaranteed to be unique, sometimes more than one family is known by the same name. Example: {"Slavic", "Slavonic"} for the Slavic languages.

Family:getFamily

:getFamily()

Returns a Family object for the parent family that the family is a part of.

Family:getCategoryName

:getCategoryName()

Returns the name of the main category of that family. Example: "Germanic languages" for the Germanic languages, whose category is at Category:Germanic languages.


local export = {}

local Family = {}


function Family:getCode()
	return self._code
end

function Family:getCanonicalName()
	return self._rawData.names[1]
end

function Family:getAllNames()
	return self._rawData.names
end

function Family: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 Family:getType()
	return "family"
end

function Family:getFamily()
	return export.getByCode(self._rawData.family)
end

function Family:getCategoryName()
	local name = self._rawData.names[1]
	
	-- If the name already has "languages" in it, don't add it.
	if name:find("[Ss]praken$") then
		return name
	else
		return name .. " Spraken"
	end
end


function Family:toJSON()
	local ret = {
		canonicalName = self:getCanonicalName(),
		categoryName = self:getCategoryName(),
		code = self._code,
		family = self._rawData.family,
		otherNames = self:getOtherNames(),
		type = self:getType(),
		}
	
	return require("Module:JSON").toJSON(ret)
end


function Family:getRawData()
	return self._rawData
end

Family.__index = Family


function export.makeObject(code, data)
	return data and setmetatable({ _rawData = data, _code = code }, Family) or nil
end

function export.getByCode(code)
	if code == 'kdo' then
		require('Modul:debug').track('Kordofanian')
	end

	return export.makeObject(code, mw.loadData("Module:families/data")[code])
end

function export.getByCanonicalName(name)
	local code = mw.loadData("Modul:families/by name")[name]
	
	if not code then
		return nil
	end
	
	return export.makeObject(code, mw.loadData("Module:families/data")[code])
end

return export