-- This module implements
local p =
local function clean_weight(s)
s = mw.ustring.gsub(s, 'kilogram', 'kg') s = mw.ustring.gsub(s, 'kgs', 'kg') s = mw.ustring.gsub(s, 'kg[%.,]', 'kg')
s = mw.ustring.gsub(s, 'pound', 'lb') s = mw.ustring.gsub(s, 'lbs', 'lb') s = mw.ustring.gsub(s, 'lb[%.,]', 'lb')
s = mw.ustring.gsub(s, 'stone', 'st') s = mw.ustring.gsub(s, 'sts', 'st') s = mw.ustring.gsub(s, 'st[%.,]', 'st')
s = mw.ustring.gsub(s, '%[%[kg%]%]s', 'kg')
return send
local function isnumber(s) if s then s = mw.ustring.gsub(s, '%+%s*%d+%s*/%s*%d+%s*$', ) s = mw.ustring.gsub(s, '%s*[–%-]%s*', ) return tonumber(s) end return nilend
local function get_convert_weight_args(s, kg_stlb, lb_stlb) local prefer_m = (prefer or )
'm' local prefer_cm = (prefer or )
'cm' unconverted = clean_weight(s or ) -- basic unit cleaning s = mw.ustring.gsub(unconverted, '&[Nn][Bb][Ss][Pp];', ' ') local kg = mw.ustring.find(s, 'kg') local st = mw.ustring.find(s, 'st') local lb = mw.ustring.find(s, 'lb') if kg
nil and lb
nil and lb
nil and st
nil and lb
if lb ~= nil and st ~=nil and kg
function convert_weight(frame, args) local targs, str = get_convert_weight_args(args[1], (args['kg-stlb'] or ) ~= , (args['lb-stlb'] or ) ~= )
if type(targs)
function p.weight(frame) return convert_weight(frame, frame.args[1] and frame.args or frame:getParent.args)end
return p