Hello everybody,
I’m currently developing a multi language website using Yii (which, by the way, is an amazing framework!), but I’m having some issues on managing the current language. Maybe I’m missing some basic step, as it’s my first try at this, and I couldn’t find any other problem alike in the forums, so let me explain it in detail.
To perform the language change, I’ve created a controller, to which I pass the destination language via GET, and then set the app language, like this:
Yii::app()->setLanguage($_GET['lang']);
Yii::app()->session['lang'] = Yii::app()->language;
Then, following some advices I found on other topics, I manage the language in my main layout page, with this line:
<?php Yii::app()->setLanguage(isset(Yii::app()->session['lang']) ? Yii::app()->session['lang'] : 'pt_br'); ?>
All this works nicely. I can translate all my text in the layout file via Yii::t command, and if I echo the language via Yii::app()->language it gives me the correct language code.
The problem I’m facing is with the controller I’m displaying. If I echo the app language from it, or from its view file, I always get the default language, even though the layout is displaying the user-set language. Curiously enough, if I echo the session variable it shows me the right language, but not in the app language. I know I could set it right in each controller, or even create a base class and extend my controllers from it, but it doesn’t seem right, as I’m already setting the language like I showed you above. Why aren’t my controllers getting the right language from the app?
Any thoughts on this are very much apreciated!
Thanks!