I am trying to internationalize my application running with GWT UI Binder using dynamic string i18n. Does UI binder support dynamic string i18n? Please let me whether this is possible.
3 Answers
UiBinder templates can be marked up for localization. You use the
<ui:msg>
and<ui:attribute>
elements to indicate which portions of the template should be translated, then provide properties files with localized versions of the messages when building your app. More about it
Updated: See this GWT Dynamic String Internationalization, I think you can find a solution from there.
-
Thanks for the reply. But i want to know if DYNAMIC i18n is possible. I know that static string i18n is possible with uibinder – javalearner Jan 12 '12 at 07:17
-
That link clarifies on static i18n. you can see that from the messages interface. It's not dynamic – javalearner Jan 12 '12 at 08:28
We have done that using Dictionary . Basically you use dynamic host page (ex. jsp) to create constants dynamically in host page. To use them with UiBinder you have few options, but most straight forward is to create wrapper class around dictionary, for example
package org.gwt.dictionary.test
public class CurrentTheme {
Dictionary theme = Dictionary.getDictionary("CurrentTheme");
public String highlightColor() {
return theme.get("highlightColor");
}
public String shadowColor() {
return theme.get("shadowColor");
}
public String errorColor() {
return theme.get("errorColor");
}
public String errorIconSrc() {
return theme.get("errorIconSrc");
}
public String errorLabel() {
return theme.get("errorLabel");
}
public String someTextContent() {
return theme.get("someTextContent");
}
}
Then you can use it in gwt.xml like this
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:with field="themeConstants" type="org.gwt.dictionary.test.CurrentTheme"/>
<g:HTMLPanel>
<g:Label text="{themeConstants.errorLabel}" styleName="{themeConstants.errorColor}"/>
<div class="aler alert-info"><ui:text from="{themeConstants.someTextContent}"/></div>
</g:HTMLPanel>
</ui:UiBinder>
Hope it helps
To answer your question - yes, i18n is supported by UI Binder. Please refer to documentation available here and here. To support my claim, here is direct quote:
UiBinder... offers direct support for internationalization that works well with GWT's i18n facility;
You simply make some *.properties files with specified locale, enable i18n module in gwt-xml, create an interface which methods (returning String) can be accessed both in Java code and ui-xml files.

- 33,595
- 11
- 64
- 74
-
Thanks for the reply. But i want to know if DYNAMIC i18n is possible. I know that static string i18n is possible with uibinder – javalearner Jan 12 '12 at 07:16