Module:Convert: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(an output combination unit can be user-defined, consisting of unit codes separated by "+" or " " (space)) |
(update from Module:Convert/sandbox: "warnings=1") |
||
Line 217: | Line 217: | ||
end |
end |
||
local function add_warning(parms, mcode, text) |
local function add_warning(parms, level, mcode, text) |
||
-- If enabled, add a warning that will be displayed after the convert result. |
-- If enabled, add a warning that will be displayed after the convert result. |
||
-- To reduce output noise, only the first warning is displayed. |
-- To reduce output noise, only the first warning is displayed. |
||
if |
if config.warnings then |
||
if |
if level <= (tonumber(config.warnings) or 1) then |
||
parms.warnings = |
if parms.warnings == nil then |
||
parms.warnings = message({ mcode, text }) |
|||
end |
|||
end |
end |
||
end |
end |
||
Line 243: | Line 245: | ||
success, speller = pcall(get_speller, spell_module) |
success, speller = pcall(get_speller, spell_module) |
||
if not success or type(speller) ~= 'function' then |
if not success or type(speller) ~= 'function' then |
||
add_warning(parms, 'cvt_no_spell') |
add_warning(parms, 1, 'cvt_no_spell') |
||
return nil |
return nil |
||
end |
end |
||
Line 1,419: | Line 1,421: | ||
-- as the latter is a deprecated alias for the former. |
-- as the latter is a deprecated alias for the former. |
||
if kv_pairs.adj ~= kv_pairs.sing and kv_pairs.sing ~= '' then |
if kv_pairs.adj ~= kv_pairs.sing and kv_pairs.sing ~= '' then |
||
add_warning(parms, 'cvt_unknown_option', 'sing=' .. kv_pairs.sing) |
add_warning(parms, 1, 'cvt_unknown_option', 'sing=' .. kv_pairs.sing) |
||
end |
end |
||
kv_pairs.sing = nil |
kv_pairs.sing = nil |
||
Line 1,429: | Line 1,431: | ||
if en_name == 'sigfig' then |
if en_name == 'sigfig' then |
||
if loc_value == '' then |
if loc_value == '' then |
||
add_warning(parms, 'cvt_empty_option', loc_name) |
add_warning(parms, 2, 'cvt_empty_option', loc_name) |
||
else |
else |
||
local number, is_integer = get_number(loc_value) |
local number, is_integer = get_number(loc_value) |
||
Line 1,435: | Line 1,437: | ||
en_value = number |
en_value = number |
||
else |
else |
||
add_warning(parms, 'cvt_bad_sigfig', loc_value) |
add_warning(parms, 1, 'cvt_bad_sigfig', loc_value) |
||
end |
end |
||
end |
end |
||
Line 1,442: | Line 1,444: | ||
if en_value == nil then |
if en_value == nil then |
||
if loc_value == '' then |
if loc_value == '' then |
||
add_warning(parms, 'cvt_empty_option', loc_name) |
add_warning(parms, 2, 'cvt_empty_option', loc_name) |
||
else |
else |
||
-- loc_value can no longer be nil here (at one time, that could occur |
-- loc_value can no longer be nil here (at one time, that could occur |
||
-- with aliases like |sing=off|adj=on), but am retaining safety check. |
-- with aliases like |sing=off|adj=on), but am retaining safety check. |
||
local text = loc_value and (loc_name .. '=' .. loc_value) or loc_name |
local text = loc_value and (loc_name .. '=' .. loc_value) or loc_name |
||
add_warning(parms, 'cvt_unknown_option', text) |
add_warning(parms, 1, 'cvt_unknown_option', text) |
||
end |
end |
||
elseif en_value == '' then |
elseif en_value == '' then |
||
Line 1,460: | Line 1,462: | ||
parms[en_name] = en_value |
parms[en_name] = en_value |
||
else |
else |
||
add_warning(parms, 'cvt_unknown_option', loc_name .. '=' .. loc_value) |
add_warning(parms, 1, 'cvt_unknown_option', loc_name .. '=' .. loc_value) |
||
end |
end |
||
end |
end |
||
Line 1,678: | Line 1,680: | ||
end |
end |
||
if is_bad_precision then |
if is_bad_precision then |
||
add_warning(parms, 'cvt_bad_prec', precision) |
add_warning(parms, 1, 'cvt_bad_prec', precision) |
||
else |
else |
||
parms.precision = precision |
parms.precision = precision |