The following documentation is located at Module:headword/documentation. [edit]

This module is used to show headword lines, along with any annotations like genders, transliterations and inflections. It's used by the template {{head}}, via the submodule Module:headword/templates.


format_headword(heads, lang, sc)

Format a headword, using the format appropriate for the given language and script (see Module:script utilities#tag_text). It has special behaviour in certain cases as well:

  • If the current page is in the appendix namespace, and the language's type (in Module:languages) is not appendix-constructed, then a * will be prepended to the headword to indicate that it is a reconstructed term.
  • If the head parameter contains wikilinks, it will turn them into section links for the given language (using Module:links#language_link, which is also used by {{l}}). For example, giving head as "[[give]] [[up]]" and lang as "en" will produce: [[give#English|give]] [[up#English|up]]. If the head parameter is prefixed with * or if any of the links are, then it will create links to the appendix namespace, as is appropriate for reconstructed terms.

The heads parameter can either be a single string or a table of strings. If it's a table, then each string in the table is shown as a headword, separated by "or". This allows you to show multiple alternative headwords, such as when the same written form can be accented in different ways.


format_transliteration(tr, lang)

If the transliteration is specified and non-empty, adds some stuff before and after it. For example, if the transliteration is 'foo' and the language is Hebrew, produces
 [[Wiktionary:Hebrew transliteration|•]] (<span lang="">foo</span>)
which looks like “ (foo)”.

(Note: the bullet/link is only added if the linked-to page actually exists.)


format_genders(genders, lang)

Format gender specifications using Module:gender and number. This function currently has fairly limited capabilities, but more may be added later.


format_inflections(inflections, lang, sc)

Format a list (table) of inflections, which are then concatenated together with commas and surrounded by parentheses. For example:

format_inflections({"first", "second", "third"}, "en", "Latn")


 (first, second, third)

displays as: (first, second, third)

If an element of the table is itself a table, then it is taken to consist of a list of labelled inflections:

  • The table must have a .label value which contains the label. It is displayed in italics and not linked.
  • The table may optionally have a .accel value. This value is used to support accelerated entry creation using WT:ACCEL. The "form-of" and "lang-(code)" classes are added automatically, so only the "(form)-form-of" class needs to be given, along with any other classes that may be needed.
  • The table may optionally have a .nolink value. If true, this will tell the function not to link to the terms, but only display them.
  • Numbered values in the table are the actual forms. They are formatted in bold text and converted to a link to the term. If a term already contains a link, it is converted into a section link using Module:links#language_link, just like in format_headword.
  • Forms are optional. If the table contains only the .label, then just the label is shown with no forms. If there is more than one form, they are shown with "or" between them.

For example:

    {label = "present", "krama"},
    {label = "past", "kramade"},
    {label = "past participle", "kramat"},
    "sv", "Latn")
    {label = "plural", accel = "plural-form-of", "voorbeelden"},
    "nl", "Latn")


 (''present'' <b lang=\"sv\">[[krama#Swedish|krama]]</b>, ''past'' <b lang=\"sv\">[[kramade#Swedish|kramade]]</b>, ''past participle'' <b lang=\"sv\">[[kramat#Swedish|kramat]]</b>)
 (''plural'' <span class=\"form-of lang-nl plural-form-of\"><b lang=\"nl\">[[voorbeelden#Dutch|voorbeelden]]</b></span>)

displays as:

(present krama, past kramade, past participle kramat)
(plural voorbeelden)

It is also possible, but optional, to supply a table instead of a term. This table can contain the keys .term (the actual term), .alt (alternative display form), .sc (script), .id (sense id) and .genders (list of genders). These are used the same way as for full_link in Module:links, and are passed directly to it.


    {label = "diminutive", {term = "Hündchen", genders = {"n"}}},
    "de", "Latn")


 (''diminutive'' <b lang=\"de\">[[Hündchen#German|Hündchen]]</b> <span class=\"gender\"><abbr title="neuter gender">n</abbr></span>)

displays as:

(diminutive Hündchen n)

Proposed/planned changes

  • Automatic transliteration for languages that support it. Note that the parameters of format_transliteration will need change for this to be implemented.
  • Checking for invalid genders, given a list genders that are valid for a particular language.

local export = {}
function export.full_headword(lang, sc, heads, tr, genders, inflections, categories, sort_key)
	local m_links = require("Module:links")
	local m_utilities = require("Module:utilities")
	local scFix = false
	-- Try to detect the script if it was not provided
	if not sc then
		sc, scFix = m_utilities.detect_script(heads[1] or SUBPAGENAME, lang)
	-- Try to generate a transliteration if necessary
	-- Generate it if the script is not Latn or similar, and if no transliteration was provided
	if tr == "-" then
		tr = nil
	elseif not tr and not ((sc:find("Latn", nil, true)) or sc == "Latinx" or sc == "unicode") then
		tr = lang:transliterate(heads[1] and m_links.remove_links(heads[1]) or SUBPAGENAME, sc)
	-- Format and return all the gathered information
		export.format_headword(heads, lang, sc) ..
		export.format_transliteration(tr, lang) ..
		export.format_genders(genders, lang) ..
		export.format_inflections(inflections, lang, sc) ..
		(scFix and "[[Category:Terms using script detection fallback]][[Category:Terms using script detection fallback/" .. lang:getCode() .. "]]" or "")
-- Format a headword
function export.format_headword(heads, lang, sc)
	local m_links = require("Module:links")
	local m_scriptutils = require("Module:script utilities")
	if type(heads) ~= "table" then
		heads = {heads}
	if #heads == 0 then
	   	NAMESPACE = NAMESPACE or mw.title.getCurrentTitle().nsText
	   	SUBPAGENAME = SUBPAGENAME or mw.title.getCurrentTitle().subpageText
		if NAMESPACE == "Appendix" and lang:getType() ~= "appendix-constructed" then
			heads = {"*" .. SUBPAGENAME}
			heads = {SUBPAGENAME}
	for i, head in ipairs(heads) do
		-- Apply processing to the headword, for formatting links and such
		if head:find("[[", nil, true) then
			head = m_links.language_link(head, nil, lang)
		-- Add language and script wrapper
		head = m_scriptutils.tag_text(head, lang, sc, "head")
		heads[i] = head
	return table.concat(heads, " ''or'' ")
-- Format transliteration
function export.format_transliteration(tr, lang)
	if tr then
		local ret = " (<span lang=\"\">" .. tr .. "</span>)"
		if lang and .. " transliteration", "Wiktionary").exists then
			ret = " [[Wiktionary:" .. lang:getCanonicalName() .. " transliteration|•]]" .. ret
		return ret
		return ""
function export.format_genders(genders, lang)
	if #genders > 0 then
		local gen = require("Module:gender and number")
		return "&nbsp;" .. gen.format_list(genders, lang:getCode())
		return ""
-- Format the inflections following the headword
function export.format_inflections(inflections, lang, sc)
	FULLPAGENAME = FULLPAGENAME or mw.title.getCurrentTitle().prefixedText
	if #inflections > 0 then
		-- Format each inflection individually
		for key, infl in ipairs(inflections) do
			-- If this inflection is a table, it contains parts
			-- consisting of alternating label-term pairs. Format them too.
			if type(infl) == "table" then
				inflections[key] = format_parts(infl, lang, sc)
		return " (" .. table.concat(inflections, ", ") .. ")"
		return ""
function format_parts(parts, lang, sc)
	local m_links = require("Module:links")
	for key, part in ipairs(parts) do
		if type(part) ~= "table" then
			part = {term = part}
		-- Convert the term into a full link
		-- Don't show a transliteration here, the consensus seems to be not to
		-- show them in headword lines to avoid clutter.
		part = m_links.full_link(not parts.nolink and part.term or nil, part.alt or (parts.nolink and part.term or nil), lang,, "bold",, {genders = part.genders, tr = "-"}, FULLPAGENAME)
		if parts.accel then
			part = "<span class=\"form-of lang-" .. lang:getCode() .. " " .. parts.accel .. "\">" .. part .. "</span>"
		parts[key] = part
	return "''" .. parts.label .. "''" .. (#parts > 0 and " " .. table.concat(parts, " ''or'' ") or "")
return export
Last modified on 20 January 2014, at 14:31