Basics
After installing MoonShine, a directory lang/vendor/moonshine
will also appear in the translations directory,
where you can add support for a new language or modify the current translations.
By default, MoonShine only includes the English language. Look for additional languages in the Plugins section.
You can also use the third-party package laravel-lang/moonshine. It provides a large number of localizations in one package.
Configuration
Before you begin, be sure to review the Configuration section.
Default Language
'locale' => 'en',
$config->locale('en');
Available Languages
'locales' => ['en', 'ru'],
It is also possible to specify a key-value:
'locales' => [ 'en' => 'English', 'ru' => 'Russian',],
$config->locales(['en', 'ru']);
It is also possible to specify a key-value:
$config->locales([ 'en' => 'English', 'ru' => 'Russian',]);
If you have changed the language in the panel interface, the selection is saved in sessions and will take precedence over the configuration.
Localization parameter
By default, _lang
is used as the name of the parameter to set localization.
It is possible to change the name both through the configuration file and through the service provider.
'locale_key' => '_lang',
$config->localeKey('_lang');
Language Switching
The logic for switching languages in the panel interface is handled by the middleware MoonShine\Laravel\Http\Middleware\ChangeLocale
.
ChangeLocale
saves the selection in the session and retrieves the value from the session to set the language, or uses the data from the config if a request to change the language is present.
If you want to change the language switching logic to your own, simply replace the middleware
with your own.
'middleware' => [ // ... ChangeLocale::class,],
$config ->exceptMiddleware(ChangeLocale::class) ->addMiddleware(MyChangeLocale::class);