[checked revision] | [checked revision] |
(Syncing content across wikis, if something seems broken as a result let me know) Â |
No edit summary  |
||
(One intermediate revision by the same user not shown) | |||
Line 2: | Line 2: | ||
local util_math = require('Module:MathUtil') |
local util_math = require('Module:MathUtil') |
||
local util_text = require('Module:TextUtil') |
local util_text = require('Module:TextUtil') |
||
− | local LOOKUP = mw.loadData('Module:Currencynames') |
||
local lang = mw.getLanguage('en') |
local lang = mw.getLanguage('en') |
||
local h = {} |
local h = {} |
||
+ | local p = require('Module:EntityAbstract'):finalExtends() |
||
+ | p.objectType = 'Currency' |
||
− | function |
+ | function p:long(amount) |
− | if |
+ | if self.is_nil or not amount then return end |
⚫ | |||
− | local data = util_args.lookupVars(currency, LOOKUP, true) |
||
⚫ | |||
− | return data |
||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
function h.padDecimal(str, places) |
function h.padDecimal(str, places) |
||
⚫ | |||
local tbl = util_text.split(str,'.',true) |
local tbl = util_text.split(str,'.',true) |
||
if tbl[2] then |
if tbl[2] then |
||
Line 26: | Line 36: | ||
end |
end |
||
return str |
return str |
||
⚫ | |||
− | |||
− | local p = {} |
||
− | function p.main(frame) |
||
− | local args = util_args.overwrite(true) |
||
− | local style = args[3] or 'short' |
||
− | return p[style](args[1], args[2], args) |
||
− | end |
||
− | |||
− | function p.singular(amount, currency, settings) |
||
− | local vars = h.getInfo(currency, settings) |
||
⚫ | |||
− | return vars.singular:format(util_math.formatNumber(amount)) |
||
− | end |
||
− | |||
− | function p.plural(amount, currency, settings) |
||
− | local vars = h.getInfo(currency, settings) |
||
⚫ | |||
⚫ | |||
− | end |
||
− | |||
− | function p.long(amount, currency, settings) |
||
− | local vars = h.getInfo(currency, settings) |
||
− | if not vars or not amount then return end |
||
⚫ | |||
⚫ | |||
− | else |
||
− | return vars.plural:format(util_math.formatNumber(amount)) |
||
⚫ | |||
− | end |
||
− | |||
⚫ | |||
− | local vars = h.getInfo(currency, settings) |
||
− | if not vars or not amount then return end |
||
⚫ | |||
− | if vars.decimals then |
||
⚫ | |||
− | else |
||
− | return unpadded |
||
− | end |
||
end |
end |
||
Latest revision as of 22:21, 8 September 2020
To edit the documentation or categories for this module, click here.
local util_args = require('Module:ArgsUtil')
local util_math = require('Module:MathUtil')
local util_text = require('Module:TextUtil')
local lang = mw.getLanguage('en')
local h = {}
local p = require('Module:EntityAbstract'):finalExtends()
p.objectType = 'Currency'
function p:long(amount)
if self.is_nil or not amount then return end
if tonumber(amount) == 1 then
return self.vars.singular:format(util_math.formatNumber(amount))
end
return self.vars.plural:format(util_math.formatNumber(amount))
end
function p:short(amount)
if self.is_nil or not amount then return end
local unpadded = self.vars.short:format(util_math.formatNumber(amount))
return h.padDecimal(unpadded, self.vars.decimals)
end
function h.padDecimal(str, places)
if not places then return str end
local tbl = util_text.split(str,'.',true)
if tbl[2] then
local zeroes = {}
local i = #tbl[2]
while i < places do
zeroes[#zeroes+1] = 0
i = i + 1
end
tbl[2] = tbl[2] .. table.concat(zeroes,'')
return table.concat(tbl,'.')
end
return str
end
return p