Difference between revisions 21306613 and 21306614 on frwiktionary

local export = {}

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	if mw.title.getCurrentTitle().nsText == "Template" then
		return "(This template should be used on pages in the Category: namespace.)"
	elseif mw.title.getCurrentTitle().nsText ~= "Category" then
(contracted; show full)	["description"] = "getBasicDescription",
	["parents"] = "getBasicParentLabels",
	["subs"] = "getBasicChildLabels",
	
	["umbrella"] = "getUmbrellaName",
	["umbrella_description"] = "getUmbrellaDescription",
	["umbrella_parents"] = "getUmbrellaParentLabels",

	["sortparentumbrella"] = "getUmbrellaSortKey",
	["umbrella-categorization"] = "getUmbrellaCategorizationType",
	
	["fundamental"] = "getFundamentalName",
}

-- Retrieves an item of information
function export.get_item(template, info, item)
	local submodule = require("Module:category tree/" .. template)
	require("Module:debug").track("category tree/get item")
	
	if functions[item] then
(contracted; show full)
	
	if info.sc then
		local parent = export.get_item(template, {code = info.code, label = info.label, sc = nil}, (info.code and "basic" or "umbrella"))
		local sortparent = require("Module:scripts").getByCode(info.sc):getCanonicalName()
		table.insert(categories, "[[Category:" .. parent .. "|" .. lang:makeSortKey(sortparent) .. "]]")
	elseif info.code then
		-- There is a code, so this is a basic category.
 Put the category in its parents.
		local parents = export.get_item(template, info, "parents")
		
		for _, parent in ipairs(parents) do
			local sortkey = export.get_item(template, info, "display_name")
			
			if type(parent) == "table" then
				sortkey = parent.sort
				parent = parent.name
			end
			
			sortkey = lang:makeSortKey(sortkey)
			
			if parent:find("^Category:") then
				table.insert(categories, "[[" .. parent .. "|" .. sortkey .. "]]")
			else
				local parent_name = export.get_item(template, {code = info.code, label = parent, sc = info.sc}, "basic")
				table.insert(categories, "[[Category:" .. parent_name .. "|" .. sortkey .. "]]")
			end
		end
		
		-- Also put the category in its corresponding "umbrella" or "by language" category.
		local umbrella = export.get_item(template, info, "umbrella")
		
		if umbrella then
			local current_name = export.get_item(template, info, "basic")
			table.insert(categories, "[[Category:" .. umbrella .. "|" .. lang:makeSortKey(current_name) .. "]]")
		end
	else
		-- There is no code, this is an umbrella category. Put the category in a "fundamental" category.
		local umbrella_categorization = export.get_item(template, info, "umbrella-categorization")
		
		if umbrella_categorization == "fundamental" then
			local fundamental = export.get_item(template, info, "fundamental")
			
			if fundamental then
				local sortkey = lang:makeSortKey(export.get_item(template, info, "sortparentumbrella") or export.get_item(template, info, "display_name"))
				table.insert(categories, "[[Category:" .. fundamental .. "|" .. sortkey .. "]]
		local parents = export.get_item(template, info, "umbrella_parents")
				end
		elseif umbrella_categorization == "parallel" then
			local parents = export.get_item(template, info, "parents")
		
	

		for _, parent in ipairs(parents) do
					local sortkey = export.get_item(template, info, "display_name")
				
		
	

			if type(parent) == "table" then
						sortkey = parent.sort
						parent = parent.name
					end
				
		
	

			sortkey = "*" .. lang:makeSortKey(sortkey)
					
					if parent:find("^Category:") then
						table.insert(categories, "[[" .. parent .. "|" .. sortkey .. "]]")
					else
						local parent_name = export.get_item(template, {code = info.code, label = parent, sc = info.sc}, "umbrella")
						table.insert(categories, "[[Category:" .. parent_name .. "|" .. sortkey .. "]]")
				end
			end
		end
	end
end

-- Show navigational "breadcrumbs" at the top of the page.
function show_breadcrumbs(template, info)
	if not info.code and export.get_item(template, info, "umbrella-categorization") ~= "parallel" then
(contracted; show full)			return mw.getCurrentFrame():expandTemplate{title = TOC_template.text, args = {}}
		end
	end
	
	return nil
end

return export