Anonymous user
Module:Convert: Difference between revisions
error messages only include a category in wanted namespaces (default 0,10); isolate template parms so they cannot be mistaken for working parms; trim boolean
(accept user-defined combination like "LT+ST"; fix adj=on|lk=on bug so do not put hyphens in link target) |
(error messages only include a category in wanted namespaces (default 0,10); isolate template parms so they cannot be mistaken for working parms; trim boolean) |
||
Line 13:
-- Configuration options to keep magic values in one location.
-- Conversion data and message text are defined in separate modules.
local config, maxsigfig
local numdot, numsep -- each must be a single byte for simple regex search/replace
local default_exceptions, link_exceptions, all_units
local SIprefixes, all_categories, all_messages, customary_units, disp_joins
Line 35:
if text then
text = text:lower()
if text == '
return true
end
end
return false
end
Line 77 ⟶ 78:
local function set_config(frame)
-- Set configuration options from template #invoke or defaults.
numdot =
numsep =
maxsigfig =
-- Scribunto sets the global variable 'mw'.
-- A testing program can set the global variable 'is_test_run'.
Line 92:
spell_module = "ConvertNumeric"
else
local sandbox = boolean(
data_module = "Module:Convert/data" .. sandbox
text_module = "Module:Convert/text" .. sandbox
Line 171:
if type(text) == 'string' then
return text:match("^%s*(.-)%s*$")
end
end
local function wanted_category(cat)
-- Return cat if it is wanted in current namespace, otherwise return nil.
-- This is so tracking categories only include pages that need correction.
-- Default wanted namespaces are 0 (article) and 10 (template).
local title = mw.title.getCurrentTitle()
if title then
for _, v in ipairs(split(config.nscat or '0,10', ',')) do
if namespace == tonumber(v) then
return cat
end
end
end
Line 188 ⟶ 203:
mcode[3] or '?',
mcode[4] or '?')
local cat = wanted_category(all_categories[msg[2]]) or ''
local prefix = all_messages[msg.warning and 'cvt_prefix_warning' or 'cvt_prefix_error'] or ''
local suffix = (prefix == '') and '' or '</span>'
Line 203 ⟶ 218:
-- If enabled, add a warning that will be displayed after the convert result.
-- To reduce output noise, only the first warning is displayed.
if boolean(config.warnings) then
if parms.warnings == nil then
parms.warnings = message({ mcode, text })
Line 1,346 ⟶ 1,361:
end
local function translate_parms(parms,
-- Update fields in parms by translating
-- used by this module (may involve translating from local language to English).
-- Also, checks are performed which may display warnings, if enabled.
-- Return true if successful or return false, t where t is an error message table.
if kv_pairs.adj and kv_pairs.sing then
-- For en.wiki (before translation), warn if attempt to use adj and sing
▲ local loc_value = parms[loc_name]
-- as the latter is a deprecated alias for the former.
if kv_pairs.adj ~= kv_pairs.sing and kv_pairs.sing ~= '' then
add_warning(parms, 'cvt_unknown_option', 'sing=' .. kv_pairs.sing)
end
kv_pairs.sing = nil
end
for loc_name, loc_value in pairs(kv_pairs) do
local en_name = en_option_name[loc_name]
if en_name then
Line 1,372 ⟶ 1,395:
add_warning(parms, 'cvt_empty_option', loc_name)
else
--
--
local text = loc_value and (loc_name .. '=' .. loc_value) or loc_name
add_warning(parms, 'cvt_unknown_option', text)
Line 1,485 ⟶ 1,507:
-- whitespace entered in the template, and whitespace is used by some
-- parameters (example: the numbered parameters associated with "disp=x").
local parms = {} -- arguments passed to template, after translation
local
for k, v in pairs(pframe.args) do
if type(k) == 'number' or k == 'test' then -- parameter "test" is reserved for testing and is not translated
▲ parms[k] = v
kv_pairs[k] = v
end
end
local success, msg = translate_parms(parms,
if not success then return false, msg end
local success, valinfo, i = get_values(parms)
|