Multi-Language Laravel: All You Need to Know

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>
<span>You have {{ $messagesCount }} new messages</span>

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...

This lesson is only for Premium Members.
Want to access all lessons of this course?

You also get:

  • 52 courses (943 lessons, 46 h 42 min total)
  • Premium tutorials
  • Access to repositories
  • Private Discord