laravel
The laravel preset supports the localization of Laravel.
Detection
The preset applies when composer.json requires laravel/framework. The preset is exclusive: when it applies, x18n tests no preset after it.
import { laravel } from '@x18n/cli/presets'
import { defineConfig } from '@x18n/core'
export default defineConfig({
presets: [laravel()],
})Locale files
If your config has no resources, the preset uses these patterns:
lang/{locale}/{namespaces}.phpresources/lang/{locale}/{namespaces}.phplang/{locale}.jsonresources/lang/{locale}.json
The php format reads a file that returns an array literal, and writes edits back into the array. The path of a PHP file is the first part of its keys:
<?php
return [
'failed' => 'These credentials do not match.',
];This file has the key auth.failed. A file in a subdirectory, such as lang/en/admin/users.php, gives keys such as admin.users.title. In a JSON file, such as lang/en.json, each key is a whole sentence: Welcome back!.
Supported syntax
In PHP and Blade files, the preset reads __, trans, trans_choice, @lang, Lang::get and Lang::choice. Laravel writes the keys of a nested file with a slash. The preset turns each slash into a dot:
{{ __('auth.failed') }}
@lang('admin/users.title')
{{ __('Welcome back!') }}These usages are auth.failed, admin.users.title and Welcome back!.
Placeholders
Colon: :name, as in 'title' => 'Users :count'.
Extraction templates
| Kinds | Template |
|---|---|
| any | __('{key}') |