ماڈیول:form of/templates

ویکی لغت سے

This module contains code that directly implements {{form of}}, {{inflection of}}, and the various other form-of templates. It is meant to be called directly from templates. See also Module:form of, which contains the underlying implementing code and is meant to be called from other modules.

form_of_t[ترمیم]

{{#invoke:form of/templates|form_of_t}}

Template-callable implementation of {{form of}} and the various more specific form-of templates (but not {{inflection of}} or templates that take tagged inflection parameters). See the code for the exact invocation arguments.

tagged_form_of_t[ترمیم]

{{#invoke:form of/templates|tagged_form_of_t}}

Template-callable implementation of form-of templates that are defined by specific tagged inflections (typically a template referring to a non-lemma inflection, such as {{genitive plural of}}). This works exactly like form_of_t() except that the "form of" text displayed before the link is based off of a pre-specified set of inflection tags (which will be appropriately linked to the glossary) instead of arbitrary text. From the user's perspective, there is no difference between templates implemented using form_of_t() and tagged_form_of_t(); they accept exactly the same parameters and work the same. See also inflection_of_t() below, which is intended for templates with user-specified inflection tags.

See the code for the exact invocation arguments, which are very similar to form_of_t().

inflection_of_t[ترمیم]

{{#invoke:form of/templates|inflection_of_t}}

Template-callable implementation of {{inflection of}} and certain semi-specific variants, such as {{participle of}} and {{past participle form of}}. This function is intended for templates that allow the user to specify a set of inflection tags. It works similarly to form_of_t() and tagged_form_of_t() except that the calling convention for the calling template is

{{TEMPLATE|LANG|MAIN_ENTRY_LINK|MAIN_ENTRY_DISPLAY_TEXT|TAG|TAG|...}}

instead of

{{TEMPLATE|LANG|MAIN_ENTRY_LINK|MAIN_ENTRY_DISPLAY_TEXT|GLOSS}}

Note that there isn't a numbered parameter for the gloss, but it can still be specified using |t= or |gloss=.

See the code for the exact invocation arguments, which are very similar to form_of_t() and tagged_form_of_t().

normalize_pos[ترمیم]

{{#invoke:form of/templates|normalize_pos}}

Template-callable function to normalize a part-of-speech tag given a possible abbreviation (passed in as |1= of the invocation args). If the abbreviation isn't recognized, the original POS tag is returned. If no POS tag is passed in, return the value of invocation arg |default=.


local export = {}

function export.template_tags(frame)
	local iparams = {
		[1] = {list = true, required = true},
		["cat"] = {},
	}
	
	local iargs = require("Module:parameters").process(frame.args, iparams)
	
	local params = {
		[1] = {required = true},
		[2] = {},
		[3] = {alias_of = "gloss"},
		
		["gloss"] = {},
		["t"] = {alias_of = "gloss"},
		["id"] = {},
		["lang"] = {required = true},
		["nodot"] = {type = "boolean"},  -- does nothing right now, but used in existing entries
		["sc"] = {},
		["tr"] = {},
	}
	
	if iargs["cat"] then
		params["nocat"] = {type = "boolean"}
		params["sort"] = {}
	end
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local lang = args["lang"] or "und"
	local sc = args["sc"]
	
	lang = require("Module:languages").getByCode(lang) or require("Module:languages").err(lang, "lang")
	sc = (sc and (require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
	
	if #iargs[1] == 1 and iargs[1][1] == "f" then
		require("Module:debug").track("feminine of/" .. lang:getCode())
	end
	
	local ret = require("Module:form of").tagged_inflections(iargs[1], {lang = lang, sc = sc, term = args[1] or "term", alt = args[2], id = args["id"], gloss = args["gloss"], tr = args["tr"]})
	
	if iargs["cat"] then
		if args["nocat"] then
			require("Module:debug").track("form of/" .. table.concat(iargs[1], "-") .. "/nocat")
		else
			require("Module:debug").track("form of/" .. table.concat(iargs[1], "-") .. "/cat")
			ret = ret .. require("Module:utilities").format_categories({lang:getCanonicalName() .. " " .. iargs["cat"]}, lang, args["sort"])
		end
	end
	
	return ret
end

function export.form_of_t(frame)
	local params = {
		[1] = {required = true},
		[2] = {required = true},
		[3] = {},
		[4] = {alias_of = "gloss"},
		
		["dot"] = {},
		["gloss"] = {},
		["t"] = {alias_of = "gloss"},
		["id"] = {},
		["lang"] = {required = lang == en},
		["nodot"] = {type = "boolean"},
		["sc"] = {},
		["tr"] = {},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local lang = args["lang"] or "und"
	local sc = sc or args["sc"]
	
	lang = require("Module:languages").getByCode(lang) or require("Module:languages").err(lang, "lang")
	sc = (sc and (require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
	
	return require("Module:form of").format_t(
		(args[1] or "form") .. " of",
		{
			lang = lang,
			sc = sc,
			term = args[2] or "term",
			alt = args[3],
			id = args["id"],
			gloss = args["gloss"],
			tr = args["tr"]
		}
	)
end

function export.inflection_of_t(frame)
	local params = {
		[1] = {required = true},
		[2] = {},
		[3] = {list = true, required = true},
		
		["gloss"] = {},
		["t"] = {alias_of = "gloss"},
		["id"] = {},
		["lang"] = {required = true},
		["nocap"] = {type = "boolean"},
		["nocat"] = {type = "boolean"},
		["nodot"] = {type = "boolean"},
		["pos"] = {},
		["sc"] = {},
		["tr"] = {},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local lang = args["lang"] or "und"
	local sc = args["sc"]
	
	lang = require("Module:languages").getByCode(lang) or
		require("Module:languages").err(lang, "lang")
	sc = (sc and (require("Module:scripts").getByCode(sc) or
		error("The script code \"" .. sc .. "\" is not valid.")) or nil)
	
	return require("Module:form of").tagged_inflections(
		args[3],
		{
			lang = lang,
			sc = sc,
			term = args[1] or "term",
			alt = args[2],
			id = args["id"],
			gloss = args["gloss"],
			pos = args["pos"],
			tr = args["tr"]
		}
	)
end

return export