A modult a Modul:etymology/templates/doublet/doc lapon tudod dokumentálni
local export = {}
local m_internal = require("Module:etymology/templates/internal")
local rsplit = mw.text.split
local rsubn = mw.ustring.gsub
-- version of rsubn() that discards all but the first return value
local function rsub(term, foo, bar)
local retval = rsubn(term, foo, bar)
return retval
end
local function get_parsed_part(template, lang, args, terms, i)
local term = terms
local alt = args
local id = args
local sc = m_internal.fetch_script(args)
local tr = args
local ts = args
local gloss = args
local pos = args
local lit = args
local g = args
if not (term or alt or tr or ts) then
require("Module:debug/track")(template .. "/no term or alt or tr")
return nil
else
return require("Module:links").full_link(
{ term = term, alt = alt, id = id, lang = lang, sc = sc, tr = tr,
ts = ts, gloss = gloss, pos = pos, lit = lit,
genders = g and rsplit(g, ",") or {}
}, "term", true)
end
end
local function get_parsed_parts(template, lang, args, terms)
local parts = {}
-- Find the maximum index among any of the list parameters.
local maxmaxindex = 0
for k, v in pairs(args) do
if type(v) == "table" and v.maxindex and v.maxindex > maxmaxindex then
maxmaxindex = v.maxindex
end
end
for index = 1, maxmaxindex do
table.insert(parts, get_parsed_part(template, lang, args, terms, index))
end
return parts
end
-- Implementation of miscellaneous templates such as {{doublet}} that can take
-- multiple terms. Doesn't handle {{blend}} or {{univerbation}}, which display
-- + signs between elements and use compound_like in ].
function export.misc_variant_multiple_terms(frame)
local params = {
= {required = true, default = "und"},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true, require_index = true},
= {list = true, allow_holes = true, require_index = true, alias_of = "t"},
= {list = true, allow_holes = true, require_index = true},
= {list = true, allow_holes = true, require_index = true},
= {list = true, allow_holes = true, require_index = true},
= {list = true, allow_holes = true, require_index = true},
= {list = true, allow_holes = true, require_index = true},
= {list = true, allow_holes = true, require_index = true},
= {list = true, allow_holes = true, require_index = true},
= {list = true, allow_holes = true, require_index = true},
= {type = "boolean"}, -- should be processed in the template itself
= {type = "boolean"},
= {type = "boolean"},
= {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local lang = m_internal.fetch_lang(args, 1)
local parts = {}
if not args then
table.insert(parts, frame.args)
end
if #args > 0 or #args > 0 then
if not args then
table.insert(parts, " ")
table.insert(parts, frame.args or "of")
table.insert(parts, " ")
end
local formatted_terms = get_parsed_parts(mw.ustring.lower(
-- Remove link and convert uppercase to lowercase to get an
-- approximation of the original template name.
rsub(rsub(frame.args, "^%%]$", "")),
lang, args, args)
table.insert(parts, require("Module:table").serialCommaJoin(formatted_terms))
end
if not args and frame.args then
local categories = {}
table.insert(categories, lang:getCanonicalName() .. " " .. frame.args)
table.insert(parts, require("Module:utilities/format_categories")(categories, lang, args))
end
return table.concat(parts)
end
return export