gwt locallizaed

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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值