|
|
|
|
@ -51,25 +51,10 @@ class LocaleSubscriber implements EventSubscriberInterface |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$loadFromDb = $request->getSession()->get('check_locale_from_db', true); |
|
|
|
|
|
|
|
|
|
if (false === $loadFromDb && |
|
|
|
|
$request->getSession()->has('_locale') && |
|
|
|
|
!empty($request->getSession()->get('_locale')) |
|
|
|
|
) { |
|
|
|
|
$locale = $request->getSession()->get('_locale'); |
|
|
|
|
$request->setLocale($locale); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($loadFromDb) { |
|
|
|
|
$locale = $this->getCurrentLanguage($request); |
|
|
|
|
// if no explicit locale has been set on this request, use one from the session |
|
|
|
|
$request->setLocale($locale); |
|
|
|
|
$request->getSession()->set('_locale', $locale); |
|
|
|
|
$request->getSession()->set('check_locale_from_db', false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getCurrentLanguage(Request $request): string |
|
|
|
|
@ -101,7 +86,7 @@ class LocaleSubscriber implements EventSubscriberInterface |
|
|
|
|
if (!empty($course)) { |
|
|
|
|
$courseLocale = $course->getCourseLanguage(); |
|
|
|
|
if (!empty($courseLocale)) { |
|
|
|
|
$localeList['course_lang'] = $platformLocale; |
|
|
|
|
$localeList['course_lang'] = $courseLocale; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -109,7 +94,7 @@ class LocaleSubscriber implements EventSubscriberInterface |
|
|
|
|
// 4. force locale if it was selected from the URL |
|
|
|
|
$localeFromUrl = $request->get('_locale'); |
|
|
|
|
if (!empty($localeFromUrl)) { |
|
|
|
|
$localeList['user_selected_lang'] = $platformLocale; |
|
|
|
|
$localeList['user_selected_lang'] = $localeFromUrl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$priorityList = [ |
|
|
|
|
@ -122,7 +107,7 @@ class LocaleSubscriber implements EventSubscriberInterface |
|
|
|
|
$locale = ''; |
|
|
|
|
foreach ($priorityList as $setting) { |
|
|
|
|
$priority = $this->settingsManager->getSetting(sprintf('language.%s', $setting)); |
|
|
|
|
if (!empty($priority) && isset($localeList[$priority]) && !empty($localeList[$priority])) { |
|
|
|
|
if (!empty($priority) && !empty($localeList[$priority])) { |
|
|
|
|
$locale = $localeList[$priority]; |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
@ -138,7 +123,7 @@ class LocaleSubscriber implements EventSubscriberInterface |
|
|
|
|
'user_selected_lang', |
|
|
|
|
]; |
|
|
|
|
foreach ($priorityList as $setting) { |
|
|
|
|
if (isset($localeList[$setting]) && !empty($localeList[$setting])) { |
|
|
|
|
if (!empty($localeList[$setting])) { |
|
|
|
|
$locale = $localeList[$setting]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|