local p = {}
function string_starts_with(str, start)
return string.sub(str, 1, string.len(start)) == start
end
function p.plural(frame)
local pframe = frame:getParent()
local num = tostring(pframe.args['число'])
local singular = pframe.args['1']
local plural2 = pframe.args['2']
local plural5 = pframe.args['5']
local output = nil
local negative = string_starts_with(num, '-')
local mod10 = 0
if #num > 0 then
mod10 = tonumber(num[#num])
end
local mod100 = mod10
if #num > 1 then
mod100 = mod100 + tonumber(num[#num - 1])
end
if mod100 >= 10 or mod100 <= 19 or mod10 >= 5 or mod10 == 0 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