Module:usex/templates

Definition from Wiktionary, the free dictionary
Jump to: navigation, search

This module is used by {{ux}} to format the usage example for a definition line, and by {{quote}} to format quotations.

It delegates the actual work to Module:usex.

Exported functions[edit]

usex_t[edit]

{{#invoke:usex/templates|usex_t}}

Format an usage example or a quotation. See {{ux}} and {{quote}} for more.

See also[edit]


local export = {}

function export.usex_t(frame)
	local params = {
		[1] = {required = true},
		[2] = {},
		[3] = {},
		
		["inline"] = {type = "boolean"},
		["noenum"] = {type = "boolean"},
		["ref"] = {},
		["lit"] = {},
		["q"] = {list = true},
		["qualifier"] = {alias_of = "qual"},
		["sc"] = {},
		["source"] = {},
		["subst"] = {},
		["t"] = {alias_of = 3},
		["translation"] = {alias_of = 3},
		["tr"] = {},
		["transliteration"] = {alias_of = "tr"},
	}
	
	local quote = (frame.args["quote"] or "") ~= ""
	local compat = (frame.args["compat"] or "") ~= ""
	local template_inline = (frame.args["inline"] or "") ~= ""
	
	if compat then
		params["lang"] = {required = true}
		params["t"].alias_of = 2
		params["translation"].alias_of = 2
		table.remove(params, 1)
	end
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local lang = args[compat and "lang" or 1] or "und"
	local sc = args["sc"]
	
	lang = require("Module:languages").getByCode(lang) or require("Module:languages").err(lang, ( compat and "lang" ) or 1)
	sc = (sc and (require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
	
	local usex = args[compat and 1 or 2]
	local translation = args[compat and 2 or 3]
	local transliteration = args["tr"]
	local noenum = args["noenum"]
	local inline = args["inline"] or template_inline
	local ref = args["ref"]
	local lit = args["lit"]
	local substs = args["subst"]
	local qualifiers = args["q"]
	local source = args["source"]
	
	return require("Module:usex").format_usex(lang, sc, usex, translation, transliteration, noenum, inline, ref, quote, lit, substs, qualifiers, source)
end

return export