Skip to main content

What is localization?

Laravel’s localization system lets you store translation strings for each language your application supports and retrieve them through a single helper function. When you call __('messages.welcome'), Laravel looks up the string in the active locale’s file and returns the translated version. There are two ways to organize translation strings:

Publishing language files

New Laravel apps don’t include the lang directory by default. Run this command to create it and publish Laravel’s built-in translations:

Configuring the locale

Default locale

Set the application’s default language in config/app.php, typically via .env:
The fallback locale is used whenever a string is missing from the active locale’s files.

Changing locale at runtime

Use the App facade to switch locale for the current request — useful in middleware:

Checking the current locale

Defining translation strings

PHP file format (short keys)

Create one file per feature group inside a locale directory:
Use underscores for regional locale directory names: en_GB for British English, fr_FR for French — not en-gb or fr-fr. Laravel follows the POSIX locale convention for directory names.

JSON file format (translation strings as keys)

Use the English text as the key. Each other language gets a JSON file at the lang/ root:
When no JSON file exists for a locale, or when a key is missing, Laravel returns the key string as-is — which doubles as the English fallback automatically.
The JSON approach works well for UI labels where you write English directly in Blade templates. You don’t have to invent key names, and the English app is ready without any translation file.

Retrieving translation strings

The __() helper

In Blade templates

Placeholders

Define dynamic parts with a :name prefix:
Pass replacement values as the second argument:
In Blade:

Pluralization

Different languages handle pluralization differently. Laravel’s trans_choice() function selects the right form based on a count.

Simple singular / plural

Separate the two forms with |:

Range-based forms

Use {n} for exact values and [min,max] for ranges (* means infinity):

Placeholders in plural strings

:count is always available as the passed count:

Setting up locale switching

Here’s a complete pattern for letting users switch language and persist it in the session:
1

Create a SetLocale middleware

2

Implement the middleware

3

Register the middleware

In bootstrap/app.php:
4

Add a locale-switching route

5

Add switcher buttons in Blade

Overriding package translations

When a third-party package ships its own language files, override individual strings by placing a file in lang/vendor/{package}/{locale}/:

Function reference

Last modified on March 29, 2026