Module:list description

From Linguifex
Jump to navigation Jump to search

Documentation for this module may be created at Module:list description/doc

local export = {}

function export.show(frame)
	local title = mw.title.getCurrentTitle()
	local rootpagename = title.rootText
	local isSubpage = title.isSubpage
	local subpagename = title.subpageText
	mw.log(rootpagename, isSubpage, subpagename)
	
	local lang, canonicalName
	if isSubpage then
		lang = require("Module:languages").getByCode(subpagename)
	end
	
	local listName, matches
	if rootpagename then
		listName, matches = mw.ustring.gsub(rootpagename, "list:", "")
	end
	
	local description
	local category = ""
	if lang then
		if matches == 1 then
			description =  "This is a list of " .. listName .. " in the " .. lang:getCanonicalName() .. " language."
			if mw.ustring.match(listName, "Latin script") then
				category = "[[Category:Latin script templates]]"
			end
		else
			description = "This is a list in the " .. lang:getCanonicalName() .. " language."
		end
	end
	
	if description then
		return description .. category
	end
end

return export