andywer / laravel-js-localization

Simple, ease-to-use and flexible package for the Laravel web framework. Allows you to use localized messages of the Laravel webapp (see `resources/lang` directory) in your Javascript code.
MIT License
143 stars 51 forks source link

Strange localization behaviours #14

Closed timo75 closed 9 years ago

timo75 commented 9 years ago

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'):

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?

andywer commented 9 years ago

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

timo75 commented 9 years ago

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

andywer commented 9 years ago

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