Thank you for this response, I was thinking of a solution like this but what
I don't like in this solution is the use of a constant for server side
ressource bundle.

If I can, I want to use a function to refer to an internationalized string.

In summary:

I want to do on my server side:
myConstants.myMessage();
(like I do on client side)


instead of:
myConstants.getString("myMessage");
(avoid the ressource bundle mechanism to have unicity on client and server
internationalization)

But if I can't I will use your solution.

---------------------------
Jérôme CANCE



On Mon, Oct 5, 2009 at 2:18 PM, Lothar Kimmeringer <[email protected]>wrote:

>
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to