Permanently protected module

모듈:변환

Module:Convert

-- Convert a value from one unit of measurement to another. -- Example: {{convert 123 lb kg}} --> 123 pounds (56 kg) -- See [[:en:Template:Convert/Transwiki guide]] if copying to another wiki.  local MINUS = '−'  -- Unicode U+2212 MINUS SIGN (UTF-8: e2 88 92) local abs = math.abs local floor = math.floor local format = string.format local log10 = math.log10 local ustring = mw.ustring local ulen = ustring.len local usub = ustring.sub  -- Configuration options to keep magic values in one location. -- Conversion data and message text are defined in separate modules. local config, maxsigfig local numdot  -- must be '.' or ',' or a character which works in a regex local numsep, numsep_remove, numsep_remove2 local data_code, all_units local text_code local varname        -- can be a code to use variable names that depend on value local from_en_table  -- to translate an output string of en digits to local language local to_en_table    -- to translate an input string of digits in local language to en -- Use translation_table in convert/text to change the following. local en_default           -- true uses lang=en unless convert has lang=local or local digits local group_method = 3     -- code for how many digits are in a group local per_word = 'per'     -- for units like "liters per kilometer" local plural_suffix = 's'  -- only other useful value is probably '' to disable plural unit names local omitsep              -- true to omit separator before local symbol/name  -- All units should be defined in the data module. However, to cater for quick changes -- and experiments, any unknown unit is looked up in an extra data module, if it exists. -- That module would be transcluded in only a small number of pages, so there should be -- little server overhead from making changes, and changes should propagate quickly. local extra_module  -- name of module with extra units local extra_units   -- nil or table of extra units from extra_module  -- Some options in the invoking template can set variables used later in the module. local currency_text  -- for a user-defined currency symbol: {{convert 12 $/ha $=€}} (euro replaces dollar)  local function from_en(text)  -- Input is a string representing a number in en digits with '.' decimal mark,  -- without digit grouping (which is done just after calling this).  -- Return the translation of the string with numdot and digits in local language.  if numdot ~= '.' then   text = text:gsub('%.', numdot)  end  if from_en_table then   text = text:gsub('%d', from_en_table)  end  return text end  local function to_en(text)  -- Input is a string representing a number in the local language with  -- an optional numdot decimal mark and numsep digit grouping.  -- Return the translation of the string with '.' mark and en digits,  -- and no separators (they have to be removed here to handle cases like  -- numsep = '.' and numdot = ',' with input "1.234.567,8").  if to_en_table then   text = ustring.gsub(text, '%d', to_en_table)  end  if numsep_remove then   text = text:gsub(numsep_remove, '')  end  if numsep_remove2 then   text = text:gsub(numsep_remove2, '')  end  if numdot ~= '.' then   text = text:gsub(numdot, '.')  end  return text end  local function decimal_mark(text)  -- Return ',' if text probably is using comma for decimal mark, or has no decimal mark.  -- Return '.' if text probably is using dot for decimal mark.  -- Otherwise return nothing (decimal mark not known).  if not text:find('[.,]') then return ',' end  text = text:gsub('^%-', ''):gsub('%+%d+/%d+
                
, ''):gsub('[Ee]%-?%d+