Module:usex/templates

Hello, you have come here looking for the meaning of the word Module:usex/templates. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:usex/templates, but we will also tell you about its etymology, its characteristics and you will know how to say Module:usex/templates in singular and plural. Everything you need to know about the word Module:usex/templates you have here. The definition of the word Module:usex/templates will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:usex/templates, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module is used by {{ux}} to format the usage example for a definition line; by {{quote}} to format quotations; by {{quote-meta/quote}} to format quotations invoked through templates like {{quote-book}}, {{quote-journal}}, etc.; and by {{collocation}} and {{coi}} to format collocations.

It delegates the actual work to Module:usex.

Exported functions

usex_t

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

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

format_langs

{{#invoke:usex/templates|format_langs|LANG,LANG,...}}

Format a list of language codes into the English equivalents. Depending on the number of languages specified, the output is in one of the following formats:

English
English and French
English, French and German
English, French, German and Latin
(etc.)

If there are three or more languages, an optional serial comma is inserted before the final "and" just as with {{,}}, allowing the user to control whether the comma appears.

first_lang

{{#invoke:usex/templates|first_lang|LANG,LANG,...}}

Return the first language code in a list of one or more language codes.

See also


local export = {}

local m_languages = require("Module:languages")
local table_module = "Module:table"
local usex_module = "Module:usex"
local yesno_module = "Module:yesno"

local rsplit = mw.text.split
local rfind = mw.ustring.find

local function track(page)
	require("Module:debug/track")("usex/templates/" .. page)
	return true
end

function export.usex_t(frame)
	-- Invocation arguments (passed in the template #invoke call).
	local iparams = {
		 = {},
		 = {type = "boolean"},
		 = {},
		 = {type = "boolean"},
		 = {},
	}

	local iargs = require("Module:parameters").process(frame.args, iparams)
	local compat = iargs.compat

	local parent_args = frame:getParent().args
	if parent_args.qualifier then
		track("qualifier")
	end

	-- Template (parent) arguments.
	local params = {
		-- Usex/quotation text parameters
		 = {required = true},
		 = {},
		 = {},
		 = {},
		 = {alias_of = "tr"},
		 = {},
		 = {alias_of = "ts"},
		 = {type = "script"},
		 = {},
		 = {alias_of = "norm"},
		 = {type = "script"},
		 = {},
		 = {list = true},
		 = {alias_of = "q"},
		 = {list = true},
		 = {},
		
		-- Usex/quotation audio parameters,
		 = {},

		-- Translation of usex text
		 = {},
		 = {alias_of = 3},
		 = {alias_of = 3},
		 = {},

		-- Original text, if the usex/quotation is a translation
		 = {},
		 = {},
		 = {},
		 = {},
		 = {type = "script"},
		 = {},
		 = {type = "script"},
		 = {},
		 = {list = true},
		 = {list = true},
		 = {},

		-- Citation-related parameters; for anything more complex, usex {{quote-*}}
		 = {},
		 = {},

		-- Formatting parameters
		 = {},
		 = {type = "boolean"},

		-- Categorization parameters
		 = {type = "boolean"},
		 = {},
	}

	if compat then
		params = {required = true}
		params.alias_of = 2
		params.alias_of = 2
		table.remove(params, 1)
	end

	local args = require("Module:parameters").process(parent_args, params)

	local langparam = compat and "lang" or 1
	local lang = m_languages.getByCode(args or "und", langparam, "allow etym")
	local sc = args.sc
	local normsc = args.normsc
	if normsc and not args.norm then
		error("Cannot specify normsc= without norm=")
	end

	if #args.qq > 0 then
		track("qq")
	end
	if #args.q > 0 then
		track("q")
	end

	local termlang
	if args.termlang then
		termlang = m_languages.getByCode(args.termlang, "termlang", "allow etym")
		table.insert(args.qq, 1, "in " .. lang:getCanonicalName())
	end

	local origlang, origsc, orignormsc
	if args.orig then
		origlang = m_languages.getByCode(args.origlang, "origlang", "allow etym")
		table.insert(args.origqq, 1, "in " .. origlang:getCanonicalName())
		origsc = args.origsc
		orignormsc = args.orignormsc
		if orignormsc and not args.orignorm then
			error("Cannot specify orignormsc= without orignorm=")
		end
	else
		for _, noparam in ipairs { "origlang", "origtr", "origts", "origsc", "orignorm", "orignormsc", "origsubst",
			"origref" } do
			if args then
				error(("Cannot specify %s= without orig="):format(noparam))
			end
		end
		if #args.origq > 0 then
			error("Cannot specify origq= without orig=")
		end
		if #args.origqq > 0 then
			error("Cannot specify origqq= without orig=")
		end
	end

	local inline = args.inline or iargs.inline
	if inline ~= "auto" then
		inline = require(yesno_module)(inline)
	end

	local data = {
		lang = lang,
		sc = sc,
		normsc = normsc,
		usex = args,
		translation = args,
		transliteration = args.tr,
		transcription = args.ts,
		normalization = args.norm,
		inline = inline,
		ref = args.ref,
		quote = iargs.quote,
		lit = args.lit,
		subst = args.subst,
		-- FIXME, change to left and right qualifiers
		qq = #args.qq > 0 and args.qq or args.q,
		audio = args.audio,
		source = args.source,
		footer = args.footer,
		nocat = args.nocat or iargs.nocat,
		brackets = args.brackets,
		sortkey = args.sort,
		class = iargs.class,

		-- Original text, if the usex/quotation is a translation
		orig = args.orig,
		origlang = origlang,
		origtr = args.origtr,
		origts = args.origts,
		origsc = origsc,
		orignorm = args.orignorm,
		orignormsc = orignormsc,
		origsubst = args.origsubst,
		origq = args.origq,
		origqq = args.origqq,
		origref = args.origref,
	}

	return require(usex_module).format_usex(data)
end

local ignore_prefixes = {"User:", "Talk:",
	"Wiktionary:Beer parlour", "Wiktionary:Translation requests",
	"Wiktionary:Grease pit", "Wiktionary:Etymology scriptorium",
	"Wiktionary:Information desk", "Wiktionary:Tea room",
	"Wiktionary:Requests for", "Wiktionary:Votes"
}

function export.page_should_be_ignored(page)
	-- Ignore user pages, talk pages and certain Wiktionary pages
	for _, ip in ipairs(ignore_prefixes) do
		if rfind(page, "^" .. ip) then
			return true
		end
	end
	if rfind(page, " talk:") then
		return true
	end
	return false
end

function export.page_should_be_ignored_t(frame)
	return export.page_should_be_ignored(frame.args) and "true" or ""
end

return export