1

I have a GWT application with internationalization support (in client side).

I have a Messages class:

/**
 * Interface to represent the messages contained in resource bundle:
 */
public interface Messages extends com.google.gwt.i18n.client.Messages {

  /**
  * Translated "No".
  * 
  * @return translated "No"
  */
  @DefaultMessage("No")
  @Key("NO")
  String NO();
}

I have two properties Messages.properties and Messages_fr.properties.

I also have this configuration :

<inherits name="com.google.gwt.i18n.I18N" />
<extend-property name="locale" values="fr" />
<set-configuration-property name="locale.useragent" value="Y"/>

And in client side i do this:

private final Messages messages = GWT.create(Messages.class);
//...
messages.NO(); 

Client side with internationalization is working but if I add theses follwoing lines in server side:

private final Messages messages = GWT.create(Messages.class);

I have an error, because GWT.create it's only for client side.

Do you know how can I display internationalization messages in the server side?

Thanks!

superscral
  • 480
  • 1
  • 11
  • 33
  • I'm successfully using a proxy described here: http://stackoverflow.com/a/4660195/4491066 – Adam Feb 16 '15 at 21:31

2 Answers2

2

Keep in mind that GWT transforms client java code in javascript so that browsers can execute it. That's why your server can't do anything with your Messages class and throws errors. See the package client in com.google.gwt.i18n.client.Messages ? This is client-side code, so in the end, it will be js.

A good start for internationalization in server-side code could be http://docs.oracle.com/javase/tutorial/i18n/

You can still use your .properties you are using in client-side code, but you have to use plain java approach to access them. An example is :

ResourceBundle bundle = ResourceBundle.getBundle("com.example.client.i18n.myresource");
bundle.getString("stringToRetrieve");
user2508244
  • 91
  • 2
  • 7
  • That's weird why GWT i18n approach is not available for server side, it looks much better than from JDK. – kan Aug 06 '13 at 11:53
  • There is a project which tried to port some of the GWT approaches to the server side: https://github.com/lightoze/gwt-i18n-server – MrTux Aug 07 '18 at 13:19
2

Not a specific answer, but unfortunately GWT currently doesn't have support for fully reusing the client messages file on the server, although there is work-in-progress to add it to GWT. John Tamplin gave a talk at the GWT Meet-up 2013 about the progress and the problems with re-using the client side messages on the server side. You can find the presentation at the meetup youtube channel.

Hilbrand Bouwkamp
  • 13,509
  • 1
  • 45
  • 52