Module:families: Difference between revisions

No edit summary
No edit summary
Line 3: Line 3:
local families_by_name_module = "Module:families/canonical names"
local families_by_name_module = "Module:families/canonical names"
local families_data_module = "Module:families/data"
local families_data_module = "Module:families/data"
local families_etymology_data_module = "Module:families/data/etymology"
local json_module = "Module:JSON"
local json_module = "Module:JSON"
local language_like_module = "Module:language-like"
local language_like_module = "Module:language-like"
Line 74: Line 73:
families_data, get_families_data = load_data(families_data_module), nil
families_data, get_families_data = load_data(families_data_module), nil
return families_data
return families_data
end
local families_etymology_data
local function get_families_etymology_data()
families_etymology_data, get_families_etymology_data = load_data(families_etymology_data_module), nil
return families_etymology_data
end
end
Line 115: Line 108:


--[==[
--[==[
Return the display form of the family. For families, this is the same as the value returned by
Return the display form of the family. For families, this is usually the same as the value returned by
{getCategoryName("nocap")}, i.e. it reads <code>"<var>name</var> languages"</code> (e.g.
{getCategoryName("nocap")}, i.e. it reads <code>"<var>name</var> languages"</code> (e.g.
{"Indo-Iranian languages"}). For full and etymology-only languages, this is the same as the canonical name, and
{"Indo-Iranian languages"}). For full and etymology-only languages, this is the same as the canonical name, and
Line 122: Line 115:
]==]
]==]
function Family:getDisplayForm()
function Family:getDisplayForm()
return self:getCategoryName("nocap")
local name = self._data[1]
if category_name_has_suffix(name, families_suffixes or get_families_suffixes()) then
name = name .. " languages"
end
return name
end
end


Line 223: Line 220:
end
end
local family, code = self:getFamily()
local family, code = self:getFamily()
while true do
while family do
if not family then
code = family:getCode()
return false
if code == superfamily then
return true
end
end
code = family:getCode()
family = family:getFamily()
family = family:getFamily()
-- If family is parent to itself, return false.
-- If family is parent to itself, return false.
if family and family:getCode() == code then
if family and family:getCode() == code then
return false
return false
elseif code == superfamily then
return true
end
end
end
end
return false
end
end
end
end
Line 456: Line 452:
]==]
]==]
function Family:getCategoryName(nocap)
function Family:getCategoryName(nocap)
local name = self._data[1]
local name = self._data.categoryName or self:getDisplayForm()
if category_name_has_suffix(name, families_suffixes or get_families_suffixes()) then
name = name .. " languages"
end
if not nocap then
if not nocap then
name = mw.getContentLanguage():ucfirst(name)
name = mw.getContentLanguage():ucfirst(name)
Line 541: Line 534:
function export.getByCode(code)
function export.getByCode(code)
local data = (families_data or get_families_data())[code]
local data = (families_data or get_families_data())[code]
if data ~= nil then
if data == nil then
return nil
elseif data.parent == nil then
return make_object(code, data)
return make_object(code, data)
end
end
data = (families_etymology_data or get_families_etymology_data())[code]
return make_lang_object(code, data)
return data ~= nil and make_lang_object(code, data) or nil
end
end
get_by_code = export.getByCode
get_by_code = export.getByCode