Managing the Ranges of Items

Learn how to manage the range of items with the help of examples.

We'll cover the following

The trans_choice function

Working with a collection of items is the more exciting part of Laravel’s translation system. We can define translation messages that will dynamically change depending on the number of items in a collection. We do this by separating each section of our translation message with the pipe character (|).

For example, we define the ranges translation key, which contains the following individual translation messages:

{0}No items
[1,3]Between one and three
[4,6]Between four and six
[7,*]Seven and beyond!

The first translation message begins with the sequence {0}, which indicates that the following message should be used when our collection contains no items (it has a count of zero):

Get hands-on with 1400+ tech skills courses.