@GetMapping(value = "/locales", produces = "application/json; charset=UTF-8") @ResponseBody public LocalesInfo getLocales() { LocalesInfo localesInfo = new LocalesInfo(); localesInfo.setLocaleSelectVisible(globalConfig.getLocaleSelectVisible()); Map<String, String> locales = new LinkedHashMap<>(); for (Map.Entry<String, Locale> entry : globalConfig.getAvailableLocales().entrySet()) { locales.put(entry.getValue().toLanguageTag(), entry.getKey()); } localesInfo.setLocales(locales); return localesInfo; }
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(); }
@Deprecated protected void copyParamsToCredentials(Map<String, Object> params, AbstractClientCredentials credentials) { // for compatibility only Object clientType = params.get(ClientType.class.getName()); if (clientType != null && credentials.getClientType() == null) { credentials.setClientType(ClientType.valueOf((String) clientType)); } Object clientInfo = params.get(SessionParams.CLIENT_INFO.getId()); if (clientInfo != null && credentials.getClientInfo() == null) { credentials.setClientInfo((String) clientInfo); } Object ipAddress = params.get(SessionParams.IP_ADDRESS.getId()); if (ipAddress != null && credentials.getIpAddress() == null) { credentials.setIpAddress((String) ipAddress); } Object hostName = params.get(SessionParams.HOST_NAME.getId()); if (hostName != null) { credentials.setHostName((String) hostName); } if (!globalConfig.getLocaleSelectVisible()) { credentials.setOverrideLocale(false); } } }
if (globalConfig.getLocaleSelectVisible() && auth.getLocale() != null) { Map<String, Locale> availableLocales = globalConfig.getAvailableLocales(); Locale requestedLocale = Locale.forLanguageTag(auth.getLocale());
@Deprecated protected void copyParamsToCredentials(Map<String, Object> params, AbstractClientCredentials credentials) { // for compatibility only Object clientType = params.get(ClientType.class.getName()); if (clientType != null) { credentials.setClientType(ClientType.valueOf((String) clientType)); } Object clientInfo = params.get(SessionParams.CLIENT_INFO.getId()); if (clientInfo != null) { credentials.setClientInfo((String) clientInfo); } Object ipAddress = params.get(SessionParams.IP_ADDRESS.getId()); if (ipAddress != null) { credentials.setIpAddress((String) ipAddress); } Object hostName = params.get(SessionParams.HOST_NAME.getId()); if (hostName != null) { credentials.setHostName((String) hostName); } if (!globalConfig.getLocaleSelectVisible()) { credentials.setOverrideLocale(false); } RemoteClientInfo remoteClientInfo = RemoteClientInfo.get(); if (remoteClientInfo != null) { String address = remoteClientInfo.getAddress(); if (!trustedLoginHandler.checkAddress(address)) { credentials.setIpAddress(address); } } }
Locale loggedInLocale = connection.getSession().getLocale(); if (globalConfig.getLocaleSelectVisible()) { app.addCookie(App.COOKIE_LOCALE, loggedInLocale.toLanguageTag());
protected void initLocales() { localesSelect.setOptionsMap(globalConfig.getAvailableLocales()); localesSelect.setValue(app.getLocale()); boolean localeSelectVisible = globalConfig.getLocaleSelectVisible(); localesSelect.setVisible(localeSelectVisible); // if old layout is used Component localesSelectLabel = getComponent("localesSelectLabel"); if (localesSelectLabel != null) { localesSelectLabel.setVisible(localeSelectVisible); } localesSelect.addValueChangeListener(e -> { Locale selectedLocale = (Locale) e.getValue(); app.setLocale(selectedLocale); authInfoThreadLocal.set(new AuthInfo(loginField.getValue(), passwordField.getValue(), rememberMeCheckBox.getValue())); try { app.createTopLevelWindow(); } finally { authInfoThreadLocal.set(null); } }); }