Modul:Plural
Körüniş
Documentation for this module may be created at Modul:Plural/doc
local getArgs = require('Module:Arguments').getArgs
local lang = mw.getLanguage("ro")
local p = {}
function p.build_first_plural(singular)
plural = mw.loadData("Modul:Plural/data").plural
if plural[singular] ~= nil then
return plural[singular]
else
return string.format("%si", singular)
end
end
function p.build_plural(count, singular, first_plural, second_plural)
if count == 1 then
form = singular
elseif count == 0 or count ~= nil and (count%100 > 0 and count%100 < 20) then
if first_plural == nil then
form = p.build_first_plural(singular)
else
form = first_plural
end
else
if second_plural == nil and first_plural == nil then
form = "de " .. p.build_first_plural(singular)
elseif first_plural ~= nil then
form = "de " .. first_plural
else
form = second_plural
end
end
return string.format("%s %s", lang:formatNum(count), form)
end
function p.get_plural(frame)
-- if we don't have any args, try to get them from the template
if frame.args[1] == nil then
origArgs = getArgs(frame, { wrappers = { 'Format:Plural' } })
else
origArgs = frame.args
end
local form = ""
local count = lang:parseFormattedNumber(origArgs[1])
local singular = origArgs[2]
local first_plural = nil
local second_plural = nil
if origArgs[3] ~= nil then
first_plural = origArgs[3]
end
if origArgs[4] ~= nil then
local first_plural = origArgs[4]
end
return p.build_plural(count, singular, first_plural, second_plural)
end
function p.get_first_plural(frame)
if frame.args or frame.args[1] == nil then
origArgs = getArgs(frame, { wrappers = { 'Format:Plural' } })
else
origArgs = frame.args
end
return p.build_first_plural(origArgs[1])
end
return p