Module:KwantitàNom
Documentation for this module may be created at Module:KwantitàNom/doc
f = {}
-- Dan il-metodu jirritorna l-għadd ta' oġġetti bil-Malti magħdud man-nom (il-metodu ma japplikax għal oġġetti/nomi li jużaw il-plural miksur). Il-parametri huma:
-- number: kwantità ta' oġġetti
-- singular: il-verżjoni bis-singular tal-oġġett/nom
-- plural: il-verżjoni bil-plural tal-oġġett/nom
-- formatNumber: għażla jekk tridx tirranġa n-numru bil-virgoli jew mingħajrhom
local function getNounCount(number, singular, plural, formatNumber)
formattedNumber = formatNumber and mw.getContentLanguage():formatNum(number) or number
flooredNearestHundred = math.floor(number / 100) * 100
difference = number - flooredNearestHundred
if number == 0 then return formattedNumber .. ' ' .. plural end
if difference >= 2 and difference <= 10 then
return formattedNumber .. ' ' .. plural
elseif difference <= 1 or difference >= 11 then
if difference >= 11 and difference <= 19 then
return formattedNumber .. '-il ' .. singular
else return formattedNumber .. ' ' .. singular
end
end
end
function f.kwantitaNom(frame)
local number = tonumber(frame.args.number)
local singular = frame.args.singular
local plural = frame.args.plural
local formatNumber = frame.args.formatNumber
return getNounCount(number, singular, plural, formatNumber)
end
-- Dan il-metodu jirritorna n-numru ta' artikli f'din il-wiki
function f.numruArtikli()
return getNounCount(mw.site.stats.articles, 'artiklu', 'artikli', true)
end
return f