Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation errors in Laravel Nova when using Honeypot #64

Open
cweiske opened this issue Sep 11, 2023 · 1 comment
Open

Translation errors in Laravel Nova when using Honeypot #64

cweiske opened this issue Sep 11, 2023 · 1 comment

Comments

@cweiske
Copy link

cweiske commented Sep 11, 2023

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.

@cweiske
Copy link
Author

cweiske commented Sep 11, 2023

I solved my problem by manually defining the service provider order in my config/app.php:

    'providers' => [
        // [...] my own providers here, and after them:

        //translator needs to be after \Laravel\Nova\NovaServiceProvider
        Laravel\Nova\NovaServiceProvider::class,
        Msurguy\Honeypot\HoneypotServiceProvider::class,
    ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant