Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpServletRequest getLocale returns OS locale not browser locale

I am using vaadin framework and in my application I have:

@Override
public void onRequestStart(HttpServletRequest request,
        HttpServletResponse response) {
    currentIP = request.getRemoteAddr();
    setLocale(request.getLocale());
    handle.set(this);    
    this.request = request;    
    this.response = response;
}

however, request.getLocale() returns en_US, which is my OS locale. However, in Firefox addon for switching locales (https://addons.mozilla.org/cs/firefox/addon/quick-locale-switcher/?src=userprofile), I have set up it to be cs_CZ, however, getLocale() will still return en_US.

like image 718
Enerccio Avatar asked Apr 26 '26 03:04

Enerccio


1 Answers

Try getting the session locale:

UI.getCurrent().getSession().getLocale();

That worked for me.

like image 121
camikiller Avatar answered Apr 28 '26 18:04

camikiller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!