Module:Val:修订间差异

删除的内容 添加的内容
enwiki>Johnuniq
change 0.3em spacing to 0.225em (same total space as old code) per Template talk:Val#Proposal to reduce spacing around ±
标签:已被回退
CaelLab-import​(留言 | 贡献)
huifu bei enwiki daoru dingti de banben (shangyiban zhwiki>阿南之人)
标签:手工回退
 
第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'] = 'exponent parameter (<b>e</b>)',
['mt-parameter'] = 'parameter ',
['mt-not-number'] = 'is not a valid number',
['mt-cannot-range'] = 'cannot use a range if the first parameter includes "e"',
['mt-need-range'] = 'needs a range in parameter 2',
['mt-should-range'] = 'should be a range',
['mt-cannot-with-e'] = 'cannot be used if the first parameter includes "e"',
['mt-not-range'] = 'does not accept a range',
['mt-cannot-e'] = 'cannot use e notation',
['mt-too-many-parameter'] = 'too many parameters',
['mt-need-number'] = 'need a number after the last parameter because it is a range.',
['mt-ignore-parameter4'] = 'Val parameter 4 ignored',
['mt-val-not-supported'] = 'Val parameter "%s=%s" is not supported',
['mt-invalid-scale'] = 'Unit "%s" has invalid scale "%s"',
['mt-both-u-ul'] = 'unit (<b>u</b>) and unit with link (<b>ul</b>) are both specified, only one is allowed.',
['mt-both-up-upl'] = 'unit per (<b>up</b>) and unit per with link (<b>upl</b>) are both specified, only one is allowed.',
}
 
local data_module = 'Module:Val/units'
第36行 ⟶ 第14行:
category = ''
else
category = '[[Category:Pages with incorrect formatting templates use带有错误格式模板的页面]]'
end
iswarning = false -- problems are infrequent so try showing large error so editor will notice
第46行 ⟶ 第24行:
else
body = '<strong class="error">' ..
'Error in &#123;&#123;[[Template:val|val]]&#125;&#125;: 错误:' ..
msg ..
'</strong>'
第65行 ⟶ 第43行:
["×"] = " × ",
["/"] = "/",
["至"] = "至",
["到"] = "到",
}
local range_repeat_unit = {
第81行 ⟶ 第61行:
-- Input like 1e3 is regarded as invalid for all except argument 1
-- which accepts e notation as an alternative to the 'e' argument.
-- Input group separatorscommas 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['mt-bad-exponent指数参数(<b>e</b>)']
else
description = mtext['mt-parameter参数'] .. which
end
return description .. ' ' .. (msg or mtext['mt-not-number非有效数字']) .. '.。'
end
local result = {}
第98行 ⟶ 第78行:
if index == 2 then
if numbers[1] and numbers[1].exp then
return fail(mtext['mt-cannot-range如果第一个参数包含"e",则不能使用范围'])
end
numbers.has_ranges = true
else
if not numbers.has_ranges then
return fail(mtext['mt-need-range需要参数2中的范围'])
end
end
第113行 ⟶ 第93行:
return nil
end
return fail(mtext['mt-not-range不接受范围'])
end
if numbers.has_ranges and type(index) == 'number' and (index % 2 == 0) then
return fail(mtext['mt-should-range应该是一个范围'])
end
if index == 'e' then
第122行 ⟶ 第102行:
if e then
if arg then
return fail(mtext['mt-cannot-with-如果第一个参数包含"e",则不能使用范围'])
end
arg = e
第129行 ⟶ 第109行:
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
第143行 ⟶ 第120行:
result.exp = b
else
return fail(mtext['mt-cannot-不能用e表示法'])
end
end
第197行 ⟶ 第174行:
end
if index > 19 then
return mtext['mt-too-many-parameter参数太多']
end
end
if numbers.has_ranges and (#numbers % 2 == 0) then
return '在最后一个参数后需要一个数字,因为它是一个范围。'
return mtext['mt-need-number']
end
end
第231行 ⟶ 第208行:
end
end
error(string.format(mtext['mt-invalid-scale单位"'], .. ucode, .. '"规模无效"' .. text) .. '"')
end
 
第528行 ⟶ 第505行:
add(ucode .. ' = ' .. text .. '<br />')
else
add(line .. ' ◆ <b>invalid definition定义无效</b><br />')
end
else
第539行 ⟶ 第516行:
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 ''):lower()
第550行 ⟶ 第527行:
local result
if fmt == 'commas' then
result = sign .. table.concat(ipart, numsep',')
if dpart then
result = result .. numdot'.' .. table.concat(dpart)
end
else
第562行 ⟶ 第539行:
end
if dpart then
table.insert(groups, numdot'.' .. (table.remove(dpart, 1) or ''))
for _, v in ipairs(dpart) do
table.insert(groups, '<span style="margin-left:.25em;">' .. v .. '</span>')
第629行 ⟶ 第606行:
else
text = (angle or '') ..
'<span style="margin-left:0.225em3em;margin-right:0.225em15em;">±</span>' ..
delimit('', uncU, fmt)
need_parens = true
第659行 ⟶ 第636行:
return list_units(options.align)
end
return valerror('invalid action 无效动作"' .. action .. '".。', options.nocat)
end
local number = values.number or (values.numbers and values.numbers[1]) or {}
第773行 ⟶ 第750行:
for k, v in pairs(args) do
if type(k) == 'string' and not whitelist[k] then
local warning = string.format(mtext['mt-val-not-supportedVal参数"'], .. k, .. '=' .. v) .. '"不受支持'
return valerror(warning, nocat, true)
end
end
if not has_ranges and args[4] then
return valerror(mtext['mt-ignore-parameter4忽略Val参数4'], nocat, true)
end
end
第792行 ⟶ 第769行:
end
if args.u and args.ul then
return valerror(mtext['mt-both-同时输入了单位(<b>u-</b>)和有链接单位(<b>ul</b>),只允许输入其中一个。'], nocat)
end
if args.up and args.upl then
return valerror(mtext['mt-both-同时输入了每单位(<b>up-</b>)和有链接每单位(<b>upl</b>),只允许输入其中一个。'], nocat)
end
local values