Difference between revisions 21306629 and 21306630 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)	else
		return nil
	end
end

-- Show the parent categories that the current category should be placed in.
function show_categories(info, categories)

	local lang = require("Module:languages").getByCode(mw.getContentLanguage():getCode())  -- Used to create English sort keys
	
	if info.sc then
		local pinfo = mw.clone(info)
		pinfo.sc = nil
		local parent = m_submodule.new(pinfo)
		
		local parent_name = (info.code and parent:getBasicName() or parent:getUmbrellaName())
		local sortkey = lang:makeSortKey(require("Module:scripts").getByCode(info.sc):getCanonicalName())
		table.insert(categories, "[[Category:" .. parent_name .. "|" .. sortkey .. "]]")
	else
		local parents = (info.code and m_submodule.new(info):getBasicParentLabels() or m_submodule.new(info):getUmbrellaParentLabels())
		
		if not parents then
			return
		end
		
		for _, parent in ipairs(parents) do
			if type(parent) == "string" or (type(parent) == "table" and not parent.sort) then
				require("Module:debug").track("category tree/no sort")
				parent = {name = parent, sort = m_submodule.new(info):getBreadcrumbName()}
			end
			
			parent.sort = lang:makeSortKey(parent.sort)
			
			if type(parent.name) == "string" then
				table.insert(categories, "[[" .. parent.name .. "|" .. parent.sort .. "]]")
			else
				local parent_name = (info.code and parent.name:getBasicName() or parent.name:getUmbrellaName())
				table.insert(categories, "[[Category:" .. parent_name .. "|" .. parent.sort .. "]]")
			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)
(contracted; show full)			return mw.getCurrentFrame():expandTemplate{title = TOC_template.text, args = {}}
		end
	end
	
	return nil
end

return export