Laravel
Laravel JSON (lang/{locale}.json) and Laravel PHP (lang/{locale}/*.php) translation files.
| Format | Identifier | Extension | Typical path |
|---|---|---|---|
| Laravel JSON | laravel_json | .json | lang/{locale}.json |
| Laravel PHP | laravel_php | .php | lang/{locale}/messages.php |
Laravel JSON
The file Laravel's __('...') helper reads when you key strings by their source sentence. It is a flat JSON object, and transglot reads and writes it exactly like JSON (flat): every value must be a string, and nested objects are an error.
{
"Welcome back": "Bon retour",
"Hello, :name!": "Bonjour, :name !",
"You have :count new messages.": "Vous avez :count nouveaux messages."
}The key is the source sentence. When transglot guesses the format of a .json file, a flat file with a space in any key is taken as Laravel JSON.
Laravel PHP
A PHP file returning a flat array of strings:
<?php
return [
'welcome' => 'Bon retour',
'greeting' => 'Bonjour, :name !',
];transglot never runs the file. It reads it with a strict scanner that accepts only this exact shape:
- the file starts with
<?php, thenreturn [and ends with];, - single-quoted keys and values,
'key' => 'value', separated by commas (a trailing comma is fine), \\and\'as the only escapes.
Anything else is an import error, including comments (such as the doc-comment header Laravel's own language files start with), double-quoted strings, nested arrays, constants, concatenation and function calls. A nested array fails with Nested arrays are not supported in Laravel PHP files.
So Laravel PHP suits files you let transglot own. For Laravel's bundled files with nested arrays (such as validation.php), or files with comments, use Laravel JSON instead. The browser upload does not offer .php files; push them with the CLI or the API.
On export, transglot writes the same shape, four-space indented, keys in byte order. An empty file is return [];.
Plurals
Neither format has a plural construct. Laravel's pipe syntax ('{0} No messages|{1} One message|[2,*] :count messages') is an ordinary string to transglot and is stored and written back as one value. Plural keys created in transglot are left out of a Laravel export.
Placeholders
:name-style parameters (and their :Name and :NAME variants) are written back exactly as they are, and the quality checks flag a translation that drops one.