Module:Convert/text: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
(add sortable=on, sp=us, customary_units; tweak)
("invalid option" is better than "unknown option" as it can be more than "unknown"; rework links in eng_scales)
Line 16: Line 16:
-- Some units can be qualified with one of the following prefixes, when linked.
-- Some units can be qualified with one of the following prefixes, when linked.
local customary_units = {
local customary_units = {
'[[United States customary units|US]] ',
{ "US", link = "United States customary units" },
'[[United States customary units|U.S.]] ',
{ "U.S.", link = "United States customary units" },
'[[Imperial unit|imperial]] ',
{ "imperial", link = "Imperial unit" },
'[[Imperial unit|imp]] ',
{ "imp", link = "Imperial unit" },
}
}


-- Names when using engineering notation (a prefix of "eN" where N is a number).
-- Names when using engineering notation (a prefix of "eN" where N is a number).
-- key = { "name", "linked name, if link wanted", exponent = key }
-- key = { "name", link = "article title", exponent = key }
-- If lk=on and link is defined, the name of the number will appear as a link.
local eng_scales = {
local eng_scales = {
["3"] = { "thousand", exponent = 3 },
["3"] = { "thousand", exponent = 3 },
["6"] = { "million", exponent = 6 },
["6"] = { "million", exponent = 6 },
["9"] = { "billion", "[[1000000000 (number)|billion]]", exponent = 9 },
["9"] = { "billion", link = "1000000000 (number)", exponent = 9 },
["12"] = { "trillion", "[[1000000000000 (number)|trillion]]", exponent = 12 },
["12"] = { "trillion", link = "1000000000000 (number)", exponent = 12 },
["15"] = { "quadrillion", "[[1000000000000000 (number)|quadrillion]]", exponent = 15 },
["15"] = { "quadrillion", link = "1000000000000000 (number)", exponent = 15 },
}
}


-- When appropriate, the following categories can be included in the output.
-- When appropriate, the following categories can be included in the output.
local all_categories = {
local all_categories = {
general = '[[Category:Convert error]]',
general = "[[Category:Convert error]]",
mismatch = '[[Category:Convert dimension mismatch]]',
mismatch = "[[Category:Convert dimension mismatch]]",
option = '[[Category:Convert unknown option]]',
option = "[[Category:Convert invalid option]]",
unknown = '[[Category:Convert unknown unit]]',
unknown = "[[Category:Convert unknown unit]]",
}
}


Line 71: Line 72:
cvt_no_num2 = { 'Need second value', 'general' },
cvt_no_num2 = { 'Need second value', 'general' },
cvt_no_unit = { 'Need name of unit', 'unknown' },
cvt_no_unit = { 'Need name of unit', 'unknown' },
cvt_unknown_option = { 'Ignored unknown option "%s"', 'option', warning = true },
cvt_unknown_option = { 'Ignored invalid option "%s"', 'option', warning = true },
cvt_should_be = { '%s', 'general', regex = unitcode_regex, replace = unitcode_replace },
cvt_should_be = { '%s', 'general', regex = unitcode_regex, replace = unitcode_replace },
cvt_sigfig_pos = { 'sigfig "%s" must be positive', 'general' },
cvt_sigfig_pos = { 'sigfig "%s" must be positive', 'general' },
Line 79: Line 80:
-- Text to join input value/unit with output value/unit.
-- Text to join input value/unit with output value/unit.
local disp_joins = {
local disp_joins = {
['or'] = { ' or ' , '' },
["or"] = { " or " , "" },
['sqbr-sp'] = { ' [' , ']' },
["sqbr-sp"] = { " [" , "]" },
['sqbr-nbsp'] = { ' [' , ']' },
["sqbr-nbsp"] = { " [" , "]" },
['comma'] = { ', ' , '' },
["comma"] = { ", " , "" },
['slash-sp'] = { ' / ' , '' },
["slash-sp"] = { " / " , "" },
['slash-nbsp'] = { ' / ', '' },
["slash-nbsp"] = { " / ", "" },
['slash-nosp'] = { '/' , '' },
["slash-nosp"] = { "/" , "" },
['b'] = { ' (' , ')' },
["b"] = { " (" , ")" },
['br'] = { '<br/>' , '' },
["br"] = { "<br/>" , "" },
}
}


-- Text to separate values in a range.
-- Text to separate values in a range.
local range_types = {
local range_types = {
['by'] = ' by ',
["by"] = " by ",
['-'] = '',
["-"] = "",
['to about'] = ' to about ',
["to about"] = " to about ",
['and'] = { ['off'] = ' and ', ['on'] = ' and ', exception = true },
["and"] = { ["off"] = " and ", ["on"] = " and ", exception = true },
['or'] = { ['off'] = ' or ' , ['on'] = ' or ' , exception = true },
["or"] = { ["off"] = " or " , ["on"] = " or " , exception = true },
['to'] = { ['off'] = ' to ' , ['on'] = ' to ' , exception = true },
["to"] = { ["off"] = " to " , ["on"] = " to " , exception = true },
['xx'] = '&nbsp;×&nbsp;',
["xx"] = "&nbsp;×&nbsp;",
['to(-)'] = { ['off'] = '&nbsp;to ', ['on'] = '' },
["to(-)"] = { ["off"] = "&nbsp;to ", ["on"] = "" },
['+/-'] = { ['off'] = '&nbsp;±&nbsp;', ['on'] = '&nbsp;±&nbsp;', ['adj'] = '&nbsp;±&nbsp;' },
["+/-"] = { ["off"] = "&nbsp;±&nbsp;", ["on"] = "&nbsp;±&nbsp;", ["adj"] = "&nbsp;±&nbsp;" },
['x'] = { ['off'] = ' by ', ['on'] = ' ×&nbsp;', is_range_x = true },
["x"] = { ["off"] = " by ", ["on"] = " ×&nbsp;", is_range_x = true },
}
}


local range_aliases = {
local range_aliases = {
['and(-)'] = 'and',
["and(-)"] = "and",
['&'] = 'and',
["&"] = "and",
[''] = '-',
[""] = "-",
['&ndash;'] = '-',
["&ndash;"] = "-",
['to-'] = 'to(-)',
["to-"] = "to(-)",
['×'] = 'x',
["×"] = "x",
['±'] = '+/-',
["±"] = "+/-",
}
}