andywer/laravel-js-localization

Strange localization behaviours

timo75 opened this issue · 3 comments

Not sure if this is related to Laravel 5.1, but with both the laravel-5 and develop branch I'm experiencing this behaviour:

Whatever locale I set in my frontend controller with App::setLocale('xx'):

  • non-JS labels are displayed correctly according to the locale set with App::setLocale
  • but js-localization is always set according to the browser (!) language.

I debugged by logging the Lang::locale() in both my frontend controller and in the JsLocalizationController in getMessagesJson() method, and the result is as mentioned above: Lang:locale() in JsLocalizationController is not influenced by the App::setLocale() value set in frontend controller, but always seems to depend on the browser's language. When I change the browser language, that value changes accordingly.

Any idea?

Hey Timo. Thanks for your feedback!
The issue was actually pretty simple: The localization controller that delivers the package's JS stuff set the locale. But as it is a request separate from the web app page, your app's locale logic had no chance to run for this request.

I changed a few things and the JS locale is set by some one-line inline JS code now.
Give it a try (develop branch) and tell me what you think :)

Cheers

That solved it. Thanks a lot for the quick help :)

PS: Merged develop into laravel-5. You will probably prefer to use this branch.