Courses

Multi-Language Laravel 11: All You Need to Know

Translating Plural/Singular Forms

You're reading a FREE PREVIEW of a PREMIUM course.
Summary of this lesson:
- Use `trans_choice()` for handling plural translations
- Implement pluralization in JSON and PHP translation files
- Use `{0}`, `{1}`, and `[2,*]` syntax for different count scenarios
- Utilize `@choice()` Blade directive for easy pluralization

Have you ever needed counting specific items, with translations?

A typical code would be:

<div class="">
@if($messagesCount === 0)
<span>You have no new messages</span>
@elseif($messagesCount === 1)
<span>You have 1 new message</span>
@else
<span>You have {{ $messagesCount }} new messages</span>
@endif
</div>

To avoid these if conditions, you can use the Laravel localization pluralization feature.


Using trans_choice() Helper

Laravel comes with a really great helper function called trans_choice(). This function allows us to use a string that contains multiple translations, and it will choose the correct one based on the number we pass to it...

The full lesson is only for Premium Members.
Want to access all 18 text lessons of this course? (80 min read)

You also get:

  • 78 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord