1,073
edits
No edit summary |
(Defining getFullCode()) |
||
Line 216: | Line 216: | ||
return self._familyObject | return self._familyObject | ||
end | end | ||
--[==[Returns the family code in the language's data file.]==] | |||
function Language:getFamilyCode() | |||
local family = self._familyCode | |||
if family == nil then | |||
-- If the value is nil, it's cached as false. | |||
family = self._rawData[3] or false | |||
self._familyCode = family | |||
end | |||
return family or nil | |||
end | |||
function Language:getFamilyName() | |||
local family = self._familyName | |||
if family == nil then | |||
family = self:getFamily() | |||
-- If the value is nil, it's cached as false. | |||
family = family and family:getCanonicalName() or false | |||
self._familyName = family | |||
end | |||
return family or nil | |||
end | |||
--[==[Check whether the language belongs to `family` (which can be a family code or object). A list of objects can be given in place of `family`; in that case, return true if the language belongs to any of the specified families. Note that some languages (in particular, certain creoles) can have multiple immediate ancestors potentially belonging to different families; in that case, return true if the language belongs to any of the specified families.]==] | |||
function Language:inFamily(...) | |||
--check_object("family", nil, ...) | |||
for _, family in ipairs{...} do | |||
if type(family) == "table" then | |||
family = family:getCode() | |||
end | |||
local self_family_code = self:getFamilyCode() | |||
if not self_family_code then | |||
return false | |||
elseif self_family_code == family then | |||
return true | |||
end | |||
local self_family = self:getFamily() | |||
if self_family:inFamily(family) then | |||
return true | |||
-- If the family isn't a real family (e.g. creoles) check any ancestors. | |||
elseif self_family:getFamilyCode() == "qfa-not" then | |||
local ancestors = self:getAncestors() | |||
for _, ancestor in ipairs(ancestors) do | |||
if ancestor:inFamily(family) then | |||
return true | |||
end | |||
end | |||
end | |||
end | |||
return false | |||
end | |||
function Language:getParent() | |||
local parent = self._parentObject | |||
if parent == nil then | |||
parent = self:getParentCode() | |||
-- If the value is nil, it's cached as false. | |||
parent = parent and export.getByCode(parent, nil, true, true, self._useRequire) or false | |||
self._parentObject = parent | |||
end | |||
return parent or nil | |||
end | |||
function Language:getParentCode() | |||
local parent = self._parentCode | |||
if parent == nil then | |||
-- If the value is nil, it's cached as false. | |||
parent = self._rawData[5] or false | |||
self._parentCode = parent | |||
end | |||
return parent or nil | |||
end | |||
function Language:getParentName() | |||
local parent = self._parentName | |||
if parent == nil then | |||
parent = self:getParent() | |||
-- If the value is nil, it's cached as false. | |||
parent = parent and parent:getCanonicalName() or false | |||
self._parentName = parent | |||
end | |||
return parent or nil | |||
end | |||
function Language:getParentChain() | |||
local chain = self._parentChain | |||
if chain == nil then | |||
chain = {} | |||
local parent, n = self:getParent(), 0 | |||
while parent do | |||
n = n + 1 | |||
chain[n] = parent | |||
parent = parent:getParent() | |||
end | |||
self._parentChain = chain | |||
end | |||
return chain | |||
end | |||
function Language:hasParent(...) | |||
--check_object("language", nil, ...) | |||
for _, otherlang in ipairs{...} do | |||
for _, parent in ipairs(self:getParentChain()) do | |||
if type(otherlang) == "string" then | |||
if otherlang == parent:getCode() then return true end | |||
else | |||
if otherlang:getCode() == parent:getCode() then return true end | |||
end | |||
end | |||
end | |||
return false | |||
end | |||
--[==[ | |||
If the language is etymology-only, this iterates through parents until a full language or family is found, and the | |||
corresponding object is returned. If the language is a full language, then it simply returns itself. | |||
]==] | |||
function Language:getFull() | |||
local full = self._fullObject | |||
if full == nil then | |||
full = self:getFullCode() | |||
full = full == self._code and self or | |||
export.getByCode(full, nil, nil, nil, self._useRequire) | |||
self._fullObject = full | |||
end | |||
return full | |||
end | |||
--[==[ | |||
If the language is an etymology-only language, this iterates through parents until a full language or family is | |||
found, and the corresponding code is returned. If the language is a full language, then it simply returns the | |||
language code. | |||
]==] | |||
function Language:getFullCode() | |||
return self._fullCode or self._code | |||
end | |||
--[==[ | |||
If the language is an etymology-only language, this iterates through parents until a full language or family is | |||
found, and the corresponding canonical name is returned. If the language is a full language, then it simply returns | |||
the canonical name of the language. | |||
]==] | |||
function Language:getFullName() | |||
local full = self._fullName | |||
if full == nil then | |||
full = self:getFull():getCanonicalName() | |||
self._fullName = full | |||
end | |||
return full | |||
end | |||
edits