code: protected function detectAndApplyLanguage() {
          if ($this->config('autodetect', true)) {
              /** @var LanguageDetector $detector */
              $detector = $this->getLanguageDetector();
              $language = $detector->getLanguageFromCookie();
              if (!$language || strlen($language) > 5 || !in_array($language, $this->getSupportedLanguages(), true)) {
                  $language = $detector->getDriver()->detect();
                  if (!$language || strlen($language) > 5) {
                      $language = $this->request->getDefaultLocale();
                  }
              }
              $this->applyNewLanguage($language, true);
          }
      }
docs: Detect and apply language for the application.
  Failsafe