মডিউল:Convert: সংশোধিত সংস্করণের মধ্যে পার্থক্য
বিষয়বস্তু বিয়োগ হয়েছে বিষয়বস্তু যোগ হয়েছে
current version from en:Module:Convert (no visible difference here) |
update from en:Module:Convert |
||
২০ নং লাইন:
-- Configuration options to keep magic values in one location.
-- The conversion data and message text are defined in separate modules.
local numdot, numsep -- each must be a single byte for simple regex search/replace
local maxsigfig, warnings
local default_exceptions, link_exceptions,
local SIprefixes, all_categories, all_messages, customary_units, disp_joins
local en_option_value, eng_scales, local_option_name, range_aliases, range_types
৩১ ⟶ ২৯ নং লাইন:
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
-- 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
local function boolean(text)
৮৭ ⟶ ৯২ নং লাইন:
local data_module, text_module, data_code, text_code
if is_test_run then
text_module = "converttext-" .. langcode
extra_module = "convertextra"
spell_module = "ConvertNumeric"
else
data_module = "Module:Convert/data"
text_module = "Module:Convert/text"
extra_module = "Module:Convert/extra"
spell_module = "Module:ConvertNumeric"
end
if args.use_require then▼
else▼
▲ data_code = mw.loadData(data_module)
end▼
default_exceptions = data_code.default_exceptions
link_exceptions = data_code.link_exceptions
SIprefixes = text_code.SIprefixes
all_categories = text_code.all_categories
১১৫ ⟶ ১১৮ নং লাইন:
range_aliases = text_code.range_aliases
range_types = text_code.range_types
▲ local lang = mw.language.getContentLanguage()
▲ local translation = text_code.translation_table[lang.code]
if translation then
if translation.group then
৪০৮ ⟶ ৪০৭ নং লাইন:
}
local function lookup(unitcode, opt_sp_us, what, utable, fails, depth)
-- Return true, t where t is a copy of the unit's converter table,
-- or return false, t where t is an error message table.
৪২৫ ⟶ ৪২৪ নং লাইন:
-- For compatibility with the old template, underscores in unitcode are replaced
-- with spaces so {{convert|350|board_feet}} --> 350 board feet (0.83 m³).
utable = utable or all_units
fails = fails or {}
depth = depth and depth + 1 or 1
-- There are ways to mistakenly define units which result in infinite
-- recursion when lookup() is called. That gives a long delay and very
-- confusing error messages, so the depth parameter is used as a guard.
return false, { 'cvt_lookup', unitcode }
if unitcode == nil or unitcode == '' then
return false, { 'cvt_no_unit' }
end
unitcode = unitcode:gsub('_', ' ')
local t =
if t then
if t.shouldbe then
৪৪১ ⟶ ৪৪৯ নং লাইন:
local target = t.target -- nil, or unitcode is an alias for this target
if target then
local success, result = lookup(target, opt_sp_us, what, utable, fails, depth)
if not success then return false, result end
override_from(result, t, { 'customary', 'default', 'link', 'symbol', 'symlink' })
৪৬২ ⟶ ৪৭০ নং লাইন:
prefix = v
else
local success, t = lookup(v, opt_sp_us, 'no_combination', utable, fails, depth)
if not success then return false, t end
cvt[i] = t
৪৮৯ ⟶ ৪৯৭ নং লাইন:
local cvt = result.combination
for i, v in ipairs(combo) do
local success, t = lookup(v, opt_sp_us, multiple and 'no_combination' or 'only_multiple', utable, fails, depth)
if not success then return false, t end
cvt[i] = t
৫০৪ ⟶ ৫১২ নং লাইন:
return true, setmetatable(result, unit_mt)
end
for plen = SIprefixes[1] or 2, 1, -1 do
-- Look for an SI prefix; should never occur with an alias.
-- Check for longer prefix first ('dam' is decametre).
-- SIprefixes[1] = prefix maximum #characters (as seen by mw.ustring.sub).
local prefix = usub(unitcode, 1, plen)
local si = SIprefixes[prefix]
if si then
local t =
if t and t.prefixes then
local result = shallow_copy(t)
৫৩৬ ⟶ ৫৪৫ নং লাইন:
local engscale = eng_scales[exponent]
if engscale then
local success, result = lookup(baseunit, opt_sp_us, 'no_combination', utable, fails, depth)
if not success then return false, result end
if not (result.offset or result.builtin or result.engscale) then
৫৪২ ⟶ ৫৫১ নং লাইন:
result.engscale = engscale
result.scale = result.scale * 10 ^ tonumber(exponent)
end▼
end
▲ end
if not extra_units then
local success, extra = pcall(function () return require(extra_module).extra_units end)
if success and type(extra) == 'table' then
end
end
if extra_units then
-- A unit in one data table might refer to a unit in the other table, so
-- switch between them, relying on fails or depth to terminate loops.
local failed = fails[unitcode]
if not failed then
fails[unitcode] = true
local other = (utable == all_units) and extra_units or all_units
local success, result = lookup(unitcode, opt_sp_us, what, other, fails, depth)
if success then
return true, result
end
১,৬৬৮ ⟶ ১,৬৯৬ নং লাইন:
if out_current.builtin == 'hand' then
-- Convert to hands, then convert the fractional part to inches.
--
-- precision if the output uses scientific notation (very large, or very
-- small). Not worth more complexity as these cases should be very rare.
local dummy_unit_table = { scale = out_current.scale }
local success, outinfo = cvtround(parms, info, in_current, dummy_unit_table)
if not success then return false, outinfo end
local fmt
local fraction = (outinfo.show):match('[' .. numdot .. '](.*)') or '' -- outinfo.show is in local language▼
▲ if not outinfo.use_default_precision then
▲ return true, outinfo
▲ end
▲ fmt = '%.0f'
else
if fraction == '' then
if not outinfo.use_default_precision then
return true, outinfo
end
fmt = '%.0f'
else
fmt = '%.' .. format('%d', ulen(fraction) - 1) .. 'f'
end
end
local hands, inches = math.modf(outinfo.raw_absvalue)
২,৪০১ ⟶ ২,৪৩৫ নং লাইন:
end
local function make_result(info)
local
local results = {}
for i = 1, #combos do
local thisvalue, strforce
local out_current = combos[i]
out_current.inout = 'out'
local scale = multiple[i]
if i == 1 then -- least significant unit ('in' from 'ftin')
local fraction
local success, outinfo = cvtround(parms, info, in_unit_table, out_current)
if not success then return false, outinfo end
sign = outinfo.sign
strforce = outinfo.show
fraction = ''
else
▲
end
fmt = '%.' .. ulen(fraction) .. 'f' -- to reproduce precision
if fraction == '' then
২,৪৩৭ ⟶ ২,৪৭৭ নং লাইন:
end
end
local strval
if strforce and outvalue == 0 then
sign = '' -- any sign is in strforce
strval = strforce -- show small values in scientific notation; will only use least significant unit
else
strval = (thisvalue == 0) and from_en('0') or with_separator(parms, format(fmt, thisvalue))
end
table.insert(results, strval .. sep1 .. id)
if outvalue == 0 then
|