Module:Convert: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
(clean up, typos fixed: , → , (3) using AWB)
(handle exceptions as a property of a unit; allows localization for other wikis)
Line 19: Line 19:
local en_option_name, en_option_value, eng_scales, range_aliases, range_types
local en_option_name, en_option_value, eng_scales, range_aliases, range_types
local group_method = 3 -- code for how many digits are in a group
local group_method = 3 -- code for how many digits are in a group
local per_word = 'per' -- for units like "miles per gallon"
local plural_suffix = 's' -- only other useful value is probably '' to disable plural unit names
local plural_suffix = 's' -- only other useful value is probably '' to disable plural unit names
local from_en_table -- to translate an output string of en digits to local language
local from_en_table -- to translate an output string of en digits to local language
Line 116: Line 117:
if translation.group then
if translation.group then
group_method = translation.group
group_method = translation.group
end
if translation.per_word then
per_word = translation.per_word
end
end
if translation.plural_suffix then
if translation.plural_suffix then
Line 938: Line 942:
-- 2 + 3 / 8 2.375, '2(3/8)' -1.625, '−2(−3/8)'
-- 2 + 3 / 8 2.375, '2(3/8)' -1.625, '−2(−3/8)'
-- 2 - 3 / 8 1.625, '2(−3/8)' -2.375, '−2(3/8)'
-- 2 - 3 / 8 1.625, '2(−3/8)' -2.375, '−2(3/8)'
-- 1 + 20/8 3.5, '1/(20/8)' 1.5, '−1/(−20/8)'
-- 1 + 20/8 3.5 , '1/(20/8)' 1.5 , '−1/(−20/8)'
-- 1 - 20/8 -1.5., '1(−20/8)' -3.5, '−1(20/8)'
-- 1 - 20/8 -1.5., '1(−20/8)' -3.5 , '−1(20/8)'
-- Wherever an integer appears above, numbers like 1.25 or 12.5e-3
-- Wherever an integer appears above, numbers like 1.25 or 12.5e-3
-- (which may be negative) are also accepted (like old template).
-- (which may be negative) are also accepted (like old template).
Line 1,568: Line 1,572:
prec = prec - exponent
prec = prec - exponent
end
end
if in_current.istemperature and out_current.istemperature then
local exception = (utype == 'temperature' and not
-- Converting between common temperatures (°C, °F, °R, K); not keVT, MK.
(in_current.exception == 'temperature' or out_current.exception == 'temperature'))
if exception then
-- Kelvin value can be almost zero, or small but negative due to precision problems.
-- Kelvin value can be almost zero, or small but negative due to precision problems.
-- Also, an input value like -300 C (below absolute zero) gives negative kelvins.
-- Also, an input value like -300 C (below absolute zero) gives negative kelvins.
Line 1,970: Line 1,973:
result = '/'
result = '/'
elseif unit1 then
elseif unit1 then
result = ' per '
result = ' ' .. per_word .. ' '
else
else
result = 'per '
result = per_word .. ' '
end
end
if unit1 then
if unit1 then
Line 1,981: Line 1,984:
if multiplier then
if multiplier then
-- A multiplier (like "100" in "100km") forces the unit to be plural.
-- A multiplier (like "100" in "100km") forces the unit to be plural.
multiplier = from_en(multiplier)
if abbr_on then
if abbr_on then
multiplier = multiplier .. ' '
multiplier = multiplier .. ' '
Line 2,088: Line 2,092:
want_name = true
want_name = true
end
end
if unit_table.utype == 'temperature' or unit_table.utype == 'temperature change' then
if unit_table.usesymbol then
if not (unit_table.exception == 'temperature') then
want_name = false
want_name = false
end
end
end
end
end