Here are my own notes to set up Internationalization (i18n) in GWT.
1. In myApp.gwt.xml
<inherits name="com.google.gwt.i18n.I18N"/>
<extend-property name="locale" values="en"/>
<extend-property name="locale" values="sp"/>
<extend-property name="locale" values="fr"/>
2. Create 3 properties files in the client folder:
MyMessages_en.properties
MyMessages_fr.properties
MyMessages_sp.properties
3. Here is the content of MyMessages_en.properties (the other two
files should be identical):
enBtn = English
spBtn = Español
frBtn = Français
4. Create 3 Button Widgets in the EntryPoint module
MyMessages myMessages = (MyMessages) GWT.create(MyMessages.class);
Button enBtn = new Button();
enBtn.setHTML(myMessages.enBtn());
Button enBtn = new Button();
enBtn.setHTML(myMessages.frBtn());
Button enBtn = new Button();
enBtn.setHTML(myMessages.spBtn());
5. Create the MyMessages.java in the client folder:
package com.myApp.client;
import com.google.gwt.i18n.client.Messages;
public interface MyMessages extends Messages {
String spBtn();
String enBtn();
String frBtn();
}
6. Here is the ClickListener for one of the buttons:
enBtn.addClickListener(new ClickListener() {
public native void onClick(Widget sender) /*-{
var currLocation = $wnd.location.toString().split("?");
var currLocale = "?locale=en";
$wnd.location.href = currLocation[0] + currLocale;
$wnd.location.replace(currLocation[0] + currLocale);
}-*/;
});
7. Don't forget this meta tag in the main html file:
<meta name="gwt:property" content="locale=en">
8. Here is how to manually check that the locale are indeed changed:
http://localhost:8888/com.myApp.myProject/myProject.html?locale=en
or
http://localhost:8888/com.myApp.myProject/myProject.html?locale=sp
or
http://localhost:8888/com.myApp.myProject/myProject.html?locale=fr
Well. That's it. I believe there are enough information in this post
to start the ball rolling for anyone interested to learn how to
internationalize his/her GWT application.
Cheerio.
|