struts 2 国际化不起作用
我正在开发 struts 2 和 spring web 应用程序,它支持两种语言:英语和印地语。 我已经配置了国际化,但它不起作用,即当我从浏览器更改编码时,文本不会更改。 我什至尝试以编程方式更改语言环境,但它仍然不起作用
RegisterAction.java
public class RegisterAction extends ActionSupport {
public String execute(){
return "SUCCESS";
}
public Locale getLocale(){
return new Locale("hi");
}
}
struts.xml
<action name="register" class="com.medics.action.RegisterAction">
<result name="SUCCESS">/Register.jsp</result>
</action>
Register.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<h4><s:text name="Registration"/></h4>
global-messages.properties
hello=hello
Registration=Registration
global-messages_hi.properties
Registration=\\u2354\\u2379\\u327\\u2367\\u2344\\u2381
这里是项目 struts.xml 的快照
,两个消息文件是在类路径的根目录中
I am developing struts 2 and spring web application which suppoerts two languages: english and hindi.
I have configured internationalization but it is not working i.e. when I change the encoding from browser, the text does not change.
I have tried to even change the locale programitically but it still does not work
RegisterAction.java
public class RegisterAction extends ActionSupport {
public String execute(){
return "SUCCESS";
}
public Locale getLocale(){
return new Locale("hi");
}
}
struts.xml
<action name="register" class="com.medics.action.RegisterAction">
<result name="SUCCESS">/Register.jsp</result>
</action>
Register.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<h4><s:text name="Registration"/></h4>
global-messages.properties
hello=hello
Registration=Registration
global-messages_hi.properties
Registration=\\u2354\\u2379\\u327\\u2367\\u2344\\u2381
here is the snapshot of the project
struts.xml and the two messages files are in the root of the classpath
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,您将密钥命名为与英语值相同的名称,因此您无法真正判断英语包是否已正确加载。我的第一个猜测是 Struts 不知道 global-messages*.properties 是语言包。
尝试将其添加到您的 struts.xml:
编辑
如果您确定正在加载英语包,那么您将需要调试应用程序以确认 Struts2 正确设置了印地语区域设置。操作中的断点应该允许您轻松检查
getLocale()
的值。Unfortunately, you named your keys the same as your values in English, so you can't really tell if the English bundle is being loaded properly either. My first guess is that Struts does not know that global-messages*.properties are language bundles.
Try adding this to your struts.xml:
Edit
If you are sure that the English bundle is loading, then you'll want to debug the application to confirm that the Hindi locale is being set properly by Struts2. A breakpoint in your action should allow you to easily check the value of
getLocale()
.