Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Current Locale in GWT using LocaleInfo

Tags:

locale

gwt

I have tried to get the current locale on the client using the LocaleInfo class and the method getCurrentLocale(). However it always returns the value default locale no matter what regional and locale settings I have on the client machine.

The Date classes toLocaleString() method returns a locale specific string but the LocaleInfo doesn't seem to be able to get the systems Locale.

like image 978
snowstreams Avatar asked Dec 21 '22 23:12

snowstreams


2 Answers

To make your GWT app auto-detect your locale, just rename your base index.html file (the file that includes the "nocache.js" script) to index.jsp and add the following line to the section:

<meta name="gwt:property" content="locale=<%=request.getLocale()%>">
like image 85
11101101b Avatar answered Jan 07 '23 12:01

11101101b


Locales for GWT are not automatically obtained from the system/browser settings. As per the GET locale documentation the locale to use at run time can be set in one of two ways:

  1. By specifying a locale request parameter in your application's URL. I.e. http://www.myapplication.com/?locale=es
  2. By including a gwt:property meta tag in the host page:

    <meta name="gwt:property" content="locale=es" />

    This is the preferred method for production applications. Your host page can determine the user's locale in a number of ways including, but not limited to, allowing the user to configure a local or detecting their preferred locale based on the Accept-Language request header.

like image 26
Jason Terk Avatar answered Jan 07 '23 12:01

Jason Terk