public function setCurrentLocaleByContext()
    {
        if (function_exists('apply_filters')) {
            // Give a chance for plugins to override this decision
            $locale = null;
            $locale = apply_filters('strata_i18n_set_current_locale_by_context', $locale);
            if (!is_null($locale)) {
                return $this->setLocale($locale);
            }
        }

        if (!is_null($this->currentLocale)) {
            return $this->currentLocale;
        }

        $request = new Request();

        // Under ajax, one could post the value.
        if (Router::isAjax() && $request->hasPost("locale")) {
            $locale = $this->getLocaleByCode($request->post("locale"));
            if (!is_null($locale)) {
                return $this->setLocale($locale);
            }
        }

        if ($request->hasGet("locale")) {
            $locale = $this->getLocaleByCode($request->get("locale"));
            if (!is_null($locale)) {
                return $this->setLocale($locale);
            }
        }

        $inAdmin = function_exists('is_admin') ? is_admin() : false;
        if (!$inAdmin) {
            // This validates all locales but the default one
            $urls = implode('|', $this->getLocaleRegexUrls());

            if (array_key_exists('REQUEST_URI', (array)$_SERVER)) {
                if (preg_match('/^\/('.$urls.')\//i', $_SERVER['REQUEST_URI'], $match)) {
                    $locale = $this->getLocaleByUrl($match[1]);
                    if (!is_null($locale)) {
                        return $this->setLocale($locale);
                    }
                // Also validates for lack of locale code, meaning
                // a possible default locale match when no ajax-ing.
                } elseif (preg_match('/^(?:(?!'.$urls.'))\/?/i', $_SERVER['REQUEST_URI'])) {
                    $locale = $this->getDefaultLocale();
                    if (!is_null($locale)) {
                        return $this->setLocale($locale);
                    }
                }
            }
        }

        if ($this->hasLocaleInSession()) {
            $locale = $this->getLocaleInSession();
            if (!is_null($locale)) {
                return $this->setLocale($locale);
            }
        }

        if ($this->hasDefaultLocale()) {
            return $this->setLocale($this->getDefaultLocale());
        }
    }