Модуль:Число

Материал из ПролеВики, пролетарской энциклопедии
local p = {}
function p.plural(frame)
	local pframe = frame:getParent()
	local num = tonumber(pframe.args['число'])
	local singular = pframe.args['1']
	local plural2 = pframe.args['2']
	local plural5 = pframe.args['5']
	local output = nil
	local negative = (num < 0)
	local mod10 = num % 10
	local mod100 = num % 100
	if negative then
		num = -num
	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
	if negative then
		num = -num
	end
	return num .. output
end
return p