protected Locale resolveLocale(@Nullable Locale requestLocale) { Map<String, Locale> locales = globalConfig.getAvailableLocales(); if (globalConfig.getLocaleSelectVisible()) { String lastLocale = getCookieValue(COOKIE_LOCALE); if (lastLocale != null) { for (Locale locale : locales.values()) { if (locale.toLanguageTag().equals(lastLocale)) { return locale; } } } } if (requestLocale != null) { Locale requestTrimmedLocale = messageTools.trimLocale(requestLocale); if (locales.containsValue(requestTrimmedLocale)) { return requestTrimmedLocale; } // if not found and application locale contains country, try to match by language only if (!StringUtils.isEmpty(requestLocale.getCountry())) { Locale appLocale = Locale.forLanguageTag(requestLocale.getLanguage()); for (Locale locale : locales.values()) { if (Locale.forLanguageTag(locale.getLanguage()).equals(appLocale)) { return locale; } } } } // return default locale return messageTools.getDefaultLocale(); }
protected Locale resolveLocale(HttpServletRequest req, Messages messages, GlobalConfig globalConfig) { Map<String, Locale> locales = globalConfig.getAvailableLocales(); if (globalConfig.getLocaleSelectVisible()) { String lastLocale = getLocaleFromCookie(req); if (lastLocale != null) { for (Locale locale : locales.values()) { if (locale.toLanguageTag().equals(lastLocale)) { return locale; } } } } Locale requestLocale = req.getLocale(); if (requestLocale != null) { Locale requestTrimmedLocale = messages.getTools().trimLocale(requestLocale); if (locales.containsValue(requestTrimmedLocale)) { return requestTrimmedLocale; } // if not found and application locale contains country, try to match by language only if (!StringUtils.isEmpty(requestLocale.getCountry())) { Locale appLocale = Locale.forLanguageTag(requestLocale.getLanguage()); for (Locale locale : locales.values()) { if (Locale.forLanguageTag(locale.getLanguage()).equals(appLocale)) { return locale; } } } } return messages.getTools().getDefaultLocale(); }
protected String internalGetMessage(String packs, String key, Locale locale, String defaultValue, boolean searchMainIfNotFound) { locale = messageTools.trimLocale(locale); String cacheKey = makeCacheKey(packs, key, locale, locale); String msg = strCache.get(cacheKey); if (msg != null) return msg; String notFound = notFoundCache.get(cacheKey); if (notFound != null) return defaultValue; msg = searchMessage(packs, key, locale, locale, new HashSet<>()); if (msg != null) { cache(cacheKey, msg); return msg; } if (searchMainIfNotFound) { String tmpCacheKey = makeCacheKey(mainMessagePack, key, locale, locale); msg = searchMessage(tmpCacheKey, key, locale, locale, new HashSet<>()); if (msg != null) { cache(cacheKey, msg); return msg; } } notFoundCache.put(cacheKey, key); return defaultValue; }
messageTools.trimLocale(locale), new FormatStrings( numberDecimalSeparator.charAt(0),
protected Locale getUserLocale(LocalizedCredentials credentials, User user) { Locale userLocale = null; if (credentials.isOverrideLocale()) { userLocale = credentials.getLocale(); } if (userLocale == null) { if (user.getLanguage() != null) { userLocale = LocaleUtils.toLocale(user.getLanguage()); } else { userLocale = messages.getTools().trimLocale(messages.getTools().getDefaultLocale()); } } return userLocale; }
@Override public AuthenticationDetails authenticate(Credentials credentials) throws LoginException { AnonymousUserCredentials anonymous = (AnonymousUserCredentials) credentials; String login = serverConfig.getAnonymousLogin(); Locale credentialsLocale = anonymous.getLocale() == null ? messages.getTools().trimLocale(messages.getTools().getDefaultLocale()) : anonymous.getLocale(); User user = loadUser(login); if (user == null) { throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale)); } Locale userLocale = getUserLocale(anonymous, user); UUID anonymousSessionId = globalConfig.getAnonymousSessionId(); UserSession session = createSession(anonymous, user, userLocale, anonymousSessionId); session.setClientInfo("System anonymous session"); return new SimpleAuthenticationDetails(session); }