rinvex / laravel-support

Rinvex common support helpers, contracts, and traits required by various Rinvex packages. Validator functionality, and basic controller included out-of-the-box.
https://rinvex.com
MIT License
73 stars 70 forks source link

Modules translations invalidated by this package #68

Closed Rattone closed 1 year ago

Rattone commented 1 year ago

Hi, for some reason this package invalidates the module translations of the nwidart/laravel-modules package. I discovered the problem using rinvex/laravel-categories which has this package as a dependency.

A simple composer require of laravel-categories stops module translations working.. trying to install the single dependencies I noticed that the problem occurs when requiring rinvex/laravel-support.

I couldn't figure out why, we are discussing it here > https://github.com/nWidart/laravel-modules/issues/1476

The problem occurs with both Laravel 8 and 9

Omranic commented 1 year ago

Thank you for your report, can you please explain what do you mean by invalidating translations please?

Also what makes you sure this package is the reason? It might be some other package that’s required in the list of dependencies too, right?

Rattone commented 1 year ago

Thanks for your fast response. By invalidate I mean that the translations stop working, the it.json file placed inside a module seems not to be read/loaded, so I see the hardcoded text __('Hello world'), eg: "Hello world" instead of "Ciao mondo".

Installing the individual dependencies in a clean install of Laravel, with just nwidart/laravel-modules (and minimal code to test the translation), I've come to realize that just installing this package will "break" the module translations. Now I have also individually installed the package's dependencies spatie/laravel-schemaless-attributes and watson/validating and the problem does not exist. So from what I've been able to understand the problem is with this package.

Omranic commented 1 year ago

You mentioned rinvex/laravel-modules that’s not a package, may you please explain more?

Also regarding rinvex/laravel-support there’s no code that overrides the translation loading, and we’re not using nWidart/laravel-modules so we investigate more. If you’re able to dig deeper and find the actual root cause, I’ll be happy to look into it. Also PRs are most welcome if you’ve any proposed fixes.

The service provider file is the only place that auto loads and could affect your project, and as you can see it only registers validation roles and collection macro, which has nothing to do with translations https://github.com/rinvex/laravel-support/blob/master/src/Providers/SupportServiceProvider.php

Please feel free to reopen this issue if you’ve further details 🙌

Rattone commented 1 year ago

You mentioned rinvex/laravel-modules that’s not a package, may you please explain more?

Sorry for the confusion, I meant nwidart/laravel-modules (fixed previous message)

Rattone commented 1 year ago

I've been trying to figure out the reason for the problem for days.

Only yesterday, with a fresh installation, I managed to figure out that installing this package broke the translations system of the module.

To my limited knowledge I could not find the cause. I'll do more tests these days, hoping to understand more .

I will also create a repository where the problem occurs so you can test it.

Thank you very much

Omranic commented 1 year ago

Sure, happy to help, and happy holidays :)

Rattone commented 1 year ago

Hi! I created the repository with minimal code to test and reproduce the translations problem. I split the few operations into individual commits. To check the problem, simply visit the route /blog, the phrase Hello World is not translated. By removing the rinvex/laravel-support package the translation works again.

https://github.com/Rattone/laravel-8-module-translations-test

The problem also occurs with Laravel 9 and the latest versions of the packages used.

Rattone commented 1 year ago

At the moment I found that the problem is related to these 2 calls to the trans() helper. If I comment out those lines or replace trans() with an hardcoded text the translation of the module works again. 😵‍💫

image

I think it's a problem related to the boot order of the various service providers but I'm not familiar with this kind of thing

Omranic commented 1 year ago

That’s really weird, because these two lines are basically using translations, not changing any behaviors!

Rattone commented 1 year ago

After a bit of research I seem to have understood that Laravel, when loading translations from different locations, it does in a precise order; the call to the translator trans() "reloads" at some stage of startup the source of the translations. This causes the framework to look for module translations in the "standard" Laravel path instead of the module folders