Tuesday, July 29, 2014

Re: How to access “locale” value (of an Internationalization App) in server side in GWT?

I found the currect solution that is to use LocaleInfo

LocaleInfo localeInfo=LocaleInfo.getCurrentLocale();
String locale=localeInfo.getLocaleName();
addToPopupSlot
(loadingPresenter);
SetLanguage action=new SetLanguage(locale);
       
    dispatchAsync
.execute(action, setLanguageCallback);


On Tuesday, July 29, 2014 4:07:47 PM UTC+10, Tom wrote:

Ok, I am developing an app that supports Internationalization. I am using Static String Internationalization method for my app.

Let say my app can have English & German version, so -1st, I created MyMessages.java which has all message texts written in English. Then I created an MyMessages_ge which is almost the same as MyMessages.java except that the text written in German

-2nd, in MyProject.html i have <meta http-equiv="content-type" content="text/html; charset=UTF-8"> to make sure it will support all languages

-3rd, in MyProject.gwt.xml I have <extend-property name="locale" values="ge"/>

Now I run my app in eclipse http://localhost:8888/MyProject.html?gwt.codesvr=127.0.0.1:9997&locale=ge & it shows all the German text as I expected.

However, I have a need to know that my app is German At Server Side. That means whenever my GWT Gui in German version then my server will know that languageCode=1 if it is in English so server will use the default language languageCode=0

Here is what I did. At HeaderPresenter.java

@Override  public void prepareFromRequest(PlaceRequest request){      super.prepareFromRequest(request);      String locale=request.getParameter("locale", "");      setLanguage(locale); // servercall back here  }  

so when my app run first time it should let server to know which language the Gwt app is using

@Override  public SetLanguageResult execute(SetLanguage action, ExecutionContext context)          throws ActionException {      String locale=action.getLocale();      if("ge".equals(locale)){          Data.languageType=1;      }      return null;  }  

However, it doesn't seem work When I go to orderPage the url will be http://localhost:8888/MyProject.html?gwt.codesvr=127.0.0.1:9997&locale=ge#!orderPage it not in the form http://localhost:8888/MyProject.html?gwt.codesvr=127.0.0.1:9997#!orderPage;locale=ge that is why server couldn't capture the locale value.

I think I misunderstood something here. I'm quite confusing.

So How to access "locale" value (of an Internationalization App) in server side in GWT?

http://stackoverflow.com/questions/25009115/how-to-access-locale-value-of-an-internationalization-app-in-server-side-in

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment