Module:headword/templates: Difference between revisions

Jump to navigation Jump to search
Undo revision 374700 by Sware (talk)
No edit summary
Tag: Reverted
(Undo revision 374700 by Sware (talk))
Tag: Undo
Line 1: Line 1:
insert = table.insert
local process_params = require("Module:parameters").process
local export = {}
local export = {}


local function get_args(frame)
-- Part of speech types that should not be pluralized.
local boolean = {type = "boolean"}
local invariable = mw.loadData("Module:headword/data").invariable
local boolean_list_allow_holes = {type = "boolean", list = true, allow_holes = true}
local list_allow_holes = {list = true, allow_holes = true}
local plain = {}
return process_params(frame:getParent().args, {
[1] = {required = true, type = "language", default = "und"},
["sc"] = {type = "script"},
["sort"] = plain,


function export.head_t(frame)
local plain_param = {}
local list_with_holes = {list = true, allow_holes = true}
local params = {
[1] = {required = true, default = "und"},
["sc"] = plain_param,
["cat sc"] = plain_param,
["sort"] = plain_param,
[2] = {required = true, default = "nouns"},
[2] = {required = true, default = "nouns"},
["sccat"] = boolean,
["noposcat"] = {type = "boolean"},
["noposcat"] = boolean,
["nomultiwordcat"] = {type = "boolean"},
["nomultiwordcat"] = boolean,
["nogendercat"] = {type = "boolean"},
["nogendercat"] = boolean,
["cat2"] = plain_param,
["nopalindromecat"] = boolean,
["cat3"] = plain_param,
["nolinkhead"] = boolean,
["cat4"] = plain_param,
["autotrinfl"] = boolean,
["cat2"] = plain,
["cat3"] = plain,
["cat4"] = plain,
["head"] = list_allow_holes,
["head"] = {list = true, allow_holes = true, default = ""},
["id"] = plain,
["id"] = plain_param,
["tr"] = list_allow_holes,
["tr"] = list_with_holes,
["ts"] = list_allow_holes,
["ts"] = list_with_holes,
["gloss"] = plain,
["g"] = {list = true},
["g"] = {list = true},
["g\1qual"] = list_allow_holes,
["affix"] = {list = true},
[3] = list_allow_holes,
[3] = list_with_holes,
["f\1accel-form"] = list_allow_holes,
["f=accel-form"]     = list_with_holes,
["f\1accel-translit"] = list_allow_holes,
["f=accel-translit"] = list_with_holes,
["f\1accel-lemma"] = list_allow_holes,
["f=accel-lemma"]   = list_with_holes,
["f\1accel-lemma-translit"] = list_allow_holes,
["f=accel-lemma-translit"] = list_with_holes,
["f\1accel-gender"] = list_allow_holes,
["f=accel-gender"]   = list_with_holes,
["f\1accel-nostore"] = boolean_list_allow_holes,
["f=accel-nostore"] = {list = true, allow_holes = true, type = "boolean"},
["f\1request"] = list_allow_holes,
["f=request"]       = list_with_holes,
["f\1alt"] = list_allow_holes,
["f=alt"]            = list_with_holes,
["f\1lang"] = {list = true, allow_holes = true, type = "language"},
["f=sc"]             = list_with_holes,
["f\1sc"] = {list = true, allow_holes = true, type = "script"},
["f=id"]             = list_with_holes,
["f\1id"] = list_allow_holes,
["f=tr"]             = list_with_holes,
["f\1tr"] = list_allow_holes,
["f=g"]             = list_with_holes,
["f\1ts"] = list_allow_holes,
["f=qual"]           = list_with_holes,
["f\1g"] = list_allow_holes,
["f=nolink"]         = {list = true, allow_holes = true, type = "boolean"},
["f\1qual"] = list_allow_holes,
["f=lang"]           = list_with_holes,
["f\1autotr"] = boolean_list_allow_holes,
}
["f\1nolink"] = boolean_list_allow_holes,
})
local args = require("Module:parameters").process(frame:getParent().args, params)
end
 
function export.head_t(frame)
local m_headword = require("Module:headword")
 
local args = get_args(frame)
 
-- Get language and script information
-- Get language and script information
local data = {}
local data = {}
data.lang = args[1]
data.lang = require("Module:languages").getByCode(args[1]) or require("Module:languages").err(args[1], 1)
data.sc = args["sc"]
data.sccat = args["sccat"]
data.sort_key = args["sort"]
data.sort_key = args["sort"]
data.heads = args["head"]
data.heads = args["head"]
Line 71: Line 57:
data.translits = args["tr"]
data.translits = args["tr"]
data.transcriptions = args["ts"]
data.transcriptions = args["ts"]
data.gloss = args["gloss"]
data.genders = args["g"]
data.genders = args["g"]
-- This shouldn't really happen.
data.affix = args["affix"]
for k, v in pairs(args["gqual"]) do
if k ~= "maxindex" then
-- Script
if data.genders[k] then
local cat_sc
data.genders[k] = {spec = data.genders[k], qualifiers = {v}}
else
if args["cat sc"] then
k = k == 1 and "" or tostring(k)
data.sc = (args["cat sc"] and (require("Module:scripts").getByCode(args["cat sc"]) or error("The script code \"" .. args["cat sc"] .. "\" is not valid.")) or nil)
error(("g%squal= specified without g%s="):format(k, k))
cat_sc = cat_sc
end
else
end
data.sc = (args["sc"] and (require("Module:scripts").getByCode(args["sc"]) or error("The script code \"" .. args["sc"] .. "\" is not valid.")) or nil)
end
end
 
-- Part-of-speech category
-- Part-of-speech category
local pos_category = args[2]
data.pos_category = args[2]
data.noposcat = args["noposcat"]
data.noposcat = args["noposcat"]
-- Check for headword aliases and then pluralize if the POS term does not have an invariable plural.
if not data.pos_category:find("s$") and not invariable[data.pos_category] then
data.pos_category = m_headword.pluralize_pos(
-- Make the plural form of the part of speech
mw.loadData("Module:headword/data").pos_aliases[pos_category] or pos_category
if data.pos_category:find("x$") then -- prefix, suffix, confix, infix, circumfix, affix, interfix, transfix
)
data.pos_category = data.pos_category .. "es"
 
else
-- Additional categories.
data.pos_category = data.pos_category .. "s"
end
end
if cat_sc then
data.pos_category = data.pos_category .. " in " .. cat_sc:getCategoryName()
end
-- Additional categories
data.categories = {}
data.categories = {}
data.whole_page_categories = {}
data.nomultiwordcat = data.pos_category == "circumfixes" and true or args["nomultiwordcat"]
data.nomultiwordcat = args["nomultiwordcat"]
data.nogendercat = args["nogendercat"]
data.nogendercat = args["nogendercat"]
data.nopalindromecat = args["nopalindromecat"]
 
table.insert(data.categories, "Contionary")
if args["cat2"] then
if args["cat2"] then
insert(data.categories, data.lang:getFullName() .. " " .. args["cat2"])
table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat2"])
end
end
 
if args["cat3"] then
if args["cat3"] then
insert(data.categories, data.lang:getFullName() .. " " .. args["cat3"])
table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat3"])
end
end
 
if args["cat4"] then
if args["cat4"] then
insert(data.categories, data.lang:getFullName() .. " " .. args["cat4"])
table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat4"])
end
end
 
-- Headword linking
data.nolinkhead = args["nolinkhead"]
 
-- Inflected forms
-- Inflected forms
data.inflections = {enable_auto_translit = args["autotrinfl"]}
data.inflections = {}
 
for i = 1, math.ceil(args[3].maxindex / 2) do
for i = 1, math.ceil(args[3].maxindex / 2) do
local infl_part = {
local infl_part = {
Line 131: Line 121:
} or nil,
} or nil,
request  = args["frequest"][i],
request  = args["frequest"][i],
enable_auto_translit = args["fautotr"][i],
}
}
local form = {
local form = {
term         =  args[3][i * 2],
term       =  args[3][i * 2],
alt           =  args["falt"][i],
alt       =  args["falt"][i],
genders       = args["fg"][i] and mw.text.split(args["fg"][i], ",") or {},
genders   = {args["fg"][i]},
id           =  args["fid"][i],
id         =  args["fid"][i],
lang         =  args["flang"][i],
lang       =  args["flang"][i],
nolinkinfl    =  args["fnolink"][i],
nolink    =  args["fnolink"][i],
q            = {args["fqual"][i]},
qualifiers = {args["fqual"][i]},
sc           =  args["fsc"][i],
sc         =  args["fsc"][i],
translit     =  args["ftr"][i],
translit   =  args["ftr"][i],
transcription =  args["fts"][i],
}
}
if form.lang then
form.lang = require("Module:languages").getByCode(form.lang) or require("Module:languages").err(form.lang, "f" .. i .. "lang")
end
if form.sc then
form.sc = require("Module:scripts").getByCode(form.sc) or error("The script code \"" .. form.sc .. "\" is not valid.")
end
if form.term == "?" or form.term == "-" then
table.insert(data.categories, "Contionary stubs")
end
-- If no term or alt is given, then the label is shown alone.
-- If no term or alt is given, then the label is shown alone.
if form.term or form.alt then
if form.term or form.alt then
insert(infl_part, form)
table.insert(infl_part, form)
end
end
Line 155: Line 155:
-- Append to the previous inflection part, if one exists
-- Append to the previous inflection part, if one exists
if #infl_part > 0 and data.inflections[1] then
if #infl_part > 0 and data.inflections[1] then
insert(data.inflections[#data.inflections], form)
table.insert(data.inflections[#data.inflections], form)
end
end
elseif infl_part.label then
elseif infl_part.label then
-- Add a new inflection part
-- Add a new inflection part
insert(data.inflections, infl_part)
table.insert(data.inflections, infl_part)
end
end
end
end
return m_headword.full_headword(data)
return require("Module:headword").full_headword(data)
end
end


return export
return export

Navigation menu