Advanced

Localization

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.

Configuration

Before you begin, be sure to review the Configuration section.

Default Language

'locale' => 'en',
$config->locale('en');

Available Languages

'locales' => ['en', 'ru'],
$config->locales(['en', 'ru']);

If you have changed the language in the panel interface, the selection is saved in sessions and will take precedence over the configuration.

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);