public static function setApplicationLanguage()
    {
        $app = Yii::app();

        // If someone has hard-coded the app-language, return it instead
        if ($app->language != 'en_US')
            return $app->language;

        // If the language is set via POST, accept it
        if (php_sapi_name()  == 'cli')
            return $app->language;

        if (Cii::get($_POST, '_lang', false))
            $app->language = $_POST['_lang'];
        else if (isset($app->session['_lang']) && $app->session['_lang'] != NULL)
            $app->language = $app->session['_lang'];
        else
            $app->language = Yii::app()->getRequest()->getPreferredLanguage();


        Yii::app()->language = $app->session['_lang'] = $app->language;
        return $app->language;
    }