Laravel PHP Translation Files
Format, editor, and workflow for the Laravel framework's translation system.
Laravel translation files are PHP files that return an associative array of translation keys mapped to translated strings. Each language has its own folder under lang/ (or resources/lang/ in Laravel 8 and older), with one .php file per logical group — messages.php, auth.php, validation.php, and so on. Laravel's __() and trans() helpers resolve keys by group.key notation. The framework also supports JSON translation files for shorter, locale-specific overrides.
- What it is: PHP file returning an associative array of translations
- File extension:
.php - Standard body: Laravel framework
- Location:
lang/<locale>/(Laravel 9+) orresources/lang/<locale>/(Laravel 8) - Plurals: pipe-delimited strings (
1 item|:count items) viatrans_choice - Used by: Laravel apps, Lumen, and PHP frameworks built on Laravel
What a Laravel translation file looks like
A typical group file returns an associative array with nested groups. Placeholders use Laravel\'s :placeholder syntax (or, increasingly, :Placeholder / :PLACEHOLDER for case modifiers). Pluralization uses pipe-delimited strings:
<?php
// lang/de/messages.php
return [
'welcome' => 'Willkommen, :name!',
'auth' => [
'failed' => 'Diese Anmeldedaten stimmen nicht überein.',
'throttle' => 'Zu viele Anmeldeversuche. Bitte versuchen Sie es in :seconds Sekunden erneut.',
],
'cart' => [
'items' => '1 Artikel im Warenkorb|:count Artikel im Warenkorb',
],
'errors' => [
'not_found' => 'Seite nicht gefunden',
'forbidden' => 'Zugriff verweigert',
],
];Editing Laravel translation files
- PhpStorm / VS Code: syntax-aware editing of .php arrays. Useful linters catch missing commas and broken array syntax.
- Cloud TMS platforms: Locize imports and exports Laravel
.phpfiles. Translators work in a CAT-style UI without writing PHP. - Text editors: fine for spot fixes; watch for broken array structure (missing commas, unbalanced brackets) which break the entire file.
Common Laravel translation workflows
- Adding a language. Create
lang/<locale>/with one .php file per group. Copy the structure fromlang/en/and translate the values. Setapp.localeat runtime. - Translator handoff. Export the default
lang/en/tree to a TMS, translate, import the result back intolang/<locale>/. - Pluralization with trans_choice. Wrap pluralized text in pipe-delimited strings, then call
trans_choice("cart.items", $count). Laravel picks the right form based on the count. - Continuous localization. Wire your TMS to push new keys into Laravel\'s lang folder via CI/CD; new translations sync back automatically.
How to translate Laravel files in Locize
Locize imports and exports Laravel .php files:
- Get started
- Import your Laravel
.phpfile - Edit translations in the CAT view with translation memory, glossary, and style guide applied automatically
- Use bulk actions for AI / machine translation, then route results through a review workflow
- Export back to
.phpper locale — or convert to JSON, YAML, gettext, XLIFF, or any other supported format
Frequently asked questions
A Laravel translation file is a .php file that returns a PHP array of translation keys mapped to translated strings. Each language has its own folder under `lang/` (or `resources/lang/` in older Laravel versions), with one .php file per logical group (`messages.php`, `auth.php`, `validation.php`). Laravel's `__()` and `trans()` helpers look up keys by `group.key` notation.
Modern Laravel uses `lang/<locale>/<group>.php` (e.g. `lang/de/messages.php`). Each .php file returns an associative array. Keys are typically dotted (`auth.failed`, `validation.required`). Laravel also supports JSON translation files in `lang/<locale>.json` for shorter, locale-specific overrides.
Laravel uses pipe-delimited strings: `"1 apple|:count apples"` for simple two-form pluralization, or interval syntax `"{0} None|[1,19] Some|[20,*] Many"` for more granular cases. Use `trans_choice("messages.apples", $count)` at runtime; Laravel picks the right form based on the count.
Any PHP-aware editor (PhpStorm, VS Code with PHP Intelephense) opens .php translation files. For team workflows use a translation management system that imports Laravel .php — Locize imports and exports the `.php` format. Translators work in a CAT-style UI without touching PHP syntax.
Both work. .php is the traditional Laravel approach and integrates cleanly with the framework's grouping convention (`auth.failed`, `validation.required`). .json files are simpler and useful for full-string keys (`"Welcome to our app" => "Willkommen in unserer App"`) — Laravel resolves JSON entries by their literal source string when no group/key is given.
In Laravel 9+, the default location is `lang/<locale>/`. In Laravel 8 and older it was `resources/lang/<locale>/`. The `lang:publish` Artisan command moves the files to the modern location if you migrate from an older version.