local p = {}
local function is_set (var)
return not (var == nil or var == '');
end
function p.plural(frame)
local pframe = frame:getParent()
local num = nil
local singular = nil
local plural2 = nil
local plural5 = nil
if is_set(pframe.args['3']) then
num = tostring(pframe.args['1'])
singular = pframe.args['2']
plural2 = pframe.args['3']
plural5 = pframe.args['4']
else
num = tostring(pframe.args['число'])
singular = pframe.args['1']
plural2 = pframe.args['2']
plural5 = pframe.args['5']
end
local output = nil
local contains_decimal_point = string.find(num, ',') ~= nil or string.find(num, '.') ~= nil
local mod10 = 0
if #num > 0 then
mod10 = tonumber(string.sub(num, #num, #num))
end
local mod100 = mod10
if #num > 1 then
mod100 = mod100 + tonumber(string.sub(num, #num - 1, #num - 1))
end
if (mod100 >= 10 and mod100 <= 19) or mod10 >= 5 or mod10 == 0 or contains_decimal_point then
output = plural5
elseif mod10 == 1 then
output = singular
elseif mod10 >= 2 or mod10 <= 4 then
output = plural2
end
return num .. ' ' .. output
end
return p