]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Middleware/Localization.php
No need to save page
[bookstack] / app / Http / Middleware / Localization.php
index e65b417d5079f43535930ab77d86a915d80ca8b8..8fe4ca9906c7f62ab61ece1df2f18ce5d0150f08 100644 (file)
@@ -31,14 +31,13 @@ class Localization
         'nl' => 'nl_NL',
         'pl' => 'pl_PL',
         'pt_BR' => 'pt_BR',
-        'pt_BR' => 'pt_BR',
         'ru' => 'ru',
         'sk' => 'sk_SK',
         'sv' => 'sv_SE',
         'uk' => 'uk_UA',
-        'uk' => 'uk_UA',
         'zh_CN' => 'zh_CN',
         'zh_TW' => 'zh_TW',
+        'tr' => 'tr_TR',
     ];
 
     /**
@@ -51,6 +50,7 @@ class Localization
     public function handle($request, Closure $next)
     {
         $defaultLang = config('app.locale');
+        config()->set('app.default_locale', $defaultLang);
 
         if (user()->isDefault() && config('app.auto_detect_locale')) {
             $locale = $this->autoDetectLocale($request, $defaultLang);
@@ -58,13 +58,13 @@ class Localization
             $locale = setting()->getUser(user(), 'language', $defaultLang);
         }
 
+        config()->set('app.lang', str_replace('_', '-', $this->getLocaleIso($locale)));
+
         // Set text direction
         if (in_array($locale, $this->rtlLocales)) {
             config()->set('app.rtl', true);
         }
 
-
-
         app()->setLocale($locale);
         Carbon::setLocale($locale);
         $this->setSystemDateLocale($locale);
@@ -89,6 +89,16 @@ class Localization
         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.
@@ -96,7 +106,7 @@ class Localization
      */
     protected function setSystemDateLocale(string $locale)
     {
-        $systemLocale = $this->localeMap[$locale] ?? $locale;
+        $systemLocale = $this->getLocaleIso($locale);
         $set = setlocale(LC_TIME, $systemLocale);
         if ($set === false) {
             setlocale(LC_TIME, $systemLocale . '.utf8');