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 | local formatted_labels = {} | ||
local | 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 | local compat = iargs.lang or parent_args.lang | ||
local params = { | local params = { | ||
[compat and "lang" or 1] = {required = not iargs | [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 | local lang = args[compat and "lang" or 1] or iargs.lang or require("Module:languages").getByCode("und") | ||
local nocat = args | local nocat = args.nocat | ||
for _, | local already_seen = {} | ||
local | for _, from_label in ipairs(args.from) do | ||
local processed_labels = require(labels_module).split_and_process_raw_labels { | |||
labels = from_label, | |||
lang = lang, | |||
if | mode = "form-of", | ||
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 | ||
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 | ||