zerospam / laravel-gettext

Adds localization support to laravel applications using PoEdit and GNU-Gettext.
99 stars 56 forks source link

Locale file don't load when setLocale(), cache issue ? #26

Closed stfr closed 5 years ago

stfr commented 5 years ago

Hello, First of all, thanks for this package ! :)

In my project, locale is changed by a custom LocaleMiddleware, which take the lang from the URL ( /en/my-page), and change it with LaravelGetText::setLocale() + App::setLocale()

But it doesn't work perfectly. This is what happens :

So, it seems to be something related to the cache. I tried lot of things, but i'm running out of ideas. Someone have ever seen this case ?

I have found an ugly solution: extend the Symfony Translator to put the loadLocaleFile method as public, in order to call it at the end of my LocaleMiddleware, after the LaravelGettext::setLocale() ...

lrotermund commented 5 years ago

Hi, I have the same problem. How do you call loadLocaleFile on your middleware? How do you initialise the extended translator/ get the translator reference?

stfr commented 5 years ago

It's been a while, but I think we added this line in our custom Locale Middleware which define locale from the url :

// Set locale and refresh locale file
LaravelGettext::getTranslator()->setLocale($locale);

it will directly force the locale in the translator Class, which refresh the cache.

Tell me if it works, I forgot to close this issue :)

lrotermund commented 5 years ago

It works! I used LaravelGettext::setLocale($sessionLocale) and these resource file problem drove me crazy...

Many many thanks!