This module is used by the template {{head}}
to create headwords for entries.
local export = {}
-- Part of speech types that should not be pluralized.
local invariable = {
= true,
= true,
= true,
= true,
= true,
= true,
= true,
= true,
= true,
= true,
= true,
= true,
= true,
= true,
}
local params = {
= {required = true, default = "und"},
= {},
= {},
= {},
= {required = true},
= {},
= {},
= {},
= {list = true, allow_holes = true, default = ""},
= {list = true, allow_holes = true},
= {list = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true, type = "boolean"},
= {list = true, allow_holes = true},
}
function export.head_t(frame)
local args = require("Module:parameters").process(frame:getParent().args, params)
-- Get language and script information
local lang = args
local sc = args
local cat_sc = args
lang = require("Module:languages").getByCode(lang) or require("Module:languages").err(lang, 1)
if cat_sc then
cat_sc = (cat_sc and (require("Module:scripts").getByCode(cat_sc) or error("The script code \"" .. cat_sc .. "\" is not valid.")) or nil)
sc = cat_sc
else
sc = (sc and (require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
end
-- Gather basic parameters
local sort_key = args
local pos = args
local cat2 = args
local cat3 = args
local cat4 = args
local heads = args
local translits = args
local genders = args
local accels = args
local requests = args
local alts = args
local gs = args
local ids = args
local langs = args
local nolinks = args
local quals = args
local scs = args
local trs = args
-- Gather inflected forms
local inflections = {}
-- Go over all the inflection parameters
for i = 1, math.ceil(args.maxindex / 2) do
local infl_part = {
label = args,
accel = accels,
request = requests,
}
local form = {
term = args,
alt = alts,
genders = {gs},
id = ids,
lang = langs,
nolink = nolinks,
qualifiers = {quals},
sc = scs,
translit = trs,
}
if form.lang ~= nil then
form.lang = require("Module:languages").getByCode(form.lang) or require("Module:languages").err(form.lang, "f" .. i .. "lang")
end
if form.sc ~= nil then
form.sc = require("Module:scripts").getByCode(form.sc) or error("The script code \"" .. form.sc .. "\" is not valid.")
end
-- If no term or alt is given, then the label is shown alone.
if form.term or form.alt then
table.insert(infl_part, form)
end
if infl_part.label == "or" then
-- Append to the previous inflection part, if one exists
if #infl_part > 0 and inflections then
table.insert(inflections, form)
end
elseif infl_part.label then
-- Add a new inflection part
table.insert(inflections, infl_part)
end
end
-- Get/set categories
local categories = {}
local tracking_categories = {}
if pos then
if not pos:find("s$") and not invariable then
-- Make the plural form of the part of speech
if pos:find("x$") then
pos = pos .. "es"
else
pos = pos .. "s"
end
end
table.insert(categories, lang:getCanonicalName() .. " " .. pos .. (cat_sc and " in " .. cat_sc:getCategoryName() or ""))
end
if cat2 then
table.insert(categories, lang:getCanonicalName() .. " " .. cat2)
end
if cat3 then
table.insert(categories, lang:getCanonicalName() .. " " .. cat3)
end
if cat4 then
table.insert(categories, lang:getCanonicalName() .. " " .. cat4)
end
if #categories == 0 and mw.title.getCurrentTitle().nsText == "Template" then
categories = {"Undetermined nouns"}
end
return
require("Module:headword").full_headword(lang, sc, heads, translits, genders, inflections, categories, sort_key) ..
require("Module:utilities").format_categories(tracking_categories, lang, sort_key)
end
return export