X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/3286f29a61833327b5701b28db626d0a480b07f9..refs/pull/2238/head:/app/Http/Middleware/Localization.php diff --git a/app/Http/Middleware/Localization.php b/app/Http/Middleware/Localization.php index e65b417d5..d24e8a9b5 100644 --- a/app/Http/Middleware/Localization.php +++ b/app/Http/Middleware/Localization.php @@ -11,7 +11,7 @@ class Localization * Array of right-to-left locales * @var array */ - protected $rtlLocales = ['ar']; + protected $rtlLocales = ['ar', 'he']; /** * Map of BookStack locale names to best-estimate system locale names. @@ -19,26 +19,30 @@ class Localization */ protected $localeMap = [ 'ar' => 'ar', + 'da' => 'da_DK', 'de' => 'de_DE', 'de_informal' => 'de_DE', 'en' => 'en_GB', 'es' => 'es_ES', 'es_AR' => 'es_AR', 'fr' => 'fr_FR', + 'he' => 'he_IL', 'it' => 'it_IT', 'ja' => 'ja', - 'kr' => 'ko_KR', + 'ko' => 'ko_KR', 'nl' => 'nl_NL', 'pl' => 'pl_PL', - 'pt_BR' => 'pt_BR', + 'pt' => 'pl_PT', 'pt_BR' => 'pt_BR', 'ru' => 'ru', 'sk' => 'sk_SK', + 'sl' => 'sl_SI', 'sv' => 'sv_SE', 'uk' => 'uk_UA', - 'uk' => 'uk_UA', + 'vi' => 'vi_VN', 'zh_CN' => 'zh_CN', 'zh_TW' => 'zh_TW', + 'tr' => 'tr_TR', ]; /** @@ -51,6 +55,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 +63,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 +94,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 +111,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');