Difference between revisions 21306621 and 21306622 on frwiktionary

local export = {}

local m_submodule = nil

-- 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
(contracted; show full)		if not parents then
			return
		end
		
		for _, parent in ipairs(parents) do
			local sortkey = m_submodule.new(info):getBreadcrumbName()
			
			if type(parent) == "table" 
and parent.name then
				parent = parent.namethen
				sortkey = parent.sort
				parent = parent.name
			end
			
			sortkey = lang:makeSortKey(sortkey)
			
			if type(parent) == "string" and parent:find("^Category:") then
				table.insert(categories, "[[" .. parent .. "|" .. sortkey .. "]]")
			else
				if type(parent) == "string" then
					parent =local parent_name = (info.code and m_submodule.new({code = info.code, label = parent, sc = info.sc})
				end
				
				local parent_nam:getBasicName() or m_submodule.new({code = (info.code and parent:getBasicName() or parent, label = parent, sc = info.sc}):getUmbrellaName())
				table.insert(categories, "[[Category:" .. parent_name .. "|" .. sortkey .. "]]")
			end
		end
		
		if info.code then
			-- Also put the category in its corresponding "umbrella" or "by language" category.
			local umbrella = m_submodule.new(info):getUmbrellaName()
			
			if umbrella then
				local current_name = m_submodule.new(info):getBasicName()
				table.insert(categories, "[[Category:" .. umbrella .. "|" .. lang:makeSortKey(current_name) .. "]]")
			end
		end
	end
end

-- Show navigational "breadcrumbs" at the top of the page.
function show_breadcrumbs(info)
	local steps = {}
	
	-- Start at the current label and move our way up the "chain" from child to parent, until we can't go further.
	local current = m_submodule.new({code = info.code, label = info.label, sc = nil})
	
	while current do
		local parents = (info.code and current:getBasicParentLabels() or current:getUmbrellaParentLabels())
		
		if not parents then
			break
		end
		
		local parent = parents[1]
		
		info.label
	
	while current do
		local parents = (info.code and m_submodule.new({code = info.code, label = current, sc = nil}):getBasicParentLabels() or m_submodule.new({code = info.code, label = current, sc = nil}):getUmbrellaParentLabels())
		local parent = parents and parents[1] or nil
		
		if not parent then
			break
		elseif type(parent) == "table" and parent.name then
			parent = parent.name
		end
		
		local parent_category = nil
		local parent_display_name = nil
		
		if type(parent) == "string" and parent:find("^Category:") then
			parent_category = parent
			parent_display_name = parent:gsub("^Category:", "")
			
			-- The chain ends here.
			current = nil
		else
			if type(parent)parent_category == "string" then
				parent =Category:" .. (info.code and m_submodule.new({code = info.code, label = parent, sc = nil})
			end
			
			parent_category = "Category:" .. (info.code and parent:getBasicName() or parent:getUmbrellaName())
			parent_display_name = parent:getBasicName() or m_submodule.new({code = info.code, label = parent, sc = nil}):getUmbrellaName())
			parent_display_name = m_submodule.new({code = info.code, label = parent, sc = nil}):getBreadcrumbName()
			
			-- Move up the "chain" by one level.
			current = parent
		end
		
		parent_display_name = mw.getContentLanguage():ucfirst(parent_display_name)
		table.insert(steps, 1, "» [[:" .. parent_category .. "|" .. parent_display_name .. "]]")
(contracted; show full)			return mw.getCurrentFrame():expandTemplate{title = TOC_template.text, args = {}}
		end
	end
	
	return nil
end

return export