Section 8.11. Specifying a Certain Locale for a Web Page


8.11. Specifying a Certain Locale for a Web Page

So how does the application find out about which locale the user is associated with? GWT provides two ways. One involves examining the URL with which the user accesses the application and determining whether the page will display English, Spanish, or German languages. The URL includes the locale in a query string.

 http://bwpmacmini.local/~bruceperry/ajax/com.parkerriver.gwt.intro.GwtAjax/GwtAjax.htm l?locale=es_ES 

The URL has one parameter/value pair appended to its end in the form locale=es_ES. You may have guessed that if the locale is "es," then the translations from GwtAjaxConstants_es.properties are used. If the locale is "es_ES," then the application uses GwtAjaxConstants_es_ES.properties. If the locale is "es" but the developer has not provided a resource with that suffix (even if you have one with a "es_ES" suffix!), then the application uses the default localein this case, English (the translations inside GwtAjaxConstants.properties).

A typical way to implement this mechanism in a web application is to have icons representing the various countries. The user clicks on an icon, and that link determines the value of the locale parameter.

Another more static way to accomplish the same thing is to include this type of meta tag in the HTML file (e.g., GwtAjax.html).

 <meta name="gwt:property" content="locale=es_ES"> 

This tag embeds the locale inside a particular web page. The query string/parameter method offers a more dynamic mechanism, since you can use it with just one web page. The i18n effort described here is admittedly limited, in that we have not translated the entire application, including the Label and Button text. For example, we could easily add a translated Button label by including the code in a properties file:

 buttonText=Request Info 

then add this method definition to the GwtConstants interface.

 String buttonText(); 

Finally, the Java file for the GUI client could include this code:

 final GwtAjaxConstants myConstants = (GwtAjaxConstants) GWT.       create(GwtAjaxConstants.class); Button but = new Button(myConstants.buttonText()); 




Google Web Toolkit for Ajax
Google Web Toolkit GWT Java AJAX Programming: A step-by-step to Google Web Toolkit for creating Ajax applications fast
ISBN: 1847191002
EAN: 2147483647
Year: 2006
Pages: 29

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net