just import the dutch language files and change the localisation in teh config file of laravel ;)
did the same with german.
Hi all,
I'd like the main Laravel application locale to be English, so I configured it this in the config file. Is there a way I can force Nova to use another locale like Dutch?
Should be fairly easy I guess, but I can't seem to get it right.
Thanks!
just import the dutch language files and change the localisation in teh config file of laravel ;)
did the same with german.
@TORPEDO - Thanks for your reply but that is not what I want. I want the main application to stay English, but Nova to use the Dutch locale.
I think you should create a middleware and change locale in it.
public function handle($request, Closure $next)
{
App::setLocale('your_locale');
return $next($request);
}
After registering the middleware in Kernel.php you must add it in middleware array in config/nova.php
'middleware' => [
'web',
Authenticate::class,
DispatchServingNovaEvent::class,
BootTools::class,
Authorize::class,
'created_middleware'
],
@vlad_kash Thanks, that did a lot but it looks like there is some bug in Laravel Nova which causes the sidebar to be translated as it should, but everything else on the right side of the screen stays in English. Pretty weird...
@MICHAEL1986 - If you keep in mind a translation of your resources, for example, you can change the title of the resource with changing label function in your resource file:
namespace App\Nova;
class User extends Resource
{
...
public static function label()
{
return "Your lable displayed in navigation";
}
}
@vlad_kash Thanks, I know, that's already working as it should. Maybe I should be a bit more specific ;-) Sorry.
I mean the buttons like "Create & add another", "Create" and headers like "New {resource name here}", texts in metric cards like "No Prior Data" and "No Current Data". And messages when a resource has no items yet, like "No bestelling matched the given criteria.".
All those things are translated in my localization file, but they won't show up. I've checked the JSON for errors, but it's a valid file.
There is singularLabel method in your resource class, it works like label method. For changing specific messages I have no idea besides to find phrases in your IDE and change it in Nova source code. Also, I suggest you one more time to read that: https://nova.laravel.com/docs/1.0/customization/localization.html.
I'm not talking about the translations of my resources, it's about translating the buttons and headers coming from Nova.
Sure enough I'm not going to modify the source code of Nova itself, as it's absolutely bad practice.
SingularLabel method is the way to change tranlation of buttons like "Create".
Finally I've found the solution. Creating a middleware did a lot but wasn't sufficient.
Removing the middleware and adding this in the boot function of the NovaServiceProvider did the trick:
Nova::serving(function (ServingNova $event) {
app()->setLocale('nl');
});
Thanks for your solution! Did this also change the language on the nova login page? If not, how did you deal with that? It doesn't seem to change the language for me.
Welcome! No it didn't, for me that wasn't a problem.
In case someone had the same problem and wanted to to change the language of the login page as well:
Add the following code to the boot function of the NovaServiceProvider.php in addition to what @michael1986 wrote.
Nova::booted(function () {
app()->setlocale('nl');
});
Hey Guys, Did anyone have an issue with not translating some of the buttons, alerts messages, search, and few other places ?
Nova::serving(function (ServingNova $event) {
if (Auth::user()) {
app()->setLocale(Auth::user()->language);
} else {
app()->setLocale('en');
}
});
-Seems to be not localising the resource buttons texts etc
Can anyone point out what i am doing wrong
Try this for Nova 4:
$this->app->make(\Illuminate\Contracts\Http\Kernel::class)
->appendToMiddlewarePriority(\Laravel\Nova\Http\Middleware\ServeNova::class);
Nova::booted(function () {
$this->app->setLocale(auth()->user ? auth()->user()->locale : 'nl');
});
Nova::serving(function () {
$this->app->setLocale(auth()->user ? auth()->user()->locale : 'nl');
});
Please or to participate in this conversation.