我在javascript中有以下resourceBundle对象。
var resourceBundle = {
en : {
"EX_ONE" : "Example One",
"EX_TWO" : "Example One",
"EX_THREE" : "Example One"
}
fr : {
"EX_ONE" : "ExampleD Uno",
"EX_TWO" : "Exampled Twono",
"EX_THREE" : "Exampled theree"
}
}
但问题是,添加标签是非常糟糕的做法,我必须来这里,为所有语言添加新的键值。我的意思是这里只有英语和(错误的)法语。但是如果有其他语言呢?你能给我一个更好的方法,比如我们使用jsp和Java的属性文件。
答案 0 :(得分:0)
将您的.properties
资源包文件放在classpath(WEB-INF / classess)下,如下所示:
resources.properties
EX_ONE=Example One
EX_TWO=ExampleTwo
EX_THREE=Example Three
resources_fr.properties
EX_ONE=ExampleD Uno
EX_TWO=Exampled Twono
EX_THREE=Exampled theree
在JSP中
<%@ page language="java" import="java.util.*" %>
<%
ResourceBundle resource = ResourceBundle.getBundle("resources");
// your language is based on current locale set in request/session
String exOne=resource.getString("EX_ONE");
String exTwo=resource.getString("EX_TWO");
%>
Your localized text here:
<%
System.out.println(exOne);
System.out.println(exTwo);
%>