Laravel localization tutorials

Laravel gives you __(), trans_choice() and a lang directory, and leaves the rest to you. The rest is where multilingual apps break: a plural rule that works in English and fails in Polish, a queued email sent in the wrong language, a validation message nobody translated, a date that reads fine in one locale and wrong in the next.

These tutorials each take one of those problems and work through it with code you can run. They assume you already know how to call __() and want to know what happens at the edges: which locale a queued job runs in, how Laravel picks a plural form, what Carbon does when a locale is missing, how Livewire components keep their language between requests.

Every example was run against a current Laravel release before it was published. Where the framework behaves in a way the documentation does not spell out, the article shows the source that decides it.

Keep going

Frequently asked questions

Where do I start with localization in a Laravel app?

Publish the language files with php artisan lang:publish, wrap user-facing strings in __(), and set the locale per request in middleware. Once strings are externalized, adding a language is a content task. The Laravel localization guide on this site walks through the full setup.

Should I use PHP or JSON language files in Laravel?

PHP files with short keys suit application strings you want grouped and namespaced, such as validation or auth messages. JSON files keyed by the source sentence suit content-heavy apps where inventing a key for every string slows the team down. Both can be used in the same project.

How does Laravel handle languages with more than two plural forms?

trans_choice() selects a form using built-in plural rules for the active locale, so a Polish or Arabic string needs every form that language defines, separated by pipes. Supplying only two forms produces wrong text for some numbers rather than an error.

We'd like to use analytics and marketing cookies to understand how the site is used. They stay off unless you accept them. Cookie Policy