Revision #7 has been created by c@cba on Dec 26, 2011, 2:45:17 AM with the memo:
Implement a language selector widget and manage the application language in the background.
« previous (#6)
Manage (Target) Language in Multilingual Applications + A Language Selector Widget (i18n)
i18n, language, multilanguage, session, cookie, Widgets, behavior, event handler
f you have
a multilingual application,
you have to provide the us
ns to select/change the language, and you have to manage the application language in the background.
Here's my way of doing this (see also this [post](http://www.yiiframework.com/wiki/26/setting-and-maintaining-the-language-in-application-i18n/ "Setting Language") for an alternative):
- Provide a language selector in the header of each page using a custom widget.
- When a language is selected, save it in the Session and in a Cookie.
- Every time a page/url is requested, check if the
language is provided (via
, session or cookie) and set the application language accordingly.
n event handler for the 'onBeginRequest' event. As the name of the event suggests, this event handler then will be called on the beginning of every request. _Why is it necessary to set the application language for every request?_
<br>--->The requested page will be shown in the _target language_ of the application, which can be set/get via `Yii::app()->language`.
<br>--->If this property is not set explicitly, Yii assumes it to be equal to the _source language_ of the application, which can be set/get via `Yii::app()->sourceLanguage` and defaults to `'en_us'`.
<br>--->These properties can also be set in the main config file, like