Modulo:Val: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
test importazione modulo:Val da en.wiki |
|||
(21 versioni intermedie di 3 utenti non mostrate) | |||
Riga 1:
-- For Template:Val, output a number and optional unit.
-- Format options include scientific and uncertainty notations.
local numdot = ',' -- decimal mark (use ',' for Italian)
local numsep = ' ' -- group separator (use ' ' for Italian)
local mtext = {
-- Message and other text that should be localized.
['mt-bad-exponent'] = 'parametro exponent (<b>e</b>)',
['mt-parameter'] = 'parametro ',
['mt-not-number'] = 'non è un numero valido',
['mt-cannot-range'] = 'non si può usare un intervallo se il primo parametro include "e"',
['mt-need-range'] = 'nel parametro ci deve essere un intervallo valido',
['mt-should-range'] = 'dovrebbe essere un intervallo',
['mt-cannot-with-e'] = 'non può essere usato se il primo parametro include "e"',
['mt-not-range'] = 'non accetta un intervallo',
['mt-cannot-e'] = 'non può usare la notazione e',
['mt-too-many-parameter'] = 'troppi parametri',
['mt-need-number'] = 'dopo l\'ultimo numero serve un parametro perchè è un intevallo.',
['mt-ignore-parameter4'] = 'parametro 4 ignorato',
['mt-val-not-supported'] = 'Parametro "%s=%s" non supportato',
['mt-invalid-scale'] = 'L\'unità "%s" ha una scala "%s" non validata',
['mt-both-u-ul'] = 'Il parametro (<b>u</b>) e (<b>ul</b>) sono entrambi specificati, solo uno è ammesso.',
['mt-both-up-upl'] = 'Il parametro (<b>up</b>) e (<b>upl</b>) sono entrambi specificati, solo uno è ammesso..',
}
local data_module = 'Module:Val/units'
Line 14 ⟶ 36:
category = ''
else
category = '[[
end
iswarning = false -- problems are infrequent so try showing large error so editor will notice
if iswarning then
body = '<sup class="noprint Inline-Template" style="white-space:nowrap;">' ..
'[[Template:
msg:gsub('"', '"') ..
'">
else
body = '<strong class="error">' ..
'Errore in {{[[Template:
msg ..
'</strong>'
Line 31 ⟶ 53:
end
local range_types = {
-- No need for ' ' because nowrap applies to all output.
▲ -- aggiunte localizzazioni
[","] = ", ",
["by"] = " su ",
["
["
["–"] = "–",▼
["and"] = " e ",
["
["
["o"] = " o ",▼
["to"] = " to " ,▼
["fino a"] = " fino a ",▼
["x"] = " × ",
["×"] = " × ",
["/"] = "/",
---
["~"] = "~",
["÷"] = "÷",
["ai"] = " ai ",
["e"] = " e ",
["xo"] = " × ",
["−"] = "−",
["+"] = "+",
["e i"] = " e i "
}
local range_repeat_unit = {
-- WP:UNIT wants unit repeated when a "multiply" range is used.
--["x"] = true,
--["×"] = true,
}
Line 64 ⟶ 95:
-- Input like 1e3 is regarded as invalid for all except argument 1
-- which accepts e notation as an alternative to the 'e' argument.
-- Input
local which = index
local function fail(msg)
local description
if which == 'e' then
description = mtext['
else
description = mtext['
end
return description .. ' ' .. (msg or mtext['
end
local result = {}
Line 81 ⟶ 112:
if index == 2 then
if numbers[1] and numbers[1].exp then
return fail(mtext['
end
numbers.has_ranges = true
else
if not numbers.has_ranges then
return fail(mtext['
end
end
Line 96 ⟶ 127:
return nil
end
return fail(mtext['
end
if numbers.has_ranges and type(index) == 'number' and (index % 2 == 0) then
return fail(mtext['
end
if index == 'e' then
Line 105 ⟶ 136:
if e then
if arg then
return fail(mtext['
end
arg = e
Line 112 ⟶ 143:
end
if arg and arg ~= '' then
arg = arg:gsub(
if numdot ~= '.' then
arg = arg:gsub(numdot, '.')
end
if arg:sub(1, 1) == '(' and arg:sub(-1) == ')' then
result.parens = true
Line 123 ⟶ 157:
result.exp = b
else
return fail(mtext['
end
end
Line 177 ⟶ 211:
end
if index > 19 then
return mtext['mt-too
end
end
if numbers.has_ranges and (#numbers % 2 == 0) then
return mtext['mt-need-number']
end
end
Line 211 ⟶ 245:
end
end
error(string.format(mtext['mt-invalid-scale'], ucode, text))
end
Line 519 ⟶ 553:
local delimit_groups = require('Module:Gapnum').groups
local function delimit(sign, numstr, fmt)
-- Return sign and numstr (unsigned digits or
-- Four-digit integers are not formatted with gaps.
fmt = (fmt or 'gaps'):lower()
if fmt == 'none' or (fmt == '' and #numstr == 4 and numstr:match('^%d+$')) then
return sign .. numstr
Line 530 ⟶ 564:
local result
if fmt == 'commas' then
result = sign .. table.concat(ipart,
if dpart then
result = result ..
end
else
Line 541 ⟶ 575:
table.insert(groups, '<span style="margin-left:.25em;">' .. v .. '</span>')
end
-- Nota su en.wiki viene divisa anche la parte decimale del numero
if dpart then
table.insert(groups,
--for _, v in ipairs(dpart) do
-- table.insert(groups, '<span style="margin-left:.25em;">' .. v .. '</span>') --end
end
result = sign .. table.concat(groups)
Line 753 ⟶ 789:
for k, v in pairs(args) do
if type(k) == 'string' and not whitelist[k] then
local warning = string.format(mtext['
return valerror(warning, nocat, true)
end
end
if not has_ranges and args[4] then
return valerror(mtext['
end
end
Line 764 ⟶ 800:
local function main(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame, {wrappers = { 'Template:Val', 'Template:M', 'Template:MNL' }})
local nocat = args.nocategory
local numbers = {} -- table of number tables, perhaps with range text
Line 772 ⟶ 808:
end
if args.u and args.ul then
return valerror(mtext['mt-both-u-ul'], nocat)
end
if args.up and args.upl then
return valerror(mtext['
end
local values
|