local p = {} local getArgs = require('module:arguments').getArgs function main(args) local rb = args[1] local rt = args[2] local rt2 = args[3] local newrb = '' local newrt = '' if rt then local lrb = mw.ustring.len(rb) local lrt = mw.ustring.len(rt) local diff = lrt * 0.75 - lrb local space = '' local important = rt2 and '!important' or '' if diff > 0 then space = tostring(math.floor(diff / (lrb + 1) * 1000) / 1000)..'em' newrb = '<span style="margin-left:'..space..important..';letter-spacing:'..space..important..'">'..rb..'</span>' newrt = rt else space = tostring(math.floor(-diff / (lrt + 1) / 0.75 * 1000) / 1000)..'em' newrb = rb newrt = '<span style="margin-left:'..space..';letter-spacing:'..space..'">'..rt..'</span>' end else newrb = rb newrt = '<span class="photrans-s">'..rb..'</span>' end return newrb, newrt, rt2 end function p.one(frame) local args = getArgs(frame) local rb = args[1] or '' local rt = args[2] or ' ' return '<ruby><rb>'..rb..'</rb><rt'..(args[2] and '>' or ' class="photrans-s">').. (args.on and rt or '<span>'..rt..'</span>')..'</rt></ruby>' end function p.multi(frame) local args = getArgs(frame) local fullrb = '' local fullrt = '' local flag = false local fullrt2 = '<span class="photrans-off">' for k, v in ipairs(args) do local eachArg = mw.text.split(v, '_') if args.on then eachArg[3] = true end local newrb, newrt, rt2 = main(eachArg) fullrb = fullrb..newrb fullrt = fullrt..newrt flag = flag or rt2 fullrt2 = fullrt2..(rt2 and newrt or '<span class="photrans-s">'..eachArg[1]..'</span>') end fullrt2 = fullrt2..'</span>' return '<ruby><rb>'..fullrb..'</rb><rt><span>'..fullrt..'</span>'..(flag and fullrt2 or '')..'</rt></ruby>' end return p