Revision #2 has been created by le_top on Feb 9, 2015, 8:47:35 PM with the memo:
Added missing method in example
« previous (#1)
Changes
Title
unchanged
Selecting best language based on Browser language and available languages.
Category
unchanged
Tips
Yii version
unchanged
Tags
unchanged
i18n, language, browser
Content
changed
[...]
At the time of writing, the code is not very much tested in production, but some small tests indicate it is ok.
You can call this code in an 'onBeginRequest' [as is suggested in this forum entry](http://www.yiiframework.com/forum/index.php/topic/48501-detecting-browser-language-onbeginrequest/ "Forum entry") or in another location that may be more appropriate for you.
```php
class Utils {
Generally you'ld call 'Utils::setLanguageFromBrowser()'. Change the class name to your likings, or include in your Utility class.
```php
class Utils {
/**
* Set the best language based on browser request.
*/
public static function setLanguageFromBrowser() {
Yii::app()->setLanguage(self::getBestLanguageFromBrowser());
}
/**
* Determine the best language base on browser preferences.
*
* @return string
*/[...]