if (!localized) {
String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName();
if (!locale.equals(user.getLocale)) {
String url = GWT.getModuleBaseURL();
String newUrl = url + "?locale="+currentLocale;
localized = true; //and save to session here
Window.Location.replace(newUrl);
}
<script type="text/javascript">
var search = location.search;
if(search.indexOf("locale") == -1){
var lang = navigator.language!= null ? navigator.language : navigator.browserLanguage;
lang = lang.replace("-", "_");
var metaTag = document.createElement('meta');
metaTag.name = "gwt:property";
metaTag.content = "locale=" + lang;
document.getElementsByTagName('head')[0].appendChild(metaTag);
}
</script>
Ok take a look at com.google.gwt.i18n.I18N.gwt.
xml
Seems like there are 5 ways to provide the locale:
1.) using a query param named "locale". To use this method you can let your web server send a redirect from
app.example.com to
app.example.com/?locale=<
locale> after determining the locale on your web server if possible or you do the redirect from within your app, e.g. in your onModuleLoad() you use Window.Location.assign(<
current url> + <locale query param>). You can change the name of the query param by setting a different value to "locale.queryparam".
2.) using a cookie. To use this you have to define the cookie name by setting "locale.cookie" to any value as in I18N.gwt.xml no default cookie name is defined.
3.) using meta tags. As already described you can include a gwt:property meta tag in a dynamic host page.
4.) using the user agent information. To use this you have to activate it by setting "locale.useragent" to "Y" as its disabled by default in I18N.gwt.xml.
5.) create your own property provider and use JavaScript to fill the "locale" property value yourself. Here you are completely free how to obtain the value.
GWT's default search order is "query param, cookie, meta, useragent" but cookie and useragent will be skipped if you don't configure/activate them. You could also modify the search order by setting "locale.searchorder" in your gwt.xml.