模組:List description

維基詞典,自由的多語言詞典
此模組需要說明文件。
請在說明文件頁加上適當的描述(如其目的、使用方法等)。

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, "[Ll]ist:", "")
	end
	
	local description
	local category = ""
	if lang then
		if matches == 1 then
			description =  "本模板爲關於" .. listName .. "的" .. lang:getCanonicalName() .. "列表。"
			if mw.ustring.match(listName, "Latin script") then
				category = "[[Category:拉丁字母模板]]"
			end
		else
			description = "本模板爲一個" .. lang:getCanonicalName() .. "列表。"
		end
	end
	
	if description then
		return description .. category
	end
end

return export