Laravel Lang Help

Configuration

Optionally, you can publish the config file with:

php artisan vendor:publish --provider="LaravelLang\Publisher\ServiceProvider"

This is the contents of the published config/localization.php file:

use LaravelLang\LocaleList\Locale; return [ /* * 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 * * By default, `false`. */ 'inline' => (bool) env('LANG_PUBLISHER_INLINE', false), /* * Do arrays need to be aligned by keys before processing arrays? * * By default, true */ 'align' => (bool) env('LANG_PUBLISHER_ALIGN', true), /* * This option determines the mechanism for converting translation * keys into a typographic version. * * For example: * for `false`: * "It's super-configurable... you can even use additional extensions to expand its capabilities -- just like this one!" * for `true`: * “It’s super-configurable… you can even use additional extensions to expand its capabilities – just like this one!” * * By default, false */ 'smart_punctuation' => [ 'enable' => false, 'common' => [ 'double_quote_opener' => '“', 'double_quote_closer' => '”', 'single_quote_opener' => '‘', 'single_quote_closer' => '’', ], 'locales' => [ Locale::French->value => [ 'double_quote_opener' => '« ', 'double_quote_closer' => ' »', 'single_quote_opener' => '‘', 'single_quote_closer' => '’', ], Locale::Russian->value => [ 'double_quote_opener' => '«', 'double_quote_closer' => '»', 'single_quote_opener' => '‘', 'single_quote_closer' => '’', ], Locale::Ukrainian->value => [ 'double_quote_opener' => '«', 'double_quote_closer' => '»', 'single_quote_opener' => '‘', 'single_quote_closer' => '’', ], Locale::Belarusian->value => [ 'double_quote_opener' => '«', 'double_quote_closer' => '»', 'single_quote_opener' => '‘', 'single_quote_closer' => '’', ], ], ], ];

Aliases

If you need to use locale aliases, you can add the aliases key to the previously published configuration file (config/localization.php).

Or you can publish if you haven’t done so before:

php artisan vendor:publish --provider="LaravelLang\Locales\ServiceProvider"

This is the contents of the published config/localization.php file:

return [ /* * The language codes chosen for the files in this repository may not * match the preferences for your project. * * Specify here mappings of localizations with your project. */ 'aliases' => [ // \LaravelLang\LocaleList\Locale::German->value => 'de-DE', // \LaravelLang\LocaleList\Locale::GermanSwitzerland->value => 'de-CH', ], ];

Alignment

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:

<?php 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:

<?php 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:

<?php return [ /* |-------------------------------------------------------------------------- | Validation Language Lines |-------------------------------------------------------------------------- | | The following language lines contain the default error messages used by | the validator class. Some of these rules have multiple versions such | as the size rules. Feel free to tweak each of these messages here. | */ 'accepted' => 'The :attribute must be accepted.', 'active_url' => 'The :attribute is not a valid URL.', // many rules 'uuid' => 'The :attribute must be a valid UUID.', /* |-------------------------------------------------------------------------- | Custom Validation Language Lines |-------------------------------------------------------------------------- | | Here you may specify custom validation messages for attributes using the | convention "attribute.rule" to name the lines. This makes it quick to | specify a specific custom language line for a given attribute rule. | */ 'custom' => [ 'name' => [ 'required' => 'Custom message 1', 'string' => 'Custom message 2', ], ], /* |-------------------------------------------------------------------------- | Custom Validation Attributes |-------------------------------------------------------------------------- | | The following language lines are used to swap our attribute placeholder | with something more reader friendly such as "E-Mail Address" instead | of "email". This simply helps us make our message more expressive. | */ 'attributes' => [ 'name' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz', ], ];

This is what it will look like after the update:

<?php 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', ], ];

Smart Punctuation

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 enabled in the config/localization.php file:

'smart_punctuation' => [ 'enable' => false, 'common' => [ 'double_quote_opener' => '“', 'double_quote_closer' => '”', 'single_quote_opener' => '‘', 'single_quote_closer' => '’', ], 'locales' => [ Locale::French->value => [ 'double_quote_opener' => '«&nbsp;', 'double_quote_closer' => '&nbsp;»', 'single_quote_opener' => '‘', 'single_quote_closer' => '’', ], Locale::Russian->value => [ 'double_quote_opener' => '«', 'double_quote_closer' => '»', 'single_quote_opener' => '‘', 'single_quote_closer' => '’', ], Locale::Ukrainian->value => [ 'double_quote_opener' => '«', 'double_quote_closer' => '»', 'single_quote_opener' => '‘', 'single_quote_closer' => '’', ], Locale::Belarusian->value => [ 'double_quote_opener' => '«', 'double_quote_closer' => '»', 'single_quote_opener' => '‘', 'single_quote_closer' => '’', ], ], ],

You can also set different rules for any localization.

By default, conversion is disabled.

Last modified: 16 February 2024