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 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 | 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() | ||
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 | while family do | ||
if | code = family:getCode() | ||
return | if code == superfamily then | ||
return true | |||
end | end | ||
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 | ||
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 | local name = self._data.categoryName or self:getDisplayForm() | ||
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 | if data == nil then | ||
return nil | |||
elseif data.parent == nil then | |||
return make_object(code, data) | return make_object(code, data) | ||
end | end | ||
return make_lang_object(code, data) | |||
return | |||
end | end | ||
get_by_code = export.getByCode | get_by_code = export.getByCode | ||