မဝ်ဂျူ:families

နူ ဝိက်ရှေန်နရဳ
အ​ညွှန်း​သို့ ခုန်ကူးရန် ရှာဖွေရန် ခုန်ကူးမည်

Documentation for this module may be created at မဝ်ဂျူ:families/doc

local export = {}

local Family = {}


function Family:getCode()
	return self._code
end


function Family:getCanonicalName()
	return self._rawData.canonicalName
end


function Family:getDisplayForm()
	return self:getCategoryName("nocap")
end


function Family:getOtherNames(onlyOtherNames)
	return require("Module:language-like").getOtherNames(self, onlyOtherNames)
end


function Family:getAliases()
	return self._rawData.aliases or {}
end


function Family:getVarieties(flatten)
	return require("Module:language-like").getVarieties(self, flatten)
end


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


function Family:getType()
	return "family"
end


function Family:getFamily()
	if self._rawData.family and not self._familyObject then
		self._familyObject = export.getByCode(self._rawData.family)
	end

	return self._familyObject
end


function Family:getProtoLanguage()
	if not self._protoLanguage then
		self._protoLanguage = require("Module:languages").getByCode(self._rawData.protoLanguage or self._code .. "-pro")
	end

	return self._protoLanguage
end


function Family:getCategoryName(nocap)
	local name = self._rawData.canonicalName
	-- consider more umbrellas in order to know whether it is a language family or a language group
	local family = self._rawData.family
	
	-- If the name already has "languages" (ဘာသာဂကူဝံသ/ဘာသာဂကောံ) in it, don't add it.
	if name:find("^ဘာသာဂကူဝံသ") or name:find("^ဘာသာဂကောံ") then
		return name
	else
		if family == nil then
			-- လ္တူအိုတ်
			return "ဘာသာဂကူဝံသ" .. name
		else
			if family == 'qfa-not' or family == 'qfa-iso' then
				-- အရေဝ်ဘာသာဟွံသေင်
				return name
			else
				return "ဘာသာဂကောံ" .. name
			end
		end
	end
	if not nocap then
		name = mw.getContentLanguage():ucfirst(name)
	end
	return name
end


function Family:makeCategoryLink()
	return "[[:Category:" .. self:getCategoryName() .. "|" .. self:getCategoryName() .. "]]"
end


function Family:getWikidataItem()
	local item = self._rawData.wikidata_item

	if type(item) == "number" then
		return "Q" .. item
	else
		return item
	end
end


function Family:getWikipediaArticle()
	return (self:getWikidataItem() and mw.wikibase and mw.wikibase.sitelink(self:getWikidataItem(), 'enwiki')) or
		self:getCategoryName()
end


function Family:makeWikipediaLink()
	return "[[w:" .. self:getWikipediaArticle() .. "|" .. self:getCanonicalName() .. "]]"
end


function Family:toJSON()
	local ret = {
		canonicalName = self:getCanonicalName(),
		categoryName = self:getCategoryName("nocap"),
		code = self._code,
		family = self._rawData.family,
		protoLanguage = self._rawData.protoLanguage,
		otherNames = self:getOtherNames(true),
		aliases = self:getAliases(),
		varieties = self:getVarieties(),
		type = self:getType(),
		wikidataItem = self:getWikidataItem(),
		}

	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)
	-- FIXME! Remove this when we've tracked down all uses.
	if code == 'kdo' then
		require('Module:debug').track('Kordofanian')
	end

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


function export.getByCanonicalName(name)
	local code = mw.loadData("Module:families/by name")[name]

	if not code then
		return nil
	end

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


return export