Jerome C. schrieb:
> I need to use internationalization files on server side (send email,
> and email content is internationalized).
> When I use GWT.create on my server side, it does not run (exception).
[...]
> If I can, I don't want to use two different mechanisms for client and
> server internationalization.
I solved it by adding the locale-string to the parameters of the
servlet-method to be called:
public String getSomething(String param1, long param2, String locale) throws
RemoteServiceException {
ResourceBundle rb = getResourceBundle(locale);
try{
doSomething()
}
catch(Exception e){
throw new
RemoteServiceException(rb.getString("ServiceGeneral_Error_SomethingHappened"));
}
}
public static ResourceBundle getResourceBundle(String locale) {
Locale loc = getLocale(locale);
ResourceBundle rb =
Utf8ResourceBundle.getBundle(AdminToolsI18NConstants.class.getName(), loc,
AdminToolsI18NConstants.class.getClassLoader());
return rb;
}
public static Locale getLocale(String locale){
if (locale == null){
return null;
}
StringTokenizer tt = new StringTokenizer (locale, "_");
Locale loc = new Locale(tt.nextToken(), tt.hasMoreTokens() ? tt.nextToken() :
"", tt.hasMoreTokens() ? tt.nextToken() : "");
return loc;
}
The Utf8ResourceBundle is inspired by
http://www.thoughtsabout.net/blog/archives/000044.html
That way you can use the ResourceBundle-files you created for the
GWT-client. In each bundle I added one property, e.g.
Locale = DE
So a call in the GWT-client looks like this:
public static final MyI18NConstants CONSTANTS = (MyI18NConstants)
GWT.create(MyI18NConstants.class);
[...]
GeneralServices.Util.getInstance().getSomething(param1, param2,
CONSTANTS.Locale(), new AsyncCallback(){
[...]
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
}
};
If you have defined Messages instead of Constants you can do the filling
of the parameters by a simple text-replacement, e.g. by replaceAll:
rb.getString(...).replaceAll("\{0\}", e.getMessage());
Regards, Lothar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---