About set a custom language value from somewhere
indigofeather opened this issue · 1 comments
Dear @WanWizard
When we set language value from cookie in our company project, we found View will render with default language.
About this issue, I found the answer in
http://fuelphp.com/forums/discussion/comment/13522#Comment_13522
Now, language settings are set per Request, to make sure that changes in HMVC calls don't alter the language on the parent request. This means that if you change the language in your controller, by the time the View renders the language has been reverted to the value from before the request started.
...
If you want to set a custom language, for example based on a session value, a cookie value, or a URI segment, you will have to do that before the Request starts. You can do that in your app bootstrap, after the Fuel init call, or in a _init() method of a class that you define as always_load in your config.
Would you please clarify it in docs? Thanks a lot!
This is very old information, and no longer (completely) true.
Since November 2012, the View object will cache the language active when creating the View object, and will use that, instead of the current language set when it renders.
If you set the language after you have instantiated the View, you need to review your logic, because you're likely doing it the wrong place.