fixes response locale not set for new sessions

Tue, 03 Aug 2021 12:22:10 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 03 Aug 2021 12:22:10 +0200
changeset 208
785820da6485
parent 207
479dd7993ef9
child 209
c9c6abf167c7

fixes response locale not set for new sessions

src/main/kotlin/de/uapcore/lightpit/AbstractServlet.kt file | annotate | diff | comparison | revisions
--- a/src/main/kotlin/de/uapcore/lightpit/AbstractServlet.kt	Mon Aug 02 17:04:17 2021 +0200
+++ b/src/main/kotlin/de/uapcore/lightpit/AbstractServlet.kt	Tue Aug 03 12:22:10 2021 +0200
@@ -104,6 +104,7 @@
             val reqLocale = req.locale
             val sessionLocale = if (availableLanguages.contains(reqLocale)) reqLocale else availableLanguages.first()
             session.setAttribute(Constants.SESSION_ATTR_LANGUAGE, sessionLocale)
+            resp.locale = sessionLocale
             logger().debug(
                 "Setting language for new session {}: {}", session.id, sessionLocale.displayLanguage
             )
@@ -176,7 +177,7 @@
     protected fun availableLanguages(): List<Locale> {
         val langTags = servletContext.getInitParameter(Constants.CTX_ATTR_LANGUAGES)?.split(",")?.map(String::trim) ?: emptyList()
         val locales = langTags.map(Locale::forLanguageTag).filter { it.language.isNotEmpty() }
-        return if (locales.isEmpty()) listOf(Locale.ENGLISH) else locales
+        return locales.ifEmpty { listOf(Locale.ENGLISH) }
     }
 
 }

mercurial