1 package eu.svjatoslav.commons.network;
3 import javax.servlet.http.HttpServletRequest;
5 public class LocaleHelper {
7 public static Locale detectLocale(final HttpServletRequest request) {
9 final String sessionLocaleString = (String) request.getSession().getAttribute("locale");
11 Locale sessionLocale = localeFromString(sessionLocaleString);
12 if (sessionLocale == null)
13 sessionLocale = Locale.ENG;
15 final Locale requestLocale = localeFromString(request.getParameter("locale"));
16 if (requestLocale != null)
17 sessionLocale = requestLocale;
19 request.getSession().setAttribute("locale", sessionLocale.asString());
24 public static Locale localeFromString(final String localeString) {
25 for (final Locale locale : Locale.values())
26 if (locale.asString().equals(localeString))