in GWT, can we manage Messages & Constants (i18n) at Server as we manage at Client?

354 views
Skip to first unread message

Tom

unread,
Mar 7, 2014, 3:33:26 AM3/7/14
to google-we...@googlegroups.com

Messages & Constants (com.google.gwt.i18n.client.Constants & com.google.gwt.i18n.client.Messages) in GWT allow us to put all Messages & Constants into properties files so that we can change these messages & constants at any time we want without the need to recompile the whole webapp when we need to change them.

Ex: you have a message call "User451 pls views order" in myMessages.properties

userViewOrder=User''{0}'' pls views order

& in the MyMessages.java

public interface MyMessages extends Messages{
    String userViewOrder(String userID);
}

At a later time, the bos wants to change the message to "Customer451 pls views order" then we don't need to recompile the whole project but just need to modify the myMessages.properties file

userViewOrder=Customer''{0}'' pls views order

So my question is, can we achieve the similar thing at the server level?

For example, in server, after inserting order data successfully into DB we need to send a private message to the customer immediately right at the server. Ex:

public boolean isertOrder(String data, String userID){
    String sql="insert query here";
    ..... more code ....
    int resultCode=prepareStmt.executeUpdate();
    if (resultCode==1){
       //insert a notification into Message table 
       String msg="Congratulation user "+userID+", You ordered successfully!"; 
// how to manage this message without needing to recompiling the whole project

       String sql="insert into Message values (.....)"
       ///do the inserting here
    }
}

can we manage Messages & Constants (i18n) at Server as we manage at Client?

Can we be able to do that?

& more importantly, Can we do it safely?

Thomas Broyer

unread,
Mar 7, 2014, 4:30:50 AM3/7/14
to google-we...@googlegroups.com


On Friday, March 7, 2014 9:33:26 AM UTC+1, Tom wrote:

Messages & Constants (com.google.gwt.i18n.client.Constants & com.google.gwt.i18n.client.Messages) in GWT allow us to put all Messages & Constants into properties files so that we can change these messages & constants at any time we want without the need to recompile the whole webapp when we need to change them.

Wrong assumption. You'll have to recompile your app whenever you change anything related to client-side code.
 

Ex: you have a message call "User451 pls views order" in myMessages.properties

userViewOrder=User''{0}'' pls views order

& in the MyMessages.java

public interface MyMessages extends Messages{
    String userViewOrder(String userID);
}

At a later time, the bos wants to change the message to "Customer451 pls views order" then we don't need to recompile the whole project but just need to modify the myMessages.properties file

userViewOrder=Customer''{0}'' pls views order

So my question is, can we achieve the similar thing at the server level?

For example, in server, after inserting order data successfully into DB we need to send a private message to the customer immediately right at the server. Ex:

public boolean isertOrder(String data, String userID){
    String sql="insert query here";
    ..... more code ....
    int resultCode=prepareStmt.executeUpdate();
    if (resultCode==1){
       //insert a notification into Message table 
       String msg="Congratulation user "+userID+", You ordered successfully!"; 
// how to manage this message without needing to recompiling the whole project

       String sql="insert into Message values (.....)"
       ///do the inserting here
    }
}

can we manage Messages & Constants (i18n) at Server as we manage at Client?

Note that you'll have to make sure that your *.properties files are US-ASCII, as GWT expects them in UTF-8 and ResourceBundle as ISO-8859-1. You can use a custom ResourceBundle.Control to load them as UTF-8.
And then use MessageFormat for replacing placeholders (for the case of c.g.g.i18n.client.Messages).

That said, there also are existing GWT-like solutions, such as https://github.com/dbaeli/ez18n (see http://fr.slideshare.net/gdigugli/con11234-baeli-diguglielmo)
There are also a few projects that directly try to use your GWT interfaces on server-side; and it's also a planned feature of GWT proper (no ETA yet).

Tom

unread,
Mar 7, 2014, 8:07:11 AM3/7/14
to google-we...@googlegroups.com
Hi Thomas, I am confused, 
why we need to recompile the whole project when we just change a simple text in properties file?

For example, suppose we have this line in properties file.

userViewOrder=User''{0}'' pls views order

Then I just change it to 
userViewOrder=Customer''{0}'' pls views order

So in this case, do i need to recompile the while project?
Message has been deleted

Tom

unread,
Mar 7, 2014, 8:16:40 AM3/7/14
to google-we...@googlegroups.com
Hello Thomas, I have just tested in eclipse. I started my webapp & just let the server run. When I clicked the button 1st time it used this text "User455 pls views order". 

Now I just let the server to continue to run without stopping it. Then, I changed "User" to "Customer" & then I clicked the button again. This time, it showed  "Customer455 pls views order".

I don't understand what u mean?

Andy Stevko

unread,
Mar 7, 2014, 8:51:21 AM3/7/14
to google-web-toolkit
Tom,
Are you using dev mode in eclipse? If so, it does the recompiling for you on the fly.
To show what your web app looks like without on the fly compiling, do a full compile using the menu item "GWT Compile Project..." and then stripping the ?gwt.codesvr= from the url.



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.



--
-- A. Stevko
===========
"If everything seems under control, you're just not going fast enough." M. Andretti




Thomas Broyer

unread,
Mar 7, 2014, 8:54:39 AM3/7/14
to google-we...@googlegroups.com


On Friday, March 7, 2014 2:07:11 PM UTC+1, Tom wrote:
Hi Thomas, I am confused, 
why we need to recompile the whole project when we just change a simple text in properties file?

That's the difference between "static" and "dynamic" internationalization: http://www.gwtproject.org/doc/latest/DevGuideI18n.html
With static i18n, your constants/messages are compiled into the generated JS (with one permutation –JS file(s)– per supported locale)
By "whole project" here, I only mean the "GWT compilation" part (client side)

Andrea Boscolo

unread,
Mar 7, 2014, 11:03:28 AM3/7/14
to google-we...@googlegroups.com

On Friday, March 7, 2014 10:30:50 AM UTC+1, Thomas Broyer wrote:

There are also a few projects that directly try to use your GWT interfaces on server-side; and it's also a planned feature of GWT proper (no ETA yet).

Just curious, but what about https://gwt-review.googlesource.com/#/c/1550/ ? An old commit (still not merged), but is it supposed to help in this way? Theoretically it should, but I can't quite 'grasp' all the bits from such a big change. I guess it was before the "GWT.create() on the server" era, but again, I'm curious about its future.

Thomas Broyer

unread,
Mar 7, 2014, 12:13:19 PM3/7/14
to google-we...@googlegroups.com
It is one step towards "I18N on the server". "GWT.create() on the server" was one such other steps. The last one being generating Messages, Constants, etc. implementations for use on the server side, that the "GWT.create() on the server" could load when called with your I18N interfaces.
I can't really tell about the future of this patch, as it's a contribution from an ex-Googler and he probably doesn't have much free time left to contribute such big changes to GWT. But the future of GWT.create() seems to be that same approach: use annotation processors to generate implementations of your interfaces and then GWT.create() will only have to pick the appropriate class for the given interface (no more generator run during the GWT compilation). It's still a long way before we reach that stage though (with probably a lot of breaking changes: GWT generators didn't use to be triggered by annotations, but annotation processors are harder –not impossible though– to trigger on anything else than annotations, so we –as users– might have to change our code to at least introduce annotations here and there to trigger the annotation processors).

Andrea Boscolo

unread,
Mar 7, 2014, 2:33:55 PM3/7/14
to google-we...@googlegroups.com
Ok, got it.
Thank you for the explanation.
Reply all
Reply to author
Forward
0 new messages