Download the PHP package nedwors/pluralize without Composer

On this page you can find all versions of the php package nedwors/pluralize. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package pluralize

Pluralize - A Laravel string helper

Latest Version on Packagist Tests

A Laravel package that provides null-safe, meaningful pluralization of strings.

Go from this...

To this...

Nice eh?

No more count($me), $me->count() or $me->total()... Just pass in your variable and have it counted for you.

No need to repeat {{ $lemons->count() }} {{ Str::plural('Lemon', $lemons->count()) }} over and over everywhere in your views. Just a unified format across your app.

No need to think anymore about whether the variable is null and what to do if so, just a clean -, or whatever you want.

The stuff of nightmares...

Call to a member function count() on null

Docs

Installation

You can install the package via composer

Setup

Minimal, if any, setup is required. The package is ready to work out of the box with sensible defaults.

The defaults are shown below. The 1st comment represents the returned string when $pizzas has a count of 10; the 2nd represents when $pizzas is null:

However you are free to configure these defaults, and fine tune the system further.

Introduction

Helper vs Class

This documentation's examples are based on the helper function pluralize(). However, the underlying class can be used just the same for every feature. For instance, the following are equivalent:

Usage

The underlying class in the package implements the Stringable interface, so in your Blade views it works just by calling the helper function or class.

Outside your views, do any of the following

Features/API

Pluralize

Pluralize has 4 main functions:

The pluralize() helper function has 4 parameters that map to these functions:

You'll notice that or is listed before as in the parameter list. This helps with usability for most use cases.

It can be accessed fluently too

This

The singular form of the string you wish to be pluralized.

From

The count/total/sum you wish to pluralize the string from.

The variable you pass can be an int, an array, a Collection, a LengthAwarePaginator or a Paginator.

By this point, it's worth noting that you are good to go. Nothing more is required for most uses.

Pluralize does provide extra features for more flexibility. These are detailed below, as well as configuration.

Or

The string to display if the count is null.

This is not required. If not provided, it will simply defer to the default -.

In addition to providing a string, you can pass a Closure that will receive the pluralized form of the word.

Why would I ever write a Closure when I can just type Oops, Rockets is not defined?

It's true, it's probably unlikely. But at least the power is there if needed. For instance, perhaps you want to grab the Auth::user(), or give context with the current time.

However, the power of using a Closure really comes when configuring the package.

As

The format to display the pluralization.

This is not required. If not provided, it will simply defer to the default n items.

The most useful means is declaring this as a Closure, which is passed the plural form of the string and the count.

How about if you wanted something along the lines of there are 10 Rockets? When there's 1 Rocket, you'll end up with There are 1 Rocket... Hmm. Well, the pipe operator is your friend! Simply declare the singular output to the left, the plural to the right.

Now, you can pass a string if you really, really want to...

...but this is most useful when used with your configuration.

Configuration

You can easily configure different aspects of the package. This is all done via the Pluralize class in your service provider.

Default Bindings

You can declare the default formats for use in your app by calling Pluralize::bind() with no arguments

The default Output is n items. The default Fallback is -.

Specific Bindings

You can bind to the word you want to pluralize for specific formatting

You can set an arbitrary key to be referred to at time of render

Driver

The package uses the Laravel Str::plural() method for pluralizing the strings passed in. You are free to use your own driver if desired. This would be especially useful for non-english languages.

Write your custom driver implementing the Pluralization interface. This defines one method, run(), which is passed the singular string and the current count. Here's the current implementation:

Then set this as the desired driver in the boot() method of your service provider

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.


All versions of pluralize with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^11.0
laravel/pint Version ^1.17
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nedwors/pluralize contains the following files

Loading the files please wait ....