Module:also/templates

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module implements the template {{also}}.


-- Prevent substitution.
if mw.isSubsting() then
	return require("Module:unsubst")
end

local export = {}

local get_script = require("Module:scripts").getByCode
local insert = table.insert
local process_params = require("Module:parameters").process
local yesno = require("Module:yesno")

function export.also_t(frame)
	local args = process_params(frame:getParent().args or frame.args, {
		[1] = {required = true, list = true},
		["sc"] = {list = true, allow_holes = true, require_index = true},
		["uni"] = {list = true, allow_holes = true, separate_no_index = true},
	})
	
	if args.sc.maxindex > 0 then
		require("Module:debug/track")("also/sc param")
	end
	
	local terms, sc, uni = {}, args.sc, args.uni
	for i, term in ipairs(args[1]) do
		local sc_i = sc[i]
		if sc_i then
			term = {term = term, sc = get_script(sc_i)}
		end
		local uni_i = uni[i]
		if uni_i then
			if type(term) == "string" then
				term = {term = term}
			end
			-- If boolean false specified, set as `false`; otherwise, retain the input value.
			-- Exceptionally, "0" is treated as itself, not `false`.
			term.uni = uni_i == "0" and uni_i or yesno(uni_i, uni_i) and uni_i or false
		end
		insert(terms, term)
	end
	
	local uni_default = args.uni.default
	terms.uni_default = yesno(uni_default == "auto" or uni_default) and "auto" or nil
	
	return require("Module:also").main(terms)
end

return export