java - How to get current Locale in Spring? -


i use method

localecontextholder.getlocale()

to switched locale (japanise) returns me english (default). how can retrieve jp_jp locale?

requestcontextutils

this should allow current locale of request:

requestcontextutils.getlocaleresolver(request).resolvelocale(request); 

return localeresolver has been bound request dispatcherservlet.
@param request current http request
@return current localeresolver, or {@code null} if not found:

public static localeresolver getlocaleresolver(httpservletrequest request) {     return (localeresolver) request.getattribute(dispatcherservlet.locale_resolver_attribute); } 

this return localeresolver can load locale.

localecontextholder

or metioned by: mohammad tanvirul islam:

localecontextholder.getlocale(); 

you can have @ docu here:

  1. requestcontextutils: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/servlet/support/requestcontextutils.html

  2. localeresolver: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/servlet/localeresolver.html

  3. localecontextholder: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/i18n/localecontextholder.html


Comments