PDA

View Full Version : Internationalization Sample



sundhar_v
3 Sep 2009, 2:05 AM
Can anyone give a sample program on internationalization (english to any language) by using GXT 1.2.3. This will be greatly helpful for me.

Thanks and Regards,
Sundhar :)

Feltros
3 Sep 2009, 6:55 AM
I was under the influence us GXT'ers relied on the GWT internationalization system?
http://code.google.com/webtoolkit/examples/I18N/
Might be quite helpful for you :)

dhanabalan
4 Sep 2009, 3:39 AM
but it is not GXT right? it is fully oriented about GWT. But we want one sample program for GXT widget with language change.

suresh.sivanantham
6 Sep 2009, 10:25 PM
ill give you some sample code...


ApplicationResuorces constResources = (ApplicationResuorces) GWT.create(ApplicationResuorces.class);

@Override
public void onModuleLoad() {
ContentPanel c = new ContentPanel();
c.setHeading(constResources.header());
ToolBar t = new ToolBar();
t.add(getlanguageListWidget());
c.setTopComponent(t);
c.setHeight(500);
RootPanel.get().add(c);
}

private Component getlanguageListWidget() {
ListStore<BeanModel> store = new ListStore<BeanModel>();
ComboBox<BeanModel> simpleCombo = new ComboBox<BeanModel>();
simpleCombo.setStore(store);
simpleCombo.setDisplayField("value");

int selectedIndex = 0;

String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName();
if (currentLocale.equals("default")) {
currentLocale = "en";
selectedIndex = 0;
}
System.out.println("currentLocale" + currentLocale);
String[] localeNames = LocaleInfo.getAvailableLocaleNames();
List<LocaleKeyValuePair> localesList = new ArrayList<LocaleKeyValuePair>();
System.out.println("-------" + localeNames.length);
for (int i = 0; i < localeNames.length; i++) {
if (!localeNames[i].equals("default")) {
localesList.add(new LocaleKeyValuePair(localeNames[i], LocaleInfo.getLocaleNativeDisplayName(localeNames[i])));
if (currentLocale.equals(localeNames[i]))
selectedIndex = i-1;
}
}
BeanModelFactory factory = BeanModelLookup.get().getFactory(LocaleKeyValuePair.class);
List<BeanModel> lm = factory.createModel(localesList);
store.add(lm);
System.out.println("----selectedIndex---" + selectedIndex);
simpleCombo.setOriginalValue(lm.get(selectedIndex));
simpleCombo.addSelectionChangedListener(new SelectionChangedListener<BeanModel>() {
@Override
public void selectionChanged(SelectionChangedEvent<BeanModel> se) {
Window.open(getHostPageLocation() + "?locale=" + se.getSelectedItem().get("key"), "_self","");
}
});

return simpleCombo;


/**
* This method is used to remove the locale parameter from the url
* (used to get the URL by stripping off the parameters.......)
*/
private static native String getHostPageLocation()
/*-{
var s = $doc.location.href;

// Pull off any hash.
var i = s.indexOf('#');
if (i != -1)
s = s.substring(0, i);

// Pull off any query string.
i = s.indexOf('?');
if (i != -1)
s = s.substring(0, i);

// Ensure a final slash if non-empty.
return s;
}-*/;have above code in your EntryPoint class. I have attached a file resources.zip.....
this file will have 3 files inside that.... named...



ApplicationResuorces.java
ApplicationResuorces_ta.properties
ApplicationResuorces.properties

these 3 files are required for gwt i18n...

don forget to add the lines below in your gwt.xml file


<extend-property name="locale" values="en" />
<extend-property name="locale" values="ja"/>
<extend-property name="locale" values="hi"/>
<extend-property name="locale" values="ta"/>dont forget to write some logic to keep the selected locale in your combo box....

hope this may help you.......

extgwt
24 Dec 2009, 12:38 PM
Hi
I think u forgot to attch zip file