Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current Locale in Spring?

Tags:

java

spring

I use this method

LocaleContextHolder.getLocale()

to get switched locale (Japanise) but it returns me English (default). How can I retrieve the jp_JP locale?

like image 479
JohnWinter Avatar asked Jul 16 '15 15:07

JohnWinter


1 Answers

//Return the Locale associated with the current thread,
// if any, or the   system default Locale else(English)   
LocaleContextHolder.getLocale();

so first you have to check Locale of your current thread. If you want to set Locale in current thread then use this code :

setLocale(Locale locale); LocaleContextHolder.getLocale() will return jp_JP locale
like image 199
Mohammad tanvirul islam Avatar answered Oct 23 '22 09:10

Mohammad tanvirul islam