Modifiche

Modulo:Headword/templates

958 byte aggiunti, 05:12, 5 set 2018
m
174 versioni importate
local m_headword export = require("Module:headword"){}
-- Part of speech types that should not be pluralized.local export invariable = {}mw.loadData("Module:headword/data").invariable
-- The main entry point.-- This is the only function that can be invoked from a template.function export.showhead_t(frame) local m_utilities plain_param = require({} 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"}, ["cat2"] = plain_param, ["cat3"] = plain_param, ["cat4"] = plain_param, ["head"] = {list = true, allow_holes = true, default = ""}, ["id"] = plain_param, ["tr"] = list_with_holes, -- See also "ts" at bottom. ["g"] = {list = true}, [3] = list_with_holes, ["f=accel"] = list_with_holes, ["f=request"] = list_with_holes, ["f=alt"] = list_with_holes, ["f=sc"] = list_with_holes, ["f=id"] = list_with_holes, ["f=tr"] = list_with_holes, ["f=g"] = list_with_holes, ["f=qual"] = list_with_holes, ["f=nolink"] = {list = true, allow_holes = true, type = "boolean"}, ["f=lang"] = list_with_holes, -- Belongs after "tr", but has to be placed here, or args["falt"] will vanish. ["Module:utilitiests")] = list_with_holes, }
local args = require("Module:parameters").process(frame:getParent().args PAGENAME = mw.title.getCurrentTitle(, params).text SUBPAGENAME = mw.title.getCurrentTitle().subpageText NAMESPACE = mw.title.getCurrentTitle().nsText
-- Get language and script information
local data = {} data.lang = args[1] or require(NAMESPACE == "Template" and "undModule:languages") or error.getByCode("Language code has not been specified. Please pass parameter args[1 to the template."]) lang = or require("Module:languages").getLanguageByCodeerr(langargs[1], 1) local sc data.sort_key = args["scsort"] or data.heads = args["head"] data.id = args["id"; if sc ] data.translits =args["tr"] data.transcriptions = args["ts" then sc ] data.genders = nil endargs["g"]
-- Gather basic parametersScript local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end local pos = args[2]; if pos == "" then pos = nil end local cat = args["cat"]; if cat == "" then cat = nil end local cat2 = args["cat2"]; if cat2 == "" then cat2 = nil end local cat3 = args["cat3"]; if cat3 == "" then cat3 = nil end local tr = args["tr"]; if tr == "" then tr = nil endcat_sc
-- Gather headwordsif args["cat sc"] then local heads 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) cat_sc = {}cat_sc local head else data.sc = (args["headsc"]; if head == and (require("Module:scripts").getByCode(args["sc"]) or error("The script code \"" .. args["sc"] .. "\"is not valid." then head = )) or nil end) local i = 2end
while head do-- Part-of-speech category table data.insert(heads, head) head pos_category = args[2] if not data.pos_category:find("heads$" ) and not invariable[data.. ipos_category]; then -- Make the plural form of the part of speech if head == data.pos_category:find("x$" ) then head -- prefix, suffix, confix, infix, circumfix, affix, interfix, transfix data.pos_category = nil enddata.pos_category .. "es" i else data.pos_category = i + 1data.pos_category .. "s" end
end
-- Gather gender and number specificationsif cat_sc then data.pos_category = data.pos_category .. " in " .. cat_sc:getCategoryName() end -- Iterate over all gn parameters (g2, g3 and so on) until one is emptyAdditional categories local genders data.categories = {} local g = if args["gcat2"]; if g == then table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat2" then g = nil end]) local i = 2end
while g doif args["cat3"] then table.insert(gendersdata.categories, gdata.lang:getCanonicalName() g = args[.. "g" .. i]; if g == args["cat3" then g = nil end i = i + 1])
end
-- Gather inflected formsif args["cat4"] then table.insert(data.categories, data.lang:getCanonicalName() .. " " .. args["cat4"]) local inflections = {}end
local i = 1-- Inflected forms local label = args[i * 2 + 1] local parts data.inflections = {label = label, accel = "f" .. i .. "accel"}
while label for i = 1, math.ceil(args[3].maxindex / 2) do local term infl_part = { label = args[3][i * 2 + 2- 1]; if term , accel =args["faccel"][i], request = args["frequest" then ][i], } local form = { term = nil end args[3][i * 2], local alt = args["ffalt" .. ][i .. ], genders = {args["altfg"]; if alt [i]}, id = args["fid"][i], lang = args["flang" then alt = nil end][i], local sc nolink = args["ffnolink" .. ][i .. ], qualifiers = {args["scfqual"]; if [i]}, sc == args["fsc" then sc = nil end][i], local id translit = args["fftr" .. ][i ], } if form.lang then form. lang = require("idModule:languages"]; if id == ).getByCode(form.lang) or require("Module:languages" then id = nil end local gender = args[).err(form.lang, "f" .. i .. "glang"]; if gender == "" then gender = nil ) end
if term form.sc then tableform.sc = require("Module:scripts").insertgetByCode(parts, {term = term, alt = alt, form.sc = ) or error("The script code \"" .. form.sc, id = id, genders = {gender}}.. "\" is not valid.")
end
i = i + 1-- If no term or alt is given, then the label is shown alone. label = args[i * 2 + 1]if form.term or form.alt then table.insert(infl_part, form) end
-- If the next label is not "or" then insert the previous one and create a new oneif infl_part. if label ~== "or" then -- Only insert if Append to the previous label is not empty.inflection part, if one exists if (parts#infl_part > 0 and data.label or "") ~= "" inflections[1] then table.insert(data.inflections[#data.inflections], partsform)
end
elseif infl_part.label then -- Add a new inflection part parts = {label = label}table.insert(data.inflections, infl_part)
end
end
-- Get/set categories local categories = {} if cat then table.insertreturn require(categories, lang:getCanonicalName() .. " " .. cat) elseif pos then -- Make the plural form of the part of speech if posModule:find("x$") then pos = pos .. "esheadword" elseif pos ~= "punctuation" or pos ~= "phrasebook" then pos = pos .. "s" end table.insert(categories, lang:getCanonicalName() .. " " .. pos) end if cat2 then table.insert(categories, lang:getCanonicalName() .. " " .. cat2) end if cat3 then table.insert(categories, lang:getCanonicalName() .. " " .. cat3) end return m_headword.full_headword(lang, sc, heads, tr, genders, inflections, categories, sort_key) .. m_utilities.format_categories(categories, lang, sort_keydata)
end
return export

Menu di navigazione