All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.biz.web.servlet.i18n.AcceptHeaderLocaleResolver Maven / Gradle / Ivy

There is a newer version: 3.3.x.20241003.RELEASE
Show newest version
package org.springframework.biz.web.servlet.i18n;

import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.http.HttpHeaders;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.i18n.AbstractLocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

public class AcceptHeaderLocaleResolver extends AbstractLocaleResolver {

	@Override
	public Locale resolveLocale(HttpServletRequest request) {
		String language = request.getHeader(HttpHeaders.ACCEPT_LANGUAGE);
		if (StringUtils.hasText(language)) {
			return Locale.forLanguageTag(language);
		}
		return getDefaultLocale();
	}

	@Override
	public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
		if(locale != null) {
			LocaleContextHolder.setLocale(locale);
		}
	}

	
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy