+
+ /**
+ * Autodetect the visitors locale by matching locales in their headers
+ * against the locales supported by BookStack.
+ * @param Request $request
+ * @param string $default
+ * @return string
+ */
+ protected function autoDetectLocale(Request $request, string $default)
+ {
+ $availableLocales = config('app.locales');
+ foreach ($request->getLanguages() as $lang) {
+ if (in_array($lang, $availableLocales)) {
+ return $lang;
+ }
+ }
+ return $default;
+ }
+
+ /**
+ * Get the ISO version of a BookStack language name
+ * @param string $locale
+ * @return string
+ */
+ public function getLocaleIso(string $locale)
+ {
+ return $this->localeMap[$locale] ?? $locale;
+ }
+
+ /**
+ * Set the system date locale for localized date formatting.
+ * Will try both the standard locale name and the UTF8 variant.
+ * @param string $locale
+ */
+ protected function setSystemDateLocale(string $locale)
+ {
+ $systemLocale = $this->getLocaleIso($locale);
+ $set = setlocale(LC_TIME, $systemLocale);
+ if ($set === false) {
+ setlocale(LC_TIME, $systemLocale . '.utf8');
+ }
+ }