FANDOM


-- Returns a pluralized form of a given singular noun. If the algorithm fails
-- for a particular noun, add it to the 'exceptions' table below.
local p = {}
 
local suffixes = {
   { [ 'zoon' ] = 'zoa' }, 
   { [ 'man' ] = 'men' },
   { [ 'ch' ] = 'ches' },
   { [ 'ex' ] = 'ices' },
   { [ 'fe' ] = 'ves' },
   { [ 'f' ] = 'ves' },
   { [ 'is' ] = 'es' },
   { [ 'ix' ] = 'ices' },
   { [ 'sh' ] = 'shes' },
   { [ 'um' ] = 'a' },
   { [ 'us' ] = 'i' },
   { [ 's' ] =  'ses' },
   { [ 'x' ] =  'xes' },
   { [ 'y' ] =  'ies' },
   { [ 'z' ] =  'zes' },
   { [ '/Home Village' ] =  's' },
   { [ '/Builder Base' ] =  's' },
}
 
local exceptions = {
   [ 'p.e.k.k.a' ] = 'p.e.k.k.as',
   [ 'P.E.K.K.A' ] = 'P.E.K.K.As',
   [ 'foot' ] = 'feet',
   [ 'tooth' ] = 'teeth',
   [ 'child' ] = 'children',
}
 
function p.pluralize( str )
   if type( str ) == 'number' then
      return str .. 's'
   elseif type( str ) ~= 'string' then
      return ''
   end
 
   if exceptions[ str ] then
      return exceptions[ str ]
   end
 
   if exceptions[ string.lower( str ) ] then
      return string.upper( exceptions[ string.lower( str ) ] )
   end
 
   for k, v in pairs( suffixes ) do
      for pk, pv in pairs( v ) do
         if string.sub( str, -string.len( pk ) ) == pk then
            return string.sub( str, 0, string.len( str ) - string.len( pk ) ) .. pv
         elseif string.sub( str, -string.len( pk ) ) == string.upper( pk ) then
            return string.sub( str, 0, string.len( str ) - string.len( pk ) ) .. string.upper( pv )
         end
      end
   end
 
   if string.upper( string.sub( str, -1 ) ) == string.sub( str, -1 ) then
      return str .. 'S'
   else
      return str .. 's'
   end
end
 
function p.main( frame )
   local str = ( frame.args[ 1 ] )
 
   if '' .. tonumber( str ) == str then
      str = tonumber( str )
   end
 
   return p.pluralize( str )
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.