Modulo:Val: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
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 = '[[CategoriaCategory:Errori di compilazione del template ValM]]' -- localizzazione
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:ValM|<span title="' ..
msg:gsub('"', '&quot;') ..
'">avvisowarning</span>]]</sup>' --localizzazione
else
body = '<strong class="error">' ..
'Errore in &#123;&#123;[[Template:valM|valM]]&#125;&#125;: ' .. --localizzazione
msg ..
'</strong>'
Line 31 ⟶ 53:
end
 
-- aggiunte localizzazioni
local range_types = {
-- No need for '&nbsp;' because nowrap applies to all output.
-- aggiunte localizzazioni
[","] = ", ",
["by"] = " su ",
["su-"] = " su= "-",
["-"] = "-",
["–"] = "–",
["and"] = " e ",
["eor"] = " eo " ,
["orto"] = " orfino a " ,
["o"] = " o ",
["to"] = " to " ,
["fino a"] = " fino a ",
["x"] = " × ",
["×"] = " × ",
["/"] = "/",
---
["~"] = "~",
["÷"] = "÷",
["toa"] = " toa " ,
["ai"] = " ai ",
["su"] = " su ",
["e"] = " e ",
["o"] = " o " ,
["fino a"] = " fino a " ,
["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 commasgroup separators are removed so 1,234 is the same as 1234.
local which = index
local function fail(msg)
local description
if which == 'e' then
description = mtext['il paramentro esponente (<b>e</b>)' mt-bad-localizzazioneexponent']
else
description = mtext['il parametro mt-parameter'] .. which
end
return description .. ' ' .. (msg or mtext['non è un numero validomt-not-number']) .. '.' --localizzazione
end
local result = {}
Line 81 ⟶ 112:
if index == 2 then
if numbers[1] and numbers[1].exp then
return fail(mtext['non si può usare un intervallo se il primo parametro include "e"mt-cannot-range'])
end
numbers.has_ranges = true
else
if not numbers.has_ranges then
return fail(mtext['serve un intervallo nel secondo parametromt-need-range'])
end
end
Line 96 ⟶ 127:
return nil
end
return fail(mtext['non accetta un intervallo') mt-not-localizzazionerange'])
end
if numbers.has_ranges and type(index) == 'number' and (index % 2 == 0) then
return fail(mtext['dovrebbe essere un intervallo') mt-should-localizzazionerange'])
end
if index == 'e' then
Line 105 ⟶ 136:
if e then
if arg then
return fail(mtext['non può essere usato se il primo parametro include "mt-cannot-with-e"']) --localizzazione
end
arg = e
Line 112 ⟶ 143:
end
if arg and arg ~= '' then
arg = arg:gsub(','numsep, '')
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['non può usare la notazione mt-cannot-e']) --localizzazione
end
end
Line 177 ⟶ 211:
end
if index > 19 then
return mtext['mt-too -many parameters-parameter']
end
end
if numbers.has_ranges and (#numbers % 2 == 0) then
return mtext['mt-need-number']
return 'dato che è un intervallo serve un numero dopo l\'ultimo parametro.' --localizzazione
end
end
Line 211 ⟶ 245:
end
end
error(string.format(mtext['mt-invalid-scale'], ucode, text))
error('Unit "' .. ucode .. '" ha una scala non valida "' .. text .. '"') --localizzazione
end
 
Line 519 ⟶ 553:
local delimit_groups = require('Module:Gapnum').groups
local function delimit(sign, numstr, fmt)
-- Return sign and numstr (unsigned digits or '.'numdot only) after formatting.
-- 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, ','numsep)
if dpart then
result = result .. '.'numdot .. table.concat(dpart)
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, '.'numdot .. (table.removeconcat(dpart, 1) or ''))
for _--table.insert(groups, vnumdot in.. ipairs(table.remove(dpart, 1) door ''))
--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['Parametro Val "mt-val-not-supported' ..], k .. '=' .., v .. '" non supportato' -- localizzazione)
return valerror(warning, nocat, true)
end
end
if not has_ranges and args[4] then
return valerror(mtext['Quarto parametro di Val ignoratomt-ignore-parameter4'], nocat, true) --localizzazione
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)
return valerror('Specificata sia unità (<b>u</b>) e unità con collegamento (<b>ul</b>).Solo una delle due è accettata.', nocat) --localizzazione
end
if args.up and args.upl then
return valerror(mtext['Specificata unità (<b>mt-both-up</b>) e "unità per" con collegamento (<b>-upl</b>). Solo una delle due è accettata.'], nocat) --localizzazione
end
local values