-
Notifications
You must be signed in to change notification settings - Fork 45
Description
When installing this Honeypot package, my custom translations from .json translation files are not available in Laravel Nova.
I know of one other package that exhibits the same problem: Intervention/validation #59 and whitecube/nova-flexible-content - laravel/nova-issues/ #4192. Nova issues are: laravel/nova-issues#2505, laravel/nova-issues#2515, laravel/nova-issues#3767
The problem is that since #13, the translator is loaded when the app is booted:
$this->app->booted(function ($app) {
$validator->extend('honeytime', 'honeypot@validateHoneytime', $translator->get('honeypot::validation.honeytime'));
});
Nova's own service provider registers its custom translations that way (nova 2.12.0):
class NovaServiceProvider extends ServiceProvider
{
public function boot()
{
$this->registerResources();
}
protected function registerResources()
{
$this->loadJsonTranslationsFrom(resource_path('lang/vendor/nova'));
}
// from vendor/laravel/framework/src/Illuminate/Support/ServiceProvider.php
protected function loadJsonTranslationsFrom($path)
{
$this->callAfterResolving('translator', function ($translator) use ($path) {
$translator->addJsonPath($path);
});
}
}
Translator::addJsonPath only registers a file path that will get loaded later.
Unfortunately, because HoneypotServiceProvider already used the translator, the translator will never load the additional json file.
One solution could be that the HoneypotServiceProvider gets loaded after the NovaServiceProvider.
Another way would be to load the translation only when it's needed, and not already in the boot process.