Module:Convert: Difference between revisions

Content deleted Content added
more bizarre rules for when a unit is singular/plural
propagate sp=us into the unit as a field; handle optional default for an alias
Line 211:
-- Return true, t where t is a copy of the unit's converter table,
-- or return false, t where t is an error message table.
-- Parameter 'sp' is nil, or is 'us' for US spelling of SI prefixes, or nil.and
-- the symbol and names of the unit. If 'us', the result includes field
-- sp_us = true (that field may also have been in the unit definition).
-- Parameter 'what' determines whether combination units are accepted:
-- 'no_combination' : single unit only
Line 231 ⟶ 233:
if t.shouldbe then
return false, { 'cvt_should_be', t.shouldbe }
end
local force_sp_us = (sp == 'us')
if t.sp_us then
localforce_sp_us success= true
sp = 'us'
end
local target = t.target -- nil, or unitcode is an alias for this target
if target then
local force_sp_ussuccess, result = t.sp_uslookup(target, sp, what)
local success, result = lookup(target, sp or (force_sp_us and 'us'), what)
if not success then return false, result end
result.sp_usif =t.default force_sp_usthen
result.default = t.default
end
return true, result
end
Line 248 ⟶ 256:
-- Recursively create a combination table containing the
-- converter table of each unitcode.
local success
local comboresult = { utype = t.utype, multiple = multiple, combination = {} }
local cvt = comboresult.combination
for i, v in ipairs(combo) do
local success, cvt[i]t = lookup(v, sp, multiple and 'no_combination' or 'only_multiple')
if not success then return false, cvt[i]t end
cvt[i] = t
end
return true, comboresult
end
local result = shallow_copy(t)
result.sp_us = force_sp_us
if result.prefixes then
result.symbol = result._symbol
Line 275 ⟶ 284:
if t and t.prefixes then
local result = shallow_copy(t)
if (sp == 'us' or t.sp_us) and si.name_us then
result.sp_us = true
end
if result.sp_us and si.name_us then
result.si_name = si.name_us
else
Line 1,124 ⟶ 1,136:
local key_name = (singular and not parms.is_range_x) and 'name1' or 'name2'
local key_symbol = 'symbol'
if parms.sp == 'us' or unit_table.sp_us then
key_name = key_name .. '_us'
key_symbol = 'sym_us'