How to Force Translation Language in Laravel

This code snippet is very useful when you want to force the language of the translator in Laravel. For bilingual systems, sometimes you need to send content based on the user language preference. It’s simple you will see!

  // Will force subject to be in french
  trans("emails.daily_reminders.subject", [], "", "fr")

  // Will force subject to be in english
  trans("emails.daily_reminders.subject", [], "", "en")

For more information, here’s the documentation of the Laravel / Symphony translator.

Has you can see, the third parameters ($domain) is useless. The third parameter is never used in Laravel. Laravel’s team said they will discontinue this in version 4.1+, but it’s still not changed in Laravel 5.1, see the issue on GitHub.

Add a comment