Horde_Registry::setLanguage PHP Method

setLanguage() public method

Sets the language.
public setLanguage ( string $lang = null ) : string
$lang string The language abbreviation.
return string The current language (since 2.5.0).
    public function setLanguage($lang = null)
    {
        if (empty($lang) || !$this->nlsconfig->validLang($lang)) {
            $lang = $this->preferredLang();
        }
        $GLOBALS['session']->set('horde', 'language', $lang);
        $changed = false;
        if (isset($GLOBALS['language'])) {
            if ($GLOBALS['language'] == $lang) {
                return $lang;
            }
            $changed = true;
        }
        $GLOBALS['language'] = $lang;
        $lang_charset = $lang . '.UTF-8';
        if (setlocale(LC_ALL, $lang_charset)) {
            putenv('LC_ALL=' . $lang_charset);
            putenv('LANG=' . $lang_charset);
            putenv('LANGUAGE=' . $lang_charset);
        } else {
            $changed = false;
        }
        if ($changed) {
            $this->rebuild();
            $this->_cache['cfile'] = array();
            foreach ($this->listApps() as $app) {
                if ($this->isAuthenticated(array('app' => $app, 'notransparent' => true))) {
                    $this->callAppMethod($app, 'changeLanguage');
                }
            }
        }
        return $lang;
    }