Module:Formatnum
Jump to navigation
Jump to search
--
-- Module for Interslavic number formatting
-- This module can be replaced by {{formatnum:}} declaration when Interslavic MediaWiki localisation will be created.
-- Source: https://sites.google.com/site/neoslavonictutorial/lessons/9
--
local p = {}
-- For usage in other modules
function p._formatnum(num)
if num == nil or num == '' then
return num
end
local withoutMarkers, commaCount = mw.text.unstrip(num):gsub(',', '.')
local formatted = tonumber(withoutMarkers)
if formatted == nil or commaCount > 1 then
local errorCategory = mw.message.new('nonnumeric-formatnum'):plain()
return num .. '[[Category:' .. errorCategory .. ']]'
end
local lang = mw.getContentLanguage()
formatted = mw.ustring.gsub(lang:formatNum(formatted), '%,', ' '):gsub('%.', ',')
formatted = mw.ustring.gsub(num, withoutMarkers, formatted)
return formatted
end
-- For usage in templates
function p.formatnum(frame)
local args = frame.args
local num = args[1]
if num == nil or num == '' then
return
end
return p._formatnum(num)
end
return p