Module:Langlist

From Wikisource
Jump to navigation Jump to search
--[=[
Module description
]=]

local p = {} --p stands for package

local getArgs = require('Module:Arguments').getArgs

function lang_link(base, code)
	return "[[Template:" .. base .. "/" .. code .. "|" .. mw.language.fetchLanguageName(code) .. "]]"
end

function p.langlist(frame)
	local args = getArgs(frame)
	local base = args.base
	
	local links = {}
	for k, v in pairs(args) do
		if tonumber(k) then
			table.insert(links, lang_link(base, v))
		end
	end
	
	local editlink
	if args.noedit then
		editlink = "[[Special:PrefixIndex/" .. "Template:" .. base .. "/|…]]"
	else
		editlink = "[" .. tostring(mw.uri.fullUrl("Template:" .. base .. "/lang", "action=edit")) .. " +/-]"
	end
	
	local title = mw.title.getCurrentTitle()
	local template_cat = ""
	if title.nsText == "Template" and title.subpageText == "lang" then
		template_cat = "[[Category:Language link templates]]"
	end
	
	local sep = " | "
	return "<span class='plainlinks' style='line-height:1.4; font-size:83%;'>" .. table.concat(links, sep) .. sep .. editlink .. "</span>" .. template_cat
end

return p