Jump to content

Module:phrasebook

From Wiktionary, the free dictionary

This module implements the template {{phrasebook}}.


local format_categories = require("Module:utilities").format_categories
local get_lang = require("Module:languages").getByCode
local html_create = mw.html.create
local insert = table.insert
local process_params = require("Module:parameters").process

local pagename = mw.loadData("Module:headword/data").encoded_pagename

local export = {}

function export.show(frame)
	local args = process_params(frame:getParent().args, {
		[1] = {required = true},
		[2] = {list = true}
	})
	
	local lang = get_lang(args[1])
	local langname = lang:getCanonicalName()
	local categories = {}
	
	
	local main = html_create("td"):wikitext("This entry is part of the [[Wiktionary:Phrasebook|phrasebook]] project, which presents [[Wiktionary:Criteria for inclusion|criteria for inclusion]] based on utility, simplicity and commonness.")
	insert(categories, langname .. " phrasebook")
	
	if #args[2] > 0 then
		local topics = {}
		for _, topic in ipairs(args[2]) do
			insert(topics, "<b>[[:Category:" .. langname .. " phrasebook/" .. topic .. "|" .. topic .. "]]</b>")
			insert(categories, langname .. " phrasebook/" .. topic)
		end
		main = main:tag("div")
			:wikitext("For other " .. langname .. " entries on this topic, see " .. mw.text.listToText(topics, ", ", " or ") .. ".")
			:allDone()
	end
	
	local div = html_create("div")
		:addClass("phrasebook NavFrame")
		:css("background-color", "var(--wikt-palette-orange,#f2caa4)")
		:tag("div")
			:addClass("NavHead")
			:css("background", "var(--wikt-palette-lightyellow,#FFFFE0)")
			:wikitext(langname .. " phrasebook")
			:done()
		:tag("div")
			:addClass("NavContent")
			:tag("table")
				:css("background", "var(--wikt-palette-lightyellow,#FFFFE0)")
				:css("width", "100%")
				:css("margin", "auto")
				:css("text-align", "center")
				:tag("tr")
					:tag("td")
						:css("text-align", "left")
						:wikitext("[[File:Open book 01.svg|40px]]")
					:node(main)
		:allDone()
	return tostring(div) .. format_categories(categories, lang, nil, pagename)
end

return export