Difference between #1 and #2 of
Selecting best language based on Browser language and available languages.

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
*/
[...]
2 0
1 follower
Viewed: 15 521 times
Version: 1.1
Category: Tips
Written by: le_top
Last updated by: le_top
Created on: Feb 9, 2015
Last updated: 9 years ago
Update Article

Revisions

View all history