roundcubemail/program/lib/Roundcube/rcube.php
protected function language_prop($lang)
    {
        static $rcube_languages, $rcube_language_aliases;

        // user HTTP_ACCEPT_LANGUAGE if no language is specified
        if (empty($lang) || $lang == 'auto') {
            $accept_langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
            $lang         = $accept_langs[0];

            if (preg_match('/^([a-z]+)[_-]([a-z]+)$/i', $lang, $m)) {
                $lang = $m[1] . '_' . strtoupper($m[2]);
            }
        }

        if (empty($rcube_languages)) {
            @include(RCUBE_LOCALIZATION_DIR . 'index.inc');
        }

        // check if we have an alias for that language
        if (!isset($rcube_languages[$lang]) && isset($rcube_language_aliases[$lang])) {
            $lang = $rcube_language_aliases[$lang];
        }
        // try the first two chars
        else if (!isset($rcube_languages[$lang])) {
            $short = substr($lang, 0, 2);

            // check if we have an alias for the short language code
            if (!isset($rcube_languages[$short]) && isset($rcube_language_aliases[$short])) {
                $lang = $rcube_language_aliases[$short];
            }
            // expand 'nn' to 'nn_NN'
            else if (!isset($rcube_languages[$short])) {
                $lang = $short.'_'.strtoupper($short);
            }
        }

        if (!isset($rcube_languages[$lang]) || !is_dir(RCUBE_LOCALIZATION_DIR . $lang)) {
            $lang = 'en_US';
        }

        return $lang;
    }
protected function language_prop($lang)
    {
        static $rcube_languages, $rcube_language_aliases;

        // user HTTP_ACCEPT_LANGUAGE if no language is specified
        if (empty($lang) || $lang == 'auto') {
            $accept_langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
            $lang         = $accept_langs[0];

            if (preg_match('/^([a-z]+)[_-]([a-z]+)$/i', $lang, $m)) {
                $lang = $m[1] . '_' . strtoupper($m[2]);
            }
        }

        if (empty($rcube_languages)) {
            @include(RCUBE_LOCALIZATION_DIR . 'index.inc');
        }

        // check if we have an alias for that language
        if (!isset($rcube_languages[$lang]) && isset($rcube_language_aliases[$lang])) {
            $lang = $rcube_language_aliases[$lang];
        }
        // try the first two chars
        else if (!isset($rcube_languages[$lang])) {
            $short = substr($lang, 0, 2);

            // check if we have an alias for the short language code
            if (!isset($rcube_languages[$short]) && isset($rcube_language_aliases[$short])) {
                $lang = $rcube_language_aliases[$short];
            }
            // expand 'nn' to 'nn_NN'
            else if (!isset($rcube_languages[$short])) {
                $lang = $short.'_'.strtoupper($short);
            }
        }

        if (!isset($rcube_languages[$lang]) || !is_dir(RCUBE_LOCALIZATION_DIR . $lang)) {
            $lang = 'en_US';
        }

        return $lang;
    }
protected function language_prop ( $ lang ) { static $ rcube_languages , $ rcube_language_aliases ; // user HTTP_ACCEPT_LANGUAGE if no language is specified if ( empty ( $ lang ) || $ lang == 'auto' ) { $ accept_langs = explode ( ',' , $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ; $ lang = $ accept_langs [ 0 ] ; if ( preg_match ( '/^([a-z]+)[_-]([a-z]+)$/i' , $ lang , $ m ) ) { $ lang = $ m [ 1 ] . '_' . strtoupper ( $ m [ 2 ] ) ; } } if ( empty ( $ rcube_languages ) ) { @ include ( RCUBE_LOCALIZATION_DIR . 'index.inc' ) ; } // check if we have an alias for that language if ( ! isset ( $ rcube_languages [ $ lang ] ) && isset ( $ rcube_language_aliases [ $ lang ] ) ) { $ lang = $ rcube_language_aliases [ $ lang ] ; } // try the first two chars else if ( ! isset ( $ rcube_languages [ $ lang ] ) ) { $ short = substr ( $ lang , 0 , 2 ) ; // check if we have an alias for the short language code if ( ! isset ( $ rcube_languages [ $ short ] ) && isset ( $ rcube_language_aliases [ $ short ] ) ) { $ lang = $ rcube_language_aliases [ $ short ] ; } // expand 'nn' to 'nn_NN' else if ( ! isset ( $ rcube_languages [ $ short ] ) ) { $ lang = $ short . '_' . strtoupper ( $ short ) ; } } if ( ! isset ( $ rcube_languages [ $ lang ] ) || ! is_dir ( RCUBE_LOCALIZATION_DIR . $ lang ) ) { $ lang = 'en_US' ; } return $ lang ; }
Check the given string and return a valid language code

@param string $lang Language code

@return string Valid language code
Check the given string and return a valid language code