Module:documentation/functions/number list

From Linguifex
Jump to navigation Jump to search
return function (title, cats)
	local suffix = title.fullText:match("^Module:number list/data/(.+)$")
	local lang_code = suffix:match "^([^/]+)/sandbox$" or suffix
	local lang = require("Module:languages").getByCode(lang_code)
	
	local function page_exists(title)
		local success, title_obj = pcall(mw.title.new, title)
		return success and title_obj.exists
	end
	
	if lang then
		local canonical_name = lang:getCanonicalName()
		local language_data_modules = canonical_name .. " data modules"
		
		cats:insert((page_exists("Category:" .. language_data_modules)
			and language_data_modules or canonical_name .. " modules")
			.. "|number list")
		cats:insert("Number data modules|" .. canonical_name)
		
		return ("This module contains data on various types of numbers in %s.\n%s")
			:format(lang:makeCategoryLink(), require("Module:number list/show").table() or '')
	end
end