What is the best way to implement GWT Server Side Internationalization?
实现GWT服务器端国际化的最佳方式是什么?
-
Use native Java properties files (not sure how to read and how to locate the right language file) (unicode string need to be ASCII encoded)
使用本地Java属性文件(不确定如何读取和如何定位正确的语言文件)(unicode字符串需要用ASCII编码)
-
Use GWTI18N.java - GWT module which gives you seamless use of GWT I18N on both the client and the server and uses "java.lang.reflect.Proxy method"
使用GWTI18N。java - GWT模块,它可以在客户端和服务器上无缝地使用GWT I18N,并使用“java.lang. reflection”。代理法”
-
Use Kotori I18N - ...
使用Kotori I18N -…
-
Other ideas?
其他的想法吗?
How can I find and pass localization from client to sever?
如何从客户端找到并传递本地化?
On the server side I have an Servlet which still doesn't use any GWT dependant source, is it better not to do so?
在服务器端,我有一个仍然不使用任何GWT依赖源的Servlet,不这样做更好吗?
2 个解决方案
#1
16
I found this solution and it looks very good
我找到了这个解,它看起来很好
gwt-i18n-server - Provides a simple support of gwt i18n feature on the server side
gwt-i18n-server——在服务器端提供对gwt i18n特性的简单支持
The aim is to permit to the GWT developer to use their Constants and Messages interfaces on the server side (See internationzation). The implementation is based on java reflect api. It loads the properties files from the classpath (same folder than the interface). It supports Constants, ConstantsWithLookup, Messages (plural too). The licence is LGPL.
目的是允许GWT开发人员在服务器端使用他们的常量和消息接口(参见国际化)。实现基于java reflection api。它从类路径(与接口相同的文件夹)加载属性文件。它支持常量、ConstantsWithLookup、Messages(复数)。LGPL许可证。
Client current locale can be found this way:
客户端当前语言环境可以通过以下方式找到:
LocaleInfo.getCurrentLocale().getLocaleName()
#2
0
Following other threads here in SO, I came up with this solution that also considers the encoding used for the properties files (which can be troublesome as ResourceBundle uses by default "ISO-8859-1"):
在SO中的其他线程之后,我提出了这个解决方案,它还考虑了用于属性文件的编码(由于ResourceBundle默认使用“ISO-8859-1”,这可能会很麻烦):
import java.io.UnsupportedEncodingException;
import java.util.Locale;
import java.util.ResourceBundle;
public class MyResourceBundle {
// feature variables
private ResourceBundle bundle;
private String fileEncoding;
public MyResourceBundle(Locale locale, String fileEncoding){
this.bundle = ResourceBundle.getBundle("com.app.Bundle", locale);
this.fileEncoding = fileEncoding;
}
public MyResourceBundle(Locale locale){
this(locale, "UTF-8");
}
public String getString(String key){
String value = bundle.getString(key);
try {
return new String(value.getBytes("ISO-8859-1"), fileEncoding);
} catch (UnsupportedEncodingException e) {
return value;
}
}
}
The way to use this would be very similar than the regular ResourceBundle usage:
使用这种方法将非常类似于常规的ResourceBundle用法:
private MyResourceBundle labels = new MyResourceBundle("es", "UTF-8");
String label = labels.getString(key)
Or you can use the alternate constructor which uses UTF-8 by default:
或使用默认使用UTF-8的备用构造函数:
private MyResourceBundle labels = new MyResourceBundle("es");
#1
16
I found this solution and it looks very good
我找到了这个解,它看起来很好
gwt-i18n-server - Provides a simple support of gwt i18n feature on the server side
gwt-i18n-server——在服务器端提供对gwt i18n特性的简单支持
The aim is to permit to the GWT developer to use their Constants and Messages interfaces on the server side (See internationzation). The implementation is based on java reflect api. It loads the properties files from the classpath (same folder than the interface). It supports Constants, ConstantsWithLookup, Messages (plural too). The licence is LGPL.
目的是允许GWT开发人员在服务器端使用他们的常量和消息接口(参见国际化)。实现基于java reflection api。它从类路径(与接口相同的文件夹)加载属性文件。它支持常量、ConstantsWithLookup、Messages(复数)。LGPL许可证。
Client current locale can be found this way:
客户端当前语言环境可以通过以下方式找到:
LocaleInfo.getCurrentLocale().getLocaleName()
#2
0
Following other threads here in SO, I came up with this solution that also considers the encoding used for the properties files (which can be troublesome as ResourceBundle uses by default "ISO-8859-1"):
在SO中的其他线程之后,我提出了这个解决方案,它还考虑了用于属性文件的编码(由于ResourceBundle默认使用“ISO-8859-1”,这可能会很麻烦):
import java.io.UnsupportedEncodingException;
import java.util.Locale;
import java.util.ResourceBundle;
public class MyResourceBundle {
// feature variables
private ResourceBundle bundle;
private String fileEncoding;
public MyResourceBundle(Locale locale, String fileEncoding){
this.bundle = ResourceBundle.getBundle("com.app.Bundle", locale);
this.fileEncoding = fileEncoding;
}
public MyResourceBundle(Locale locale){
this(locale, "UTF-8");
}
public String getString(String key){
String value = bundle.getString(key);
try {
return new String(value.getBytes("ISO-8859-1"), fileEncoding);
} catch (UnsupportedEncodingException e) {
return value;
}
}
}
The way to use this would be very similar than the regular ResourceBundle usage:
使用这种方法将非常类似于常规的ResourceBundle用法:
private MyResourceBundle labels = new MyResourceBundle("es", "UTF-8");
String label = labels.getString(key)
Or you can use the alternate constructor which uses UTF-8 by default:
或使用默认使用UTF-8的备用构造函数:
private MyResourceBundle labels = new MyResourceBundle("es");