Module:compound/templates: Verskil tussen weergawes

Content deleted Content added
Pynappel (Besprekings | bydraes)
Nuwe bladsy geskep met 'local m_compound = require("Module:compound") local m_languages = require("Module:languages") local m_debug = require("Module:debug") local export = {} local function...'
 
Naudefj (Besprekings | bydraes)
Werk by vanaf en:
Lyn 1:
local export = {}
 
local m_compound = require("Module:compound")
local m_languages = require("Module:languages")
local m_debug = require("Module:debug")
 
local exportrsplit = {}mw.text.split
 
 
local function get_partif_not_empty(args, offset, ival)
if val == "" then
offset = offset or 0
return nil
else
return val
end
end
 
 
local function to_boolean(val)
if not val or val == "" then
return false
else
return true
end
end
 
 
local function fetch_lang(args, allow_compat)
local compat = true
 
if not allow_compat and args["lang"] then
error('The |lang= parameter is not used by this template. Place the language code in parameter 1 instead.')
end
local termlang = allow_compat and if_not_empty(args[i + offset]; if term == "lang"]) then term =or nil end
if not lang then
local alt = args["alt" .. i]; if alt == "" then alt = nil end
compat = false
local id = args["id" .. i]; if id == "" then id = nil end
lang = if_not_empty(args[1])
local lang = args["lang" .. i]; if lang == "" then lang = nil end
end
local sc = args["sc" .. i]; if sc == "" then sc = nil end
if not lang and mw.title.getCurrentTitle().nsText == "Template" then
local tr = args["tr" .. i]; if tr == "" then tr = nil end
lang = "und"
local gloss = args["t" .. i] or args["gloss" .. i]; if gloss == "" then gloss = nil end
end
local pos = args["pos" .. i]; if pos == "" then pos = nil end
local lit = args["lit" .. i]; if lit == "" then lit = nil end
lang = lang and m_languages.getByCode(lang) or m_languages.err(lang, compat and "lang" or 1)
return lang, compat
end
 
local function fetch_script(sc)
sc = if_not_empty(sc)
if sc then
return require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
else
return nil
end
end
 
 
local function parse_args(args, allow_compat, hack_params)
local compat = args["lang"]
if compat and not allow_compat then
error('The |lang= parameter is not used by this template. Place the language code in parameter 1 instead.')
end
 
local params = {
[compat and "lang" or 1] = {required = true, default = "und"},
[compat and 1 or 2] = {list = true, allow_holes = true},
["t"] = {list = true, allow_holes = true, require_index = true},
["gloss"] = {list = true, allow_holes = true, require_index = true, alias_of = "t"},
["tr"] = {list = true, allow_holes = true, require_index = true},
["ts"] = {list = true, allow_holes = true, require_index = true},
["g"] = {list = true, allow_holes = true, require_index = true},
["id"] = {list = true, allow_holes = true, require_index = true},
["alt"] = {list = true, allow_holes = true, require_index = true},
["q"] = {list = true, allow_holes = true, require_index = true},
["lit"] = {list = true, allow_holes = true, require_index = true},
["pos"] = {},
-- Note, pos1=, pos2=, ... are different from pos=
["partpos"] = {list = "pos", allow_holes = true, require_index = true},
-- Note, lang1=, lang2=, ... are different from lang=; the former apply to
-- individual arguments, while the latter applies to all arguments
["partlang"] = {list = "lang", allow_holes = true, require_index = true},
["sc"] = {},
-- Note, sc1=, sc2=, ... are different from sc=; the former apply to
-- individual arguments when lang1=, lang2=, ... is specified, while
-- the latter applies to all arguments where langN=... isn't specified
["partsc"] = {list = "sc", allow_holes = true, require_index = true},
["pos"] = {},
["sort"] = {},
["nocat"] = {type = "boolean"},
}
 
if hack_params then
hack_params(params)
end
 
args = require("Module:parameters").process(args, params)
return args, compat and args[1] or args[2], fetch_lang(args, allow_compat), fetch_script(args["sc"])
end
 
 
local function get_parsed_part(template, args, terms, i)
local term = terms[i]
local alt = args["alt"][i]
local id = args["id"][i]
local lang = args["partlang"][i]
local sc = fetch_script(args["partsc"][i])
local tr = args["tr"][i]
local ts = args["ts"][i]
local gloss = args["t"][i]
local pos = args["partpos"][i]
local lit = args["lit"][i]
local q = args["q"][i]
local g = args["g"][i]
 
if lang then
lang =
Line 27 ⟶ 124:
end
if scnot (term or alt or tr or ts) then
sc = require("Module:scriptsdebug").getByCodetrack(sc) or error("The script code \""template .. sc"/no ..term "\"or isalt notor valid.tr")
end
if not term and not alt and not tr then
return nil
else
return { term = term, alt = alt, id = id, lang = lang, sc = sc, tr = tr,
ts = ts, gloss = gloss, pos = pos, lit = lit, }q = q,
genders = g and rsplit(g, ",") or {}
}
end
end
 
 
local function get_partsget_parsed_parts(template, args, offsetterms, istart_index)
local parts = {}
istart_index = istart_index or 1
 
-- Find the maximum index among any of the list parameters.
-- Temporary tracking code for bare arguments of which numeric variants
local maxmaxindex = 0
-- are recognized, but where the bare argument shouldn't occur.
for k, v in pairs(args) do
-- Eventually, this should be converted to use [[Module:parameters]] and
if type(v) == "table" and v.maxindex and v.maxindex > maxmaxindex then
-- the unrecognized arguments removed.
maxmaxindex = v.maxindex
local no_bare_args = {"tr", "alt", "id", "gloss", "t", "lit"}
for _, bare_arg in ipairs(no_bare_args) do
if args[bare_arg] then
m_debug.track(template .. "/bare-" .. bare_arg)
m_debug.track(template .. "/bare-arg")
end
end
 
for index = start_index, maxmaxindex do
while true do
local part = get_partget_parsed_part(template, args, offsetterms, iindex)
parts[index - start_index + 1] = part
if not part then
break
end
table.insert(parts, part)
i = i + 1
end
Line 72 ⟶ 158:
 
function export.affix(frame)
local args, terms, lang, sc = parse_args(frame:getParent().args)
 
local parts = get_parsed_parts("affix", args, terms)
-- There must be at least one part to display. If there are gaps, a term
local lang = args[1]; if lang == "" then lang = nil end
-- request will be shown.
local sc = args["sc"] or ""; if sc == "" then sc = nil end
if not next(parts) then
local pos = args["pos"]; if pos == "" then pos = nil end
local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end
local nocat = args["nocat"]; if not nocat or nocat == "" then nocat = false else nocat = true end
if args.lang then
error('The "lang" parameter is not used by the {{affix}} template. Place the language code in parameter 1 instead.')
end
if not lang then
if mw.title.getCurrentTitle().nsText == "Template" then
lang = "und"
else
error("Place the language code in parameter 1 of the {{affix}} template.")
end
end
lang = m_languages.getByCode(lang) or m_languages.err(lang, 1)
if sc then
sc = require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
end
local parts = get_parts("affix", args, 1)
-- There must be at least one part to display.
if #parts < 1 then
if mw.title.getCurrentTitle().nsText == "Template" then
parts = { {term = "prefix-"}, {term = "base"}, {term = "-suffix"} }
Line 108 ⟶ 172:
end
return m_compound.show_affixes(lang, sc, parts, args["pos"], sort_keyargs["sort"], args["nocat"])
end
 
 
function export.compound(frame)
local args, terms, lang, sc = parse_args(frame:getParent().args)
 
local compat = true
local parts = get_parsed_parts("compound", args, terms)
local lang = args["lang"]; if lang == "" then lang = nil end
local sc = args["sc"] or ""; if sc == "" then sc = nil end
local pos = args["pos"]; if pos == "" then pos = nil end
local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end
local nocat = args["nocat"]; if not nocat or nocat == "" then nocat = false else nocat = true end
if not lang then
compat = false
lang = args[1]; if lang == "" then lang = nil end
end
if not lang and mw.title.getCurrentTitle().nsText == "Template" then
lang = "und"
end
lang = m_languages.getByCode(lang) or m_languages.err(lang, compat and "lang" or 1)
if sc then
sc = require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
end
local parts = get_parts("compound", args, compat and 0 or 1)
-- There must be at least one part to display. If there are gaps, a term
-- request will be shown.
if #parts < 1 then
if not next(parts) then
if mw.title.getCurrentTitle().nsText == "Template" then
parts = { {term = "first"}, {term = "second"} }
Line 147 ⟶ 191:
end
return m_compound.show_compound(lang, sc, parts, args["pos"], sort_keyargs["sort"], args["nocat"])
end
 
 
function export.interfix_compoundcompound_like(frame)
local argsfunction = frame:getParenthack_params(params).args
params["pos"] = nil
params["nocap"] = {type = "boolean"}
local lang = args[1]; if lang == "" then lang = nil end
params["notext"] = {type = "boolean"}
local sc = args["sc"] or ""; if sc == "" then sc = nil end
end
local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end
 
local nocat = args["nocat"]; if not nocat or nocat == "" then nocat = false else nocat = true end
local args, terms, lang, sc = parse_args(frame:getParent().args, nil, hack_params)
local pos = args["pos"]; if pos == "" then pos = nil end
 
local template = frame.args["template"]
if not lang then
local nocat = args["nocat"]
local notext = args["notext"]
local text = not notext and frame.args["text"]
local oftext = not notext and (frame.args["oftext"] or text and "of")
local cat = not nocat and frame.args["cat"]
 
local parts = get_parsed_parts(template, args, terms)
 
if not next(parts) then
if mw.title.getCurrentTitle().nsText == "Template" then
parts = { {term = "first"}, {term = "second"} }
lang = "und"
else
error("Language code has not been specified. Please pass parameter 1 to the template.")
end
end
return m_compound.show_compound_like(lang, sc, parts, args["sort"], text, oftext, cat)
lang = m_languages.getByCode(lang) or m_languages.err(lang, 1)
end
if sc then
 
sc = require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
 
end
function export.interfix_compound(frame)
local args, terms, lang, sc = parse_args(frame:getParent().args)
local parts = get_parts("interfix-compound", args, 1)
 
local parts = get_parsed_parts("interfix-compound", args, terms)
local base1 = parts[1]
local interfix = parts[2]
Line 189 ⟶ 242:
end
return m_compound.show_interfix_compound(lang, sc, base1, interfix, base2, args["pos"], sort_keyargs["sort"], args["nocat"])
end
 
 
function export.circumfix(frame)
local args, terms, lang, sc = parse_args(frame:getParent().args)
 
local compat = true
local parts = get_parsed_parts("circumfix", args, terms)
local lang = args["lang"]; if lang == "" then lang = nil end
local sc = args["sc"] or ""; if sc == "" then sc = nil end
local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end
local nocat = args["nocat"]; if not nocat or nocat == "" then nocat = false else nocat = true end
local pos = args["pos"]; if pos == "" then pos = nil end
if not lang then
compat = false
lang = args[1]; if lang == "" then lang = nil end
end
if not lang and mw.title.getCurrentTitle().nsText == "Template" then
lang = "und"
end
lang = m_languages.getByCode(lang) or m_languages.err(lang, compat and "lang" or 1)
if sc then
sc = require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
end
local parts = get_parts("circumfix", args, compat and 0 or 1)
local prefix = parts[1]
local base = parts[2]
Line 232 ⟶ 264:
end
end
return m_compound.show_circumfix(lang, sc, prefix, base, suffix, args["pos"], sort_keyargs["sort"], args["nocat"])
end
 
 
function export.confix(frame)
local args, terms, lang, sc = parse_args(frame:getParent().args)
 
local compat = true
local parts = get_parsed_parts("confix", args, terms)
local lang = args["lang"]; if lang == "" then lang = nil end
local sc = args["sc"] or ""; if sc == "" then sc = nil end
local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end
local nocat = args["nocat"]; if not nocat or nocat == "" then nocat = false else nocat = true end
local pos = args["pos"]; if pos == "" then pos = nil end
if not lang then
compat = false
lang = args[1]; if lang == "" then lang = nil end
end
if not lang and mw.title.getCurrentTitle().nsText == "Template" then
lang = "und"
end
lang = m_languages.getByCode(lang) or m_languages.err(lang, compat and "lang" or 1)
if sc then
sc = require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
end
local parts = get_parts("confix", args, compat and 0 or 1)
local prefix = parts[1]
local base = #parts >= 3 and parts[2] or nil
Line 275 ⟶ 286:
end
end
return m_compound.show_confix(lang, sc, prefix, base, suffix, args["pos"], sort_keyargs["sort"], args["nocat"])
end
 
 
function export.infix(frame)
local args, terms, lang, sc = parse_args(frame:getParent().args)
 
local compat = true
local parts = get_parsed_parts("infix", args, terms)
local lang = args["lang"]; if lang == "" then lang = nil end
local sc = args["sc"] or ""; if sc == "" then sc = nil end
local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end
local nocat = args["nocat"]; if not nocat or nocat == "" then nocat = false else nocat = true end
local pos = args["pos"]; if pos == "" then pos = nil end
if not lang then
compat = false
lang = args[1]; if lang == "" then lang = nil end
end
if not lang and mw.title.getCurrentTitle().nsText == "Template" then
lang = "und"
end
lang = m_languages.getByCode(lang) or m_languages.err(lang, compat and "lang" or 1)
if sc then
sc = require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
end
local parts = get_parts("infix", args, compat and 0 or 1)
local base = parts[1]
local infix = parts[2]
Line 318 ⟶ 308:
end
return m_compound.show_infix(lang, sc, base, infix, args["pos"], sort_keyargs["sort"], args["nocat"])
end
 
 
function export.prefix(frame)
local args, terms, lang, sc = parse_args(frame:getParent().args)
 
local compat = true
local prefixes = get_parsed_parts("prefix", args, terms)
local lang = args["lang"]; if lang == "" then lang = nil end
local sc = args["sc"] or ""; if sc == "" then sc = nil end
local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end
local nocat = args["nocat"]; if not nocat or nocat == "" then nocat = false else nocat = true end
local pos = args["pos"]; if pos == "" then pos = nil end
if not lang then
compat = false
lang = args[1]; if lang == "" then lang = nil end
end
if not lang and mw.title.getCurrentTitle().nsText == "Template" then
lang = "und"
end
lang = m_languages.getByCode(lang) or m_languages.err(lang, compat and "lang" or 1)
if sc then
sc = require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
end
local prefixes = get_parts("prefix", args, compat and 0 or 1)
local base = nil
Line 353 ⟶ 322:
prefixes[#prefixes] = nil
end
 
-- Just to make sure someone didn't use the template in a silly way
if #prefixes == 0 then
Line 364 ⟶ 333:
end
return m_compound.show_prefixes(lang, sc, prefixes, base, args["pos"], sort_keyargs["sort"], args["nocat"])
end
 
 
function export.suffix(frame)
local args, terms, lang, sc = parse_args(frame:getParent().args)
 
local compat = true
local base = get_parsed_part("suffix", args, terms, 1)
local suffixes = get_parsed_parts("suffix", args, terms, 2)
local lang = args["lang"]; if lang == "" then lang = nil end
local sc = args["sc"] or ""; if sc == "" then sc = nil end
local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end
local nocat = args["nocat"]; if not nocat or nocat == "" then nocat = false else nocat = true end
local pos = args["pos"]; if pos == "" then pos = nil end
if not lang then
compat = false
lang = args[1]; if lang == "" then lang = nil end
end
if not lang and mw.title.getCurrentTitle().nsText == "Template" then
lang = "und"
end
lang = m_languages.getByCode(lang) or m_languages.err(lang, compat and "lang" or 1)
if sc then
sc = require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
end
local base = get_part(args, compat and 0 or 1, 1)
local suffixes = get_parts("suffix", args, compat and 0 or 1, 2)
-- Just to make sure someone didn't use the template in a silly way
Line 405 ⟶ 353:
end
return m_compound.show_suffixes(lang, sc, base, suffixes, args["pos"], sort_keyargs["sort"], args["nocat"])
end
 
Line 424 ⟶ 372:
local lang = m_languages.getByCode(args[1]) or m_languages.err(lang, 1)
local sc = fetch_script(args["sc"])
 
if sc then
sc = require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
end
local base = {term = args[2]}
local transfix = {term = args[3]}
Line 440 ⟶ 385:
local derivtype = frame.args["derivtype"]
local mode = if_not_empty(frame.args["mode"]; if mode == "" then mode = nil end)
local lang
local term
if derivtype == "PIE root" then
lang = m_languages.getByCode("ine-pro")
term = if_not_empty(args[1] or args["head"]; if term == "" then term = nil end)
 
if term then
Line 452 ⟶ 397:
end
else
lang = fetch_lang(args)
lang = args[1] or (mw.title.getCurrentTitle().nsText == "Template" and "und") or error("Language code has not been specified. Please pass parameter 1 to the template.")
term = if_not_empty(args[2] or args["head"]; if term == "" then term = nil end)
end
local id = args["id"]; if id == "" then id = nil end
local sc = args["sc"]; if sc == "" then sc = nil end
local pos = args["pos"]; if pos == "" then pos = nil end
lang = m_languages.getByCode(lang)
if sc then
sc = require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")
end
local id = if_not_empty(args["id"])
local sc = fetch_script(args["sc"])
local pos = if_not_empty(args["pos"])
 
pos = pos or "word"