GWT国际化(i18n)在服务器端 [英] GWT Internationalization (i18n) in server side

查看:136
本文介绍了GWT国际化(i18n)在服务器端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Message类:

  / ** 
*表示资源包中包含的消息的接口:
* /
公共接口消息扩展了com.google.gwt。 i18n.client.Messages {

/ **
*翻译否。
*
* @return翻译否
* /
@DefaultMessage(否)
@Key(NO)
字符串否();
}

我有两个属性Messages.properties和Messages_fr.properties。



我也有这样的配置:

 < inherits name =com.google .gwt.i18n.I18N/> 
< extend-property name =localevalues =fr/>
< set-configuration-property name =locale.useragentvalue =Y/>

而在客户端我这样做:

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

具有国际化功能的客户端正在运行,但如果我在服务器端添加以下几行代码:

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

我有一个错误,因为GWT.create它仅适用于客户端。



您知道如何在服务器端显示国际化信息吗?

谢谢!



服务器端代码国际化的良好开端可能是 http://docs.oracle.com/javase/tutorial/i18n/



您仍然可以使用您在客户端代码中使用的.properties,但必须使用纯java方法来访问它们。例如:

  ResourceBundle bundle = ResourceBundle.getBundle(com.example.client.i18n.myresource); 
bundle.getString(stringToRetrieve);


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!

解决方案

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");

这篇关于GWT国际化(i18n)在服务器端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆