From 86f56dd22b09c1cfc79518e9c416c4dba88ed2e1 Mon Sep 17 00:00:00 2001 From: Kostas Dizas <254960+kostasdizas@users.noreply.github.com> Date: Tue, 11 Jun 2019 20:35:31 +0100 Subject: [PATCH] Added locale and text direction to html templates --- app/Http/Middleware/Localization.php | 14 +++++++++++++- resources/views/base.blade.php | 2 +- resources/views/books/export.blade.php | 2 +- resources/views/chapters/export.blade.php | 2 +- resources/views/pages/export.blade.php | 2 +- .../views/vendor/notifications/email.blade.php | 2 +- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/Http/Middleware/Localization.php b/app/Http/Middleware/Localization.php index ff5526cc7..753fe438e 100644 --- a/app/Http/Middleware/Localization.php +++ b/app/Http/Middleware/Localization.php @@ -59,6 +59,8 @@ class Localization $locale = setting()->getUser(user(), 'language', $defaultLang); } + config()->set('app.lang', $this->getLocaleIso($locale)); + // Set text direction if (in_array($locale, $this->rtlLocales)) { config()->set('app.rtl', true); @@ -88,6 +90,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. @@ -95,7 +107,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'); diff --git a/resources/views/base.blade.php b/resources/views/base.blade.php index 367a2cd8b..971a90340 100644 --- a/resources/views/base.blade.php +++ b/resources/views/base.blade.php @@ -1,5 +1,5 @@ - +