Download GWT Messages from the Database

GWT typically loads i18n lines using this interface:

public interface StatusMessage extends Messages { String error(String username); : } 

which then loads the actual lines from the StatusMessage.property file:

 error=User: {0} does not have access to resource 

This is a great solution, however my client cannot claim to put i18n strings in the database so that they can be changed at runtime (although this is not a requirement that they be changed in real time).

One solution is to create an asynchronization service that accepts the message identifier and user locale and returns a string. I implemented this and find it terribly ugly (it introduces a huge amount of additional communication with the server, and also makes replacing the placeholder replacement quite difficult).

So my question is whether it is possible in some good way to implement a specialized message provider that downloads messages from the backend in one major fell swoop (for the current user session). If he can also connect to the default GWT messaging engine, then I would be completely happy (i.e. I could create an interface as described above and continue to use the nice {0}, {1} ... property replacement format )

Other suggestions for clean database-driven messages in the GWT are also welcome.

+6
java internationalization gwt
source share
4 answers

The GWT in-built Dictionary class is the best way to move forward. Here is the official documentation on how to use it.

+3
source share

Let's say your application has 500 messages per locale with an average of 60 characters per message. I would not think twice about downloading all this data when a user logs in or selects his language: it is 50 thousand. Data should not be a problem if you can assume that access to a broadband connection ... your suggestion is "one Maha, "I already do this in one GWT application, although these are not messages, but properties that are read from the database.

+1
source share

I think you may find this article helpful: http://googlewebtoolkit.blogspot.com/2010/02/putting-test-data-in-its-place.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+blogspot/NWLT+ (Google + Web + Toolkit + Blog) & utm_content = Google + Reader

What you can do is set up a TextResource, and then you can just change the text at runtime. I have not tried this, but I am very sure that it will work.

+1
source share

To optimize performance, you can put your messages in a js resource, for example: http://host.com/app/js/messages.js?lang=en , and then map this resource to a servlet that will take a message dictionary from your cache (e.g. singleton bean) and write it in response.

To further optimize, you can:
- put the parameter in the resource URL, for example: ... / messages.js? lang = ru & version = {last updated date of messages}
- {last updated message date} is stored somewhere in the database
- whenever the user updates messages, {last updated date of messages} will change
- In response to the browser, install Cache-control to instruct the browser to cache your messages.

0
source share

All Articles