Jump to content

Module:Translation category

From Meta, a Wikimedia project coordination wiki
Module documentation
local Transcluder = require('Module:Transcluder')
local p = {}

--[[
	Extracts categories from given basePageName category, suffixes them
	with "/Translations" and returns them.
]]
function p.get_categories(frame)
	local basePageName = frame.args[1]
	local basePageContent = Transcluder.get("Category:" .. basePageName)
	local basePageCategories = Transcluder.getCategories(basePageContent)
	
	local translationCatCategories = {}
	
	for i, cat in ipairs(basePageCategories) do
		if not string.find( cat, basePageName .. "/Translations", 1, true ) then --avoids self categorization
			local newCat = mw.ustring.sub(cat, 1, #cat-2) --removes final ]]
			newCat = newCat .. "/Translations]]"
			table.insert( translationCatCategories, newCat )
		end
	end
	
	return frame:preprocess( table.concat(translationCatCategories) )
	--[[ Preprocess is probably needed because translationCatCategories should
	contain {{#translations}}. If this preprocessing is expensive, we can try to
	remove {{#translations}} calls before. ]]
end

return p