Module:alternative forms: Difference between revisions
Created page with "local export = {} local labels_module = "Module:labels" local links_module = "Module:links" local parameter_utilities_module = "Module:parameter utilities" local function track(page) require("Module:debug/track")("alter/" .. page) end --[==[ Main function for displaying alternative forms. Extracted out from the template-callable function so this can be called by other modules (in particular, Module:descendants tree). `show_labels_after_terms` no longer has any me..." |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 11: | Line 11: | ||
--[==[ | --[==[ | ||
Main function for displaying alternative forms. Extracted out from the template-callable function so this can be | Main function for displaying alternative forms. Extracted out from the template-callable function so this can be | ||
called by other modules (in particular, [[Module:descendants tree]]) | called by other modules (in particular, [[Module:descendants tree]]). `allow_self_link` causes terms the same as the | ||
pagename to be shown normally; otherwise they are displayed unlinked. `default_separator` controls the separator between | |||
terms when the user didn't use a special separator term like ";" (defaulting to ", "). | |||
]==] | ]==] | ||
function export.display_alternative_forms(parent_args, pagename, | function export.display_alternative_forms(parent_args, pagename, allow_self_link, default_separator) | ||
local params = { | local params = { | ||
[1] = {required = true, type = "language", default = "en"}, | [1] = {required = true, type = "language", default = "en"}, | ||
| Line 21: | Line 21: | ||
} | } | ||
local m_param_utils = require(parameter_utilities_module) | |||
local param_mods = m_param_utils.construct_param_mods { | local param_mods = m_param_utils.construct_param_mods { | ||
| Line 31: | Line 31: | ||
} | } | ||
local items, args = m_param_utils. | local items, args = m_param_utils.parse_list_with_inline_modifiers_and_separate_params { | ||
params = params, | params = params, | ||
param_mods = param_mods, | param_mods = param_mods, | ||
| Line 41: | Line 41: | ||
sc = "sc.default", | sc = "sc.default", | ||
stop_when = function(data) | stop_when = function(data) | ||
local stop = not data.any_param_at_index | |||
if stop and parent_args[data.orig_index + 1] == nil then | |||
track("actual hole in params") | |||
end | |||
return stop | |||
end, | end, | ||
default_separator = default_separator, | |||
} | } | ||
| Line 87: | Line 92: | ||
-- If the to-be-linked term is the same as the pagename, display it unlinked. | -- If the to-be-linked term is the same as the pagename, display it unlinked. | ||
for _, item in ipairs(items) do | for _, item in ipairs(items) do | ||
if not item.term and | if not item.term and lang:stripDiacritics(item.term) == pagename then | ||
track("term is pagename") | track("term is pagename") | ||
item.alt = item.alt or item.term | item.alt = item.alt or item.term | ||
| Line 135: | Line 140: | ||
function export.create(frame) | function export.create(frame) | ||
local parent_args = frame:getParent().args | local parent_args = frame:getParent().args | ||
return export.display_alternative_forms(parent_args, mw.loadData("Module:headword/data").pagename) | |||
return export.display_alternative_forms(parent_args, | |||
end | end | ||
return export | return export | ||