Configuration
Optionally, you can publish the config file with:
php artisan vendor:publish --tag="localization"
This is the contents of the published config/localization.php
file:
Show configuration
{...}
The inline
option determines what type of files to use when updating language files.
true
means inline files will be used.false
means that default files will be used.
For example, the difference between them can be seen here:
The :attribute must be accepted. // default
This field must be accepted. // inline
This option is available in the config/localization.php
file:
return [
'inline' => (bool) env('LOCALIZATION_INLINE', env('LANG_PUBLISHER_INLINE')),
];
The align
option defines the alignment of values relative to each other when processing localization files.
When updating files, all comments from the final files are automatically deleted. Unfortunately, var_export does not know how to work with comments.
Your file example:
return [
/*
|--------------------------------------------------------------------------
| Authentication Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used during authentication for various
| messages that we need to display to the user. You are free to modify
| these language lines according to your application's requirements.
|
*/
'failed' => 'These credentials do not match our records 123456.',
'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
'foo' => 'bar',
];
An updated file like this:
return [
'failed' => 'These credentials do not match our records 123456.',
'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
'foo' => 'bar',
];
and example of validation.php
file:
Show content
{...}
This is what it will look like after the update:
return [
'accepted' => 'The :attribute must be accepted.',
'active_url' => 'The :attribute is not a valid URL.',
'uuid' => 'The :attribute must be a valid UUID.',
'custom' => [
'name' => [
'required' => 'Custom message 1',
'string' => 'Custom message 2',
],
],
'attributes' => [
'name' => 'Foo',
'bar' => 'Bar',
'baz' => 'Baz',
],
];
This option is available in the config/localization.php
file:
return [
'align' => (bool) env('LOCALIZATION_ALIGN', env('LANG_PUBLISHER_ALIGN', true)),
];
If you want to name codes differently, such as de-DE
instead of de
or de-CH
instead of de_CH
, you can define aliases
in the configuration file.
After that, all adding, updating, and deleting actions will automatically use the specified aliases in the config/localization.php
config file:
use LaravelLang\LocaleList\Locale;
return [
'aliases' => [
Locale::German->value => 'de-DE',
Locale::GermanSwitzerland->value => 'de-CH',
],
];
If the config/localization.php
file already exists, then you can add the aliases key in it and specify the desired aliases
using a data array.
After this, you can, for example, add new localizations by specifying both the main code and its alias:
php artisan lang:add de de_CH
Installed locales will use the specified aliases as folder names for PHP translations and file names for JSON translations:
lang
de-CH
de-DE
This option is available in the config/localization.php
file:
return [
'aliases' => [
// \LaravelLang\LocaleList\Locale::German->value => 'de-DE',
// \LaravelLang\LocaleList\Locale::GermanSwitzerland->value => 'de-CH',
],
];
When updating translation keys, you can also enable intelligent converts ASCII quotes, dashes, and ellipses to their Unicode.
For example:
{
"Some": "\"It's super-configurable... you can even use additional extensions to expand its capabilities -- just like this one!\""
}
Will result in files:
{
"Some": "“It’s super-configurable… you can even use additional extensions to expand its capabilities – just like this one!”"
}
This option is available in the config/localization.php
file:
Show settings
{...}
You can also set different rules for any localization.
By default, conversion is disabled.
When using the package to work with routing, you can override the default values of key names.
This option is enabled in the config/localization.php
file:
use LaravelLang\Config\Constants\RouteName;
return [
'routes' => [
'names' => [
'parameter' => RouteName::Parameter,
'header' => RouteName::Header,
'cookie' => RouteName::Cookie,
'session' => RouteName::Session,
'column' => RouteName::Column,
],
'name_prefix' => env('LOCALIZATION_NAME_PREFIX', 'localized.'),
'redirect_default' => (bool) env('LOCALIZATION_REDIRECT_DEFAULT', false),
'group' => [
'middlewares' => [
'default' => [
LaravelLang\Routes\Middlewares\LocalizationByCookie::class,
LaravelLang\Routes\Middlewares\LocalizationByHeader::class,
LaravelLang\Routes\Middlewares\LocalizationBySession::class,
LaravelLang\Routes\Middlewares\LocalizationByModel::class,
],
'prefix' => [
LaravelLang\Routes\Middlewares\LocalizationByParameterPrefix::class,
LaravelLang\Routes\Middlewares\LocalizationByCookie::class,
LaravelLang\Routes\Middlewares\LocalizationByHeader::class,
LaravelLang\Routes\Middlewares\LocalizationBySession::class,
LaravelLang\Routes\Middlewares\LocalizationByModel::class,
],
],
],
],
];
You can define default parameter values when using the Models package.
This setting available in the config/localization.php
file:
return [
'models' => [
'suffix' => 'Translation',
'filter' => [
'enabled' => (bool) env('LOCALIZATION_FILTER_ENABLED', true),
],
'helpers' => env('VENDOR_PATH', base_path('vendor/_laravel_lang')),
],
];
The suffix
parameter is used to specify the suffix of the models to which the translation repository belongs.
For example:
App\Models\Post::class
App\Models\PostTranslation::class
Here you can not only activate default translators, but also create your own. You can read more about this on the Translator package information page.
This setting available in the config/localization.php
file:
return [
'translators' => [
'channels' => [
'google' => [
'translator' => '\LaravelLang\Translator\Integrations\Google',
'enabled' => (bool) env('TRANSLATION_GOOGLE_ENABLED', true),
'priority' => (int) env('TRANSLATION_GOOGLE_PRIORITY', 1),
],
'deepl' => [
'translator' => '\LaravelLang\Translator\Integrations\Deepl',
'enabled' => (bool) env('TRANSLATION_DEEPL_ENABLED', false),
'priority' => (int) env('TRANSLATION_DEEPL_PRIORITY', 2),
'credentials' => [
'key' => (string) env('TRANSLATION_DEEPL_KEY'),
],
],
'yandex' => [
'translator' => '\LaravelLang\Translator\Integrations\Yandex',
'enabled' => (bool) env('TRANSLATION_YANDEX_ENABLED', false),
'priority' => (int) env('TRANSLATION_YANDEX_PRIORITY', 3),
'credentials' => [
'key' => (string) env('TRANSLATION_YANDEX_KEY'),
'folder' => (string) env('TRANSLATION_YANDEX_FOLDER_ID'),
],
],
],
'options' => [
'preserve_parameters' => true,
],
],
];