Download the PHP package eolica/nova-locale-switcher without Composer
On this page you can find all versions of the php package eolica/nova-locale-switcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nova-locale-switcher
Laravel Nova Locale Switcher Tool
This tool provides a simple header dropdown to quickly switch between locales. This tool does not have any concrete implementation, so is up to you of what happens when a locale is selected from the dropdown.
Installation
If you were using our tramuntana-studio/nova-locale-switcher
package, please modify it accordingly.
Usage
We will demonstrate how tu use this tool with a simple example. First, you must register the tool in NovaServiceProvider
under tools.
The setLocales
method expects an associative array, the key being the locale code and the value the name of the locale. In this example, we set the locales from de nova.php
config file:
For handling the locale switching we must pass a callable
to the onSwitchLocale
method, in this example we update the current user locale field (this is a custom field that we added to the model) with the locale that we receive from the Request object.
Now, for setting the application locale we can do it inside the boot
method of the NovaServiceProvider
by using the Nova::serving()
method:
The last step is to display the language selector. For that we must publish Nova's views executing the next command:
Now we go to the file /resources/views/vendor/nova/layout.blade.php
and right after the dropdown that includes the user's partial we add the locale-switcher
Vue component:
And that should be it!
This is one of many solutions you can use, the important thing is that you can switch to another type of implementation without depending on an external package.
Changelog
Please see CHANGELOG for more information what has changed recently.
Security
If you discover a security vulnerability within this package, please send an email at [email protected] instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.