Modulo:Conversione/sandbox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
Nuova sandbox |
m Bot: rimuovo no globals obsoleto |
||
(3 versioni intermedie di un altro utente non mostrate) | |||
Riga 6:
]]--
require('
local cfg = mw.loadData('Modulo:Conversione/Configurazione/sandbox')
local p = {}
Riga 19:
local function getUnit(val, targetunitdata, args)
local ret, link, space
if args.showunit
-- unità per esteso
ret = val > 1 and targetunitdata
▲ elseif args.showunit == 'true' then
▲ ret = targetunitdata[3]
end
if args.
link = targetunitdata
end
return space .. (link and '[[' .. link .. '|' .. ret .. ']]' or ret)
end
-- Ritorna il valore convertito alla unità di misura e alle opzioni specificate
function p._main(
local
val = tonumber(
-- se non è un numero ritorna la stringa non modificata
if not val then
return
end
if not args then
Riga 56:
targetunitdata = cfg.units[targetunit] or cfg.units[cfg.alias[targetunit]]
if sourceunitdata and targetunitdata then
if sourceunitdata
error('unità di misura incompatibili: ' .. sourceunitdata
end
-- nothing
elseif sourceunitdata.type == 'temperature' then
val = (val - sourceunitdata.offset) * sourceunitdata.scale
val = val / targetunitdata.scale + targetunitdata.offset
else
val = val * sourceunitdata.scale / targetunitdata.scale
end
▲ val = val * sourceunitdata[2] / targetunitdata[2]
else
cat = '[[Categoria:Pagine con unità di misura non supportata]]'
end
--
if args.rounding then
val = round(val, args.rounding)
end
-- formatnum
if targetunitdata and (args.showunit == 'true' or args.showunit == 'long') then▼
if args.formatnum then
unit = getUnit(val, targetunitdata, args)▼
val = mw.language.getContentLanguage():formatNum(val)
end
-- unità di misura
end
return val
end
|