Overrides locale configuration and storages it to configured storages.

@param array $preferences The preferences to store

@author Benjamin Carl <opensource@clickalicious.de>

@return Doozr_I18n_Service_Detector Instance for chaining
359675
public function override(array $preferences)
    {

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

        $this->writePreferences($preferences);

        return $this;
    }
718288
public function setLocale($locale)
    {
        $this->parentSetLocale($locale);
        $this->formatCache = [];
        $this->dateFormatCache = [];
        return $this;
    }
166916
public static function setLocale($default = null)
    {
        $locale = self::extractLocale($default);
        Logger::log('Set locale to project [' . $locale . ']');
        // Load translations
        putenv("LC_ALL=" . $locale);
        setlocale(LC_ALL, $locale);
        // Load the locale path
        $locale_path = BASE_DIR . DIRECTORY_SEPARATOR . 'locale';
        Logger::log('Set locale dir ' . $locale_path);
        GeneratorHelper::createDir($locale_path);
        bindtextdomain('translations', $locale_path);
        textdomain('translations');
        bind_textdomain_codeset('translations', 'UTF-8');
        Security::getInstance()->setSessionKey(I18nHelper::PSFS_SESSION_LANGUAGE_KEY, substr($locale, 0, 2));
    }
1249335
protected function setLocale($locale)
    {
        if (is_null($locale) || $locale === 'auto') {
            $locale = app()->getLocale();
        }

        $this->locale = $locale;

        return $this;
    }
1300146
public function setLocale()
    {
        // Initialize Locale if set and configured.
        if ($this['language']->enabled() && $this['config']->get('system.languages.override_locale')) {
            $language = $this['language']->getLanguage();
            setlocale(LC_ALL, \strlen($language) < 3 ? ($language . '_' . strtoupper($language)) : $language);
        } elseif ($this['config']->get('system.default_locale')) {
            setlocale(LC_ALL, $this['config']->get('system.default_locale'));
        }
    }
1333267
public void setPreferredLocale(Locale preferredLocale) {
        if (!Objects.equals(this.preferredLocale, preferredLocale)) {
            this.preferredLocale = preferredLocale;
            this.manifestXml = null;
            this.apkMeta = null;
            this.manifestParsed = false;
        }
    }
1096885
protected function initDefaultConfig(array $options) {
        $configLocation = isset($options['app.dir.config']) ? $options['app.dir.config'] : getcwd();
        $config = new DefaultConfig($configLocation);
        unset($options['app.dir.config']);

        $rootDir = isset($options['app.dir.root']) ? $options['app.dir.root'] : getcwd();
        unset($options['app.dir.root']);

        // copy remaining config options to the DefaultConfig
        foreach ($options as $name => $value) {
            $config->set($name, $value);
        }

        // set root directory and expand relative app directories
        $config->set('app.dir.root', $rootDir);
        $this->expandAppDirs($config, $rootDir);

        return $config;
    }
740120
protected function configureOptions(array $options = [])
    {
        try {
            $resolver = new OptionsResolver();
            // We set all global options as defined options, otherwise we would get a lot of exceptions
            $resolver->setDefined(array_keys($options));
            $this->resolveOptions($resolver);
            return $resolver->resolve($options);
        } catch (MissingOptionsException $e) {
            throw new InvalidConfigurationException($e->getMessage(), $e->getCode());
        } catch (InvalidOptionsException $e) {
            throw new InvalidConfigurationException($e->getMessage(), $e->getCode());
        } catch (NoConfigurationException $e) {
            throw new InvalidConfigurationException($e->getMessage(), $e->getCode());
        } catch (NoSuchOptionException $e) {
            throw new InvalidConfigurationException($e->getMessage(), $e->getCode());
        } catch (OptionDefinitionException $e) {
            throw new InvalidConfigurationException($e->getMessage(), $e->getCode());
        } catch (UndefinedOptionsException $e) {
            throw new InvalidConfigurationException($e->getMessage(), $e->getCode());
        } catch (ExceptionInterface $e) {
            throw new InvalidConfigurationException($e->getMessage(), $e->getCode());
        }
    }
977911
public function chooseLocale($preferred) {
        $available_locales   = array_flip($this->locales);
        $available_languages = array();
        foreach($available_locales as $key => $value) {
            $available_languages[substr($key, 0, 2)] = $key;
        }

        preg_match_all('~([\w-]+)(?:[^,\d]+([\d.]+))?~', $preferred, $matches, PREG_SET_ORDER);

        $matched_locales = array();
        foreach($matches as $match) {
            $temp  = explode('-', $match[1]);
            $lang  = array_shift($temp);
            $value = isset($match[2]) ? (float)$match[2] : 1.0;

            // Full match (language_territory)?
            if(isset($available_locales[$match[1]]) && !isset($matched_locales[$match[1]])) {
                $matched_locales[$match[1]] = $value;
            }

            // Language match (without territory)?
            if(isset($available_languages[$lang]) && !isset($matched_locales[$available_languages[$lang]])) {
                $matched_locales[$available_languages[$lang]] = $value - 0.05;
            }
        }

        if(count($matched_locales)) {
            arsort($matched_locales);
            $this->setLocale(key($matched_locales));
            return true;
        } else {
            $this->setLocale($this->locale_default);
            return false;
        }
    }
386315
public static final function configuration(string $locale) {
    if (!empty($locale)) {
      Lang::$locale = $locale;
    } else {
      Lang::$locale = Lang::STANDARD_LOCALE;
    }
    return null;
  }
369208
public function switchLocale($locale)
    {
        if (in_array($locale, $this->config['locales'])) {
            app('session')->put('administrator_locale', $locale);
        }

        return redirect()->back();
    }
440829
public function setLocale($localization = null)
    {
        $locale = Config::get('global.config', 'locale');
        if (!is_null($localization)) {
            $locale = $localization;
        }

        $fallbackLocale = Config::get('global.config', 'fallback.locale');
        $trans = $this->getTranslator();

        return $trans->setRootDirectory($this->container->get('app.path').DS.'Resources'.DS)
              ->setFallback($fallbackLocale)
              ->locale($locale);
    }
439066
private function convertSingleEntryToDefault(array $locales): array
    {
        foreach ($locales as $group => $segments) {
            // If single locale is passed, it's considered the default for this group
            if (!is_array($segments)) {
                $locales[$group] = $segments = ['/' => $segments];
            }
        }

        return $locales;
    }
568383
public function setDefault($locale)
    {
        // Make sure locale is available (set it on list if not set yet)
        $this->addLocale($locale);

        // Mark as default locale
        $this->default = $this->findByLocale($locale);

        // Mark as current locale (if none set yet)
        if (!$this->getActive()) {
            $this->setActive($this->default);
        }

        return $this;
    }
405711
public function getDefaultMainWebspaceForLocale($searchedLocale)
    {
        if (array_key_exists($searchedLocale, $this->defaultMainWebspace)) {
            return $this->defaultMainWebspace[$searchedLocale];
        }

        if (array_key_exists('default', $this->defaultMainWebspace)) {
            return $this->defaultMainWebspace['default'];
        }

        throw new InvalidConfigurationException('No configured default main webspace for locale "' . $searchedLocale . '" not found.');
    }
230089
public function setLocale($locale)
    {
        $this->locale = $locale;

        $this->getContentRoute()->setLocale($locale);

        return $this;
    }
155350
function config_form($preferences){
        global $USER, $OUTPUT, $CFG;
        $string = '';

        $choices = array();
        $choices['0'] = get_string('textformat');
        $choices['1'] = get_string('htmlformat');
        $current = $preferences->mailformat;
        $string .= $OUTPUT->container(html_writer::label(get_string('emailformat'), 'mailformat'));
        $string .= $OUTPUT->container(html_writer::select($choices, 'mailformat', $current, false, array('id' => 'mailformat')));
        $string .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'userid', 'value' => $USER->id));

        if (!empty($CFG->allowusermailcharset)) {
            $choices = array();
            $charsets = get_list_of_charsets();
            if (!empty($CFG->sitemailcharset)) {
                $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
            } else {
                $choices['0'] = get_string('site').' (UTF-8)';
            }
            $choices = array_merge($choices, $charsets);
            $current = $preferences->mailcharset;
            $string .= $OUTPUT->container(html_writer::label(get_string('emailcharset'), 'mailcharset'));
            $string .= $OUTPUT->container(
                html_writer::select($choices, 'preference_mailcharset', $current, false, array('id' => 'mailcharset'))
            );
        }

        if (!empty($CFG->messagingallowemailoverride)) {
            $inputattributes = array('size' => '30', 'name' => 'email_email', 'value' => $preferences->email_email,
                    'id' => 'email_email');
            $string .= html_writer::label(get_string('email', 'message_email'), 'email_email');
            $string .= $OUTPUT->container(html_writer::empty_tag('input', $inputattributes));

            if (empty($preferences->email_email) && !empty($preferences->userdefaultemail)) {
                $string .= $OUTPUT->container(get_string('ifemailleftempty', 'message_email', $preferences->userdefaultemail));
            }

            if (!empty($preferences->email_email) && !validate_email($preferences->email_email)) {
                $string .= $OUTPUT->container(get_string('invalidemail'), 'error');
            }

            $string .= '<br/>';
        }

        return $string;
    }