errai/errai — pull request #24 by EricWittmann (2012-12-11 21:32:03+00:00)
Title: Proposed: i18n support in errai-ui

Since I had already started playing with this proposed feature, I figured I would finish it up before I revisited the TransitionAnchor idea.

This pull request contains code to support internationalization in Errai UI. It does this in two ways.

### Annotations and i18n
If you're not using Templates, you can still use i18n support by using the following new annotations:
* @Bundle - allows the developer to specify the name of a Bundle (a Bundle is a [GWT Dictionary](http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/i18n/client/Dictionary.html))
* @I18n - indicates the key into the Bundle - the value will be used in a call to setText or setHTML on the annotated field or parameter
* @I18nDefault - indicates a default value if the key is not found - also prevents a runtime error if the key is not found

These annotations can be used on fields and parameters for any Widget that implements HasText or HasHTML.

Example:

```java
@Page(path="login")
@Dependent
@Bundle("myBundle")
public class LoginPage extends FlowPanel {

@Inject @I18n("pages.login.username")
private InlineLabel usernameLabel;
@Inject
private TextBox username;

@Inject @I18n("pages.login.password")
private InlineLabel passwordLabel;
@Inject
private TextBox password;

@PostConstruct
private void init() {
add(username);
add(usernameLabel);
add(password);
add(passwordLabel);
}
}
```

### Templating and i18n
Even better, the templating system also supports a new attribute 'i18n'. If this attribute is present, then the template is pre-processed, looking up replacement values from the bundle (default bundle or one specified by @Bundle on the @Templated class). The replacement value is set as the innerHtml of the attributed Element.

Example:

```html

Username:

Password:

Login

```

### Random Thoughts
* I don't have a way to i18n just a single attribute in the template. That could be useful for certain element types (I'm thinking the 'title' attribute on some elements).
* The template approach is nice - if you use the defaults there's almost no client-side code - just the i18n attributes in the templates
* On the server-side, a message bundle needs to be written either to the host page or an included javascript file in GWT Dictionary format (JSON) - this is pretty standard, but it might be nice to include something that could convert a standard messages.properties into the right JSON format