Spring: Custom locale resolver

时间:2018-09-19 08:28:19

标签: spring spring-boot

I'm using a custom implemented ResourceBundleMessageSource:

public class CustomResourceBundleMessageSource
    extends org.springframework.context.support.ResourceBundleMessageSource { //... }

Shortly, it's looking for message codes into resource bundles according to current locale.

public final String getMessage(String code) {
    return getMessage(code, null, null, getCurrentLocale());
}


public Locale getCurrentLocale() {
    Locale locale = ThreadLocalHolder.get(LOCALE_PROPERTY_NAME, Locale.class);

    if (locale == null) {           
        locale = (defaultLocale==null)?Locale.getDefault():defaultLocale;
    }

    return locale;
}

As you can see it's picking current locale from a ThreadLocalHolder class.

So, I'd like to resolve Accept-Language request header and set this value on this ThreadLocalHolder.

Any ideas?

0 个答案:

没有答案