# HG changeset patch # User Mike Becker # Date 1514313931 -3600 # Node ID bb594abac7967575634bcd2161aa1f86979d7007 # Parent 2b270c714678dc3b2aa52c1163b73036e14ce6db language selector completed diff -r 2b270c714678 -r bb594abac796 src/java/de/uapcore/lightpit/AbstractLightPITServlet.java --- a/src/java/de/uapcore/lightpit/AbstractLightPITServlet.java Tue Dec 26 19:18:32 2017 +0100 +++ b/src/java/de/uapcore/lightpit/AbstractLightPITServlet.java Tue Dec 26 19:45:31 2017 +0100 @@ -243,7 +243,9 @@ session.setAttribute(Constants.SESSION_ATTR_LANGUAGE, sessionLocale); LOG.debug("Settng language for new session {}: {}", session.getId(), sessionLocale.getDisplayLanguage()); } else { - LOG.trace("Continuing session {} with language {}", session.getId(), session.getAttribute(Constants.SESSION_ATTR_LANGUAGE)); + Locale sessionLocale = (Locale) session.getAttribute(Constants.SESSION_ATTR_LANGUAGE); + resp.setLocale(sessionLocale); + LOG.trace("Continuing session {} with language {}", session.getId(), sessionLocale); } req.setAttribute(Constants.REQ_ATTR_PATH, Functions.fullPath(req)); diff -r 2b270c714678 -r bb594abac796 src/java/de/uapcore/lightpit/modules/LanguageModule.java --- a/src/java/de/uapcore/lightpit/modules/LanguageModule.java Tue Dec 26 19:18:32 2017 +0100 +++ b/src/java/de/uapcore/lightpit/modules/LanguageModule.java Tue Dec 26 19:45:31 2017 +0100 @@ -30,6 +30,7 @@ import de.uapcore.lightpit.LightPITModule; import de.uapcore.lightpit.AbstractLightPITServlet; +import de.uapcore.lightpit.Constants; import de.uapcore.lightpit.Functions; import de.uapcore.lightpit.HttpMethod; import javax.servlet.annotation.WebServlet; @@ -59,7 +60,7 @@ private static final Logger LOG = LoggerFactory.getLogger(LanguageModule.class); - private List languages = new ArrayList<>(); + private final List languages = new ArrayList<>(); @Override public void init() throws ServletException { @@ -84,6 +85,12 @@ LOG.warn("Context parameter 'available-languges' not found. Only english will be available."); } } + + @Override + public void destroy() { + super.destroy(); + languages.clear(); + } @RequestMapping(method = HttpMethod.GET) public ResponseType handle(HttpServletRequest req, HttpServletResponse resp) { @@ -95,4 +102,17 @@ setDynamicFragment(req, "language"); return ResponseType.HTML_FULL; } + + @RequestMapping(method = HttpMethod.POST) + public ResponseType switchLanguage(HttpServletRequest req, HttpServletResponse resp) { + + Optional chosenLanguage = Optional.ofNullable(req.getParameter("language")) + .map(Locale::forLanguageTag) + .filter((l) -> !l.getLanguage().isEmpty()); + + chosenLanguage.ifPresent((l) -> req.getSession().setAttribute(Constants.SESSION_ATTR_LANGUAGE, l)); + chosenLanguage.ifPresent(resp::setLocale); + + return handle(req, resp); + } } diff -r 2b270c714678 -r bb594abac796 src/java/de/uapcore/lightpit/resources/localization/language.properties --- a/src/java/de/uapcore/lightpit/resources/localization/language.properties Tue Dec 26 19:18:32 2017 +0100 +++ b/src/java/de/uapcore/lightpit/resources/localization/language.properties Tue Dec 26 19:45:31 2017 +0100 @@ -24,3 +24,4 @@ menuLabel = Languages submit = Switch language browserLanguage = Browser language +browserLanguageNotAvailable = Browser language not available. diff -r 2b270c714678 -r bb594abac796 src/java/de/uapcore/lightpit/resources/localization/language_de.properties --- a/src/java/de/uapcore/lightpit/resources/localization/language_de.properties Tue Dec 26 19:18:32 2017 +0100 +++ b/src/java/de/uapcore/lightpit/resources/localization/language_de.properties Tue Dec 26 19:45:31 2017 +0100 @@ -24,3 +24,4 @@ menuLabel = Sprache submit = Sprache ausw\u00e4hlen browserLanguage = Browsersprache +browserLanguageNotAvailable = Browsersprache nicht verf\u00fcgbar. diff -r 2b270c714678 -r bb594abac796 web/WEB-INF/dynamic_fragments/language.jsp --- a/web/WEB-INF/dynamic_fragments/language.jsp Tue Dec 26 19:18:32 2017 +0100 +++ b/web/WEB-INF/dynamic_fragments/language.jsp Tue Dec 26 19:45:31 2017 +0100 @@ -31,16 +31,17 @@ -
+ + + "/>
-
diff -r 2b270c714678 -r bb594abac796 web/WEB-INF/jsp/full.jsp --- a/web/WEB-INF/jsp/full.jsp Tue Dec 26 19:18:32 2017 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -<%-- -DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - -Copyright 2017 Mike Becker. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---%> -<%@page contentType="text/html" pageEncoding="UTF-8" trimDirectiveWhitespaces="true" %> -<%@page import="de.uapcore.lightpit.Constants" %> -<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> -<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> - -<%-- Define an alias for the main menu --%> - - -<%-- Define an alias for the module info --%> - - - - - - - LightPIT - - <fmt:bundle basename="${moduleInfo.bundleBaseName}"> - <fmt:message key="${moduleInfo.titleKey}" /> - </fmt:bundle> - - - - - - - -
- <%-- Resource keys should be rooted in the specific bundle for this module. --%> - - TODO: load fragment - -
- - diff -r 2b270c714678 -r bb594abac796 web/WEB-INF/jsp/html_full.jsp --- a/web/WEB-INF/jsp/html_full.jsp Tue Dec 26 19:18:32 2017 +0100 +++ b/web/WEB-INF/jsp/html_full.jsp Tue Dec 26 19:45:31 2017 +0100 @@ -42,6 +42,11 @@ <%-- Define an alias for the module info --%> +<%-- Apply the session locale (should always be present, but check nevertheless) --%> + + + + @@ -78,7 +83,8 @@
- + +
diff -r 2b270c714678 -r bb594abac796 web/language.css --- a/web/language.css Tue Dec 26 19:18:32 2017 +0100 +++ b/web/language.css Tue Dec 26 19:45:31 2017 +0100 @@ -37,3 +37,10 @@ input { margin: .5em; } + +span.blNA { + margin: .5em; + color: red; + font-style: italic; + font-size: smaller; +}