protected function init($lookupAlternative)
    {
        // 1st try to retrieve previously stored preferences from session (fastest store) and cookie
        $userPreferences = $this->readPreferences();

        // Retrieving of stored preferences failed ... 
        if (null === $userPreferences) {
            // ... now try to detect
            $userPreferences = $this->detectPreferences();

            // check if retrieved locale exists
            if (false === $userPreferences || !in_array($userPreferences['locale'], self::$availableLocales)) {

                // look in the list of retrieved locales for the next matching one (alternative = true)
                if ($lookupAlternative) {
                    // reset the one found
                    $userPreferences = null;

                    // get count of found locales
                    $countDetectedLocales = count($this->detectedLocales);

                    // iterate over all detected locales to find the first matching one
                    for ($i = 1; $i < $countDetectedLocales; ++$i) {
                        // check if we got a matching locale
                        if (in_array($this->detectedLocales[$i]['locale'], self::$availableLocales)) {
                            $userPreferences['locale']   = $this->detectedLocales[$i]['locale'];
                            $userPreferences['weight']   = $this->detectedLocales[$i]['weight'];
                            $userPreferences['language'] = $this->detectedLanguages[$i];
                            $userPreferences['country']  = $this->detectedCountries[$i];

                            // leave loop
                            break;
                        }
                    }
                }

                // if we should'nt lookup an alternative OR no locale was detected -> use systems default
                if (!$lookupAlternative || $userPreferences === null) {
                    // or if we use the systems default locale if auto-detect fails
                    $userPreferences['locale']   = self::$default['locale'];
                    $userPreferences['weight']   = self::$default['weight'];
                    $userPreferences['language'] = self::$default['language'];
                    $userPreferences['country']  = self::$default['country'];
                }
            }

            // we did change something
            $this->dirty = true;
        }

        // store retrieved data in class and afterwards in store(s)
        $this->locale   = $userPreferences['locale'];
        $this->weight   = $userPreferences['weight'];
        $this->language = $userPreferences['language'];
        $this->country  = $userPreferences['country'];

        // finally store in defines storages
        if ($this->dirty) {
            $this->writePreferences($userPreferences);
        }

        // init successfully done (means locale, language and country are set to an existing locale)
        return true;
    }
protected function init($lookupAlternative)
    {
        // 1st try to retrieve previously stored preferences from session (fastest store) and cookie
        $userPreferences = $this->readPreferences();

        // Retrieving of stored preferences failed ... 
        if (null === $userPreferences) {
            // ... now try to detect
            $userPreferences = $this->detectPreferences();

            // check if retrieved locale exists
            if (false === $userPreferences || !in_array($userPreferences['locale'], self::$availableLocales)) {

                // look in the list of retrieved locales for the next matching one (alternative = true)
                if ($lookupAlternative) {
                    // reset the one found
                    $userPreferences = null;

                    // get count of found locales
                    $countDetectedLocales = count($this->detectedLocales);

                    // iterate over all detected locales to find the first matching one
                    for ($i = 1; $i < $countDetectedLocales; ++$i) {
                        // check if we got a matching locale
                        if (in_array($this->detectedLocales[$i]['locale'], self::$availableLocales)) {
                            $userPreferences['locale']   = $this->detectedLocales[$i]['locale'];
                            $userPreferences['weight']   = $this->detectedLocales[$i]['weight'];
                            $userPreferences['language'] = $this->detectedLanguages[$i];
                            $userPreferences['country']  = $this->detectedCountries[$i];

                            // leave loop
                            break;
                        }
                    }
                }

                // if we should'nt lookup an alternative OR no locale was detected -> use systems default
                if (!$lookupAlternative || $userPreferences === null) {
                    // or if we use the systems default locale if auto-detect fails
                    $userPreferences['locale']   = self::$default['locale'];
                    $userPreferences['weight']   = self::$default['weight'];
                    $userPreferences['language'] = self::$default['language'];
                    $userPreferences['country']  = self::$default['country'];
                }
            }

            // we did change something
            $this->dirty = true;
        }

        // store retrieved data in class and afterwards in store(s)
        $this->locale   = $userPreferences['locale'];
        $this->weight   = $userPreferences['weight'];
        $this->language = $userPreferences['language'];
        $this->country  = $userPreferences['country'];

        // finally store in defines storages
        if ($this->dirty) {
            $this->writePreferences($userPreferences);
        }

        // init successfully done (means locale, language and country are set to an existing locale)
        return true;
    }
protected function init ( $ lookupAlternative ) { // 1st try to retrieve previously stored preferences from session (fastest store) and cookie $ userPreferences = $ this -> readPreferences ( ) ; // Retrieving of stored preferences failed ...  if ( null === $ userPreferences ) { // ... now try to detect $ userPreferences = $ this -> detectPreferences ( ) ; // check if retrieved locale exists if ( false === $ userPreferences || ! in_array ( $ userPreferences [ 'locale' ] , self :: $ availableLocales ) ) { // look in the list of retrieved locales for the next matching one (alternative = true) if ( $ lookupAlternative ) { // reset the one found $ userPreferences = null ; // get count of found locales $ countDetectedLocales = count ( $ this -> detectedLocales ) ; // iterate over all detected locales to find the first matching one for ( $ i = 1 ; $ i < $ countDetectedLocales ; ++ $ i ) { // check if we got a matching locale if ( in_array ( $ this -> detectedLocales [ $ i ] [ 'locale' ] , self :: $ availableLocales ) ) { $ userPreferences [ 'locale' ] = $ this -> detectedLocales [ $ i ] [ 'locale' ] ; $ userPreferences [ 'weight' ] = $ this -> detectedLocales [ $ i ] [ 'weight' ] ; $ userPreferences [ 'language' ] = $ this -> detectedLanguages [ $ i ] ; $ userPreferences [ 'country' ] = $ this -> detectedCountries [ $ i ] ; // leave loop break ; } } } // if we should'nt lookup an alternative OR no locale was detected -> use systems default if ( ! $ lookupAlternative || $ userPreferences === null ) { // or if we use the systems default locale if auto-detect fails $ userPreferences [ 'locale' ] = self :: $ default [ 'locale' ] ; $ userPreferences [ 'weight' ] = self :: $ default [ 'weight' ] ; $ userPreferences [ 'language' ] = self :: $ default [ 'language' ] ; $ userPreferences [ 'country' ] = self :: $ default [ 'country' ] ; } } // we did change something $ this -> dirty = true ; } // store retrieved data in class and afterwards in store(s) $ this -> locale = $ userPreferences [ 'locale' ] ; $ this -> weight = $ userPreferences [ 'weight' ] ; $ this -> language = $ userPreferences [ 'language' ] ; $ this -> country = $ userPreferences [ 'country' ] ; // finally store in defines storages if ( $ this -> dirty ) { $ this -> writePreferences ( $ userPreferences ) ; } // init successfully done (means locale, language and country are set to an existing locale) return true ; }
This method is intend to initialize and start the detection.

@param bool $lookupAlternative TRUE to try to find a matching locale, FALSE to use systems default as fallback

@author Benjamin Carl <opensource@clickalicious.de>

@return bool TRUE if detection was successful
This method is intend to initialize and start the detection .