Module:Language category link

Jump to navigation Jump to search

Module version of {{Language category link}} allowing easy adding categories in modules for translation projects.

Usage[edit source]

local ll = require('Module:Language category link').main

-- Parameters
ll('Category (Required)', 'Sort (Optional)')

-- Examples
ll('Olennot') --> [[Category:/Finnish translation/Olennot]]

ll('Olennot', 'Zombi') --> [[Category:Finnish translation/Olennot|Zombi]]
[view] [edit] [history] [refresh]The above documentation is transcluded from Module:Language category link/doc.
require('strict')
local p = {}

local title = mw.title.getCurrentTitle()
local namespace = mw.site.namespaces.Category.name

function p.main(category, sort)
	assert(category, "bad argument #1 for 'category' (string expected, got nil)")
	local page = title.baseText
		:gsub('^Projects/', '')
	
	local subpage = string.find(page, '/')
	if subpage then
		page = string.sub(page, 1, subpage - 1)
	end
	
	if sort == nil then
		return string.format('[[%s:%s/%s]]', namespace, page, category)
	end
	
	return string.format('[[%s:%s/%s|%s]]', namespace, page, category, sort)
end

return p