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

Package seems to cause translation errors in other packages #59

Open
sanderbaas opened this issue Aug 31, 2022 · 4 comments
Open

Package seems to cause translation errors in other packages #59

sanderbaas opened this issue Aug 31, 2022 · 4 comments

Comments

@sanderbaas
Copy link

sanderbaas commented Aug 31, 2022

It seems that this package causes translation errors in Laravel Nova (see this issue laravel/nova-issues#4192).

By calling a translation in a constructor the incorrect locale is set for the App (laravel/nova-issues#4192 (comment))

I think this is what is happening with this package in the file validation/src/Laravel/ValidationServiceProvider.php.

From the boot() function $this->getErrorMessage() is called and this calls
return $this->app['translator']->get('validation::validation.' . $rulename);. (https://github.com/Intervention/validation/blob/master/src/Laravel/ValidationServiceProvider.php#L48)

When I comment this out or replace it with return ''; the translation errors in Laravel Nova disappear.

I am using php8, laravel/framework 9.26.1, laravel/nova 4.13.0, intervention/validation 3.2.0

@olivervogel
Copy link
Member

olivervogel commented Sep 1, 2022

Thanks for reporting.

According to this comment the translation should not be used before setting a current locale. I checked this and noticed the locale is already set when this code runs.

Can't think of an other solution as to pass static text error messages to the Illuminate\Validation\Factory::extend() method, which contradicts the whole translation logic.

Any other thoughts on this?

@rderks88
Copy link

Still happening. Using it in combination with Laravel nova and all of my translation suddenly don't work. When I uninstall the package, they do.

@rderks88
Copy link

rderks88 commented Oct 15, 2024

Just noticed that it all has to do with calling that translater too early.
Below fixes it for me. I'll just override the serviceProvider and continue.
Errormessages are still translated for me when the key is returned.

protected function getErrorMessage(string $rulename): string
    {
        return 'validation::validation.' . $rulename;
//        return $this->app['translator']->get('validation::validation.' . $rulename);
    }

@olivervogel
Copy link
Member

olivervogel commented Oct 15, 2024

Errormessages are still translated for me when the key is returned.

Thanks, I just tested your approach with Laravel 11.22 and Intervention Validation 4.4.2. I only get the string validation::validation.rulename and not the translation.

However, I cannot reproduce the error with the setup mentioned above.

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

No branches or pull requests

3 participants