Module:labels/templates/show from: Difference between revisions

Created page with "local export = {} local labels_module = "Module:labels" --[[ this function is only to be used in {{alternative spelling of}}, {{eye dialect of}} and similar templates ]] function export.show_from(frame) local froms = {} local categories = {} local iparams = { ["lang"] = {type = "language"}, ["default"] = {}, } local iargs = require("Module:parameters").process(frame.args, iparams) local parent_args = frame:getParent().args local compat = iargs["..."
 
No edit summary
 
Line 2: Line 2:


local labels_module = "Module:labels"
local labels_module = "Module:labels"
local table_module = "Module:table"
local insert = table.insert
local concat = table.concat


--[[ this function is only to be used in
--[[ this function is only to be used in
Line 8: Line 11:
and similar templates ]]
and similar templates ]]
function export.show_from(frame)
function export.show_from(frame)
local froms = {}
local formatted_labels = {}
local categories = {}
local formatted_categories = {}


local iparams = {
local iparams = {
Line 18: Line 21:
local iargs = require("Module:parameters").process(frame.args, iparams)
local iargs = require("Module:parameters").process(frame.args, iparams)
local parent_args = frame:getParent().args
local parent_args = frame:getParent().args
local compat = iargs["lang"] or parent_args["lang"]
local compat = iargs.lang or parent_args.lang


local params = {
local params = {
[compat and "lang" or 1] = {required = not iargs["lang"], type = "language"},
[compat and "lang" or 1] = {required = not iargs.lang, type = "language"},
["from"] = {list = true},
["from"] = {list = true},
["nocat"] = {type = "boolean"},
["nocat"] = {type = "boolean"},
Line 31: Line 34:
-- form-of template will catch true unrecognized params.
-- form-of template will catch true unrecognized params.
local args = require("Module:parameters").process(parent_args, params, "allow unrecognized params")
local args = require("Module:parameters").process(parent_args, params, "allow unrecognized params")
local lang = args[compat and "lang" or 1] or iargs["lang"] or require("Module:languages").getByCode("und")
local lang = args[compat and "lang" or 1] or iargs.lang or require("Module:languages").getByCode("und")
local nocat = args["nocat"]
local nocat = args.nocat


for _, k in ipairs(args["from"]) do
local already_seen = {}
local ret = require(labels_module).get_label_info { label = k, lang = lang, mode = "form-of", }
for _, from_label in ipairs(args.from) do
if ret.label ~= "" then
local processed_labels = require(labels_module).split_and_process_raw_labels {
table.insert(froms, ret.label)
labels = from_label,
end
lang = lang,
if not nocat and ret.formatted_categories and ret.formatted_categories ~= "" then
mode = "form-of",
table.insert(categories, ret.formatted_categories)
nocat = nocat,
already_seen = already_seen,
ok_to_destructively_modify = true,
}
local this_formatted_labels, this_formatted_categories = require(labels_module).format_processed_labels {
labels = processed_labels,
lang = lang,
mode = "form-of",
open = false,
close = false,
no_ib_content = true,
ok_to_destructively_modify = true,
split_output = true,
}
if this_formatted_labels ~= "" then
insert(formatted_labels, this_formatted_labels)
end
end
insert(formatted_categories, this_formatted_categories)
end
end
if #froms == 0 then
return iargs.default
end


return require("Module:table").serialCommaJoin(froms) .. table.concat(categories)
local joined_formatted_labels =
#formatted_labels == 0 and iargs.default or require(table_module).serialCommaJoin(formatted_labels)
 
return joined_formatted_labels .. concat(formatted_categories)
end
end


return export
return export