我正在使用jquery i18n插件( http://code.google.com/p/jquery-i18n-properties/ )来国际化放置在jquery/js中的消息。我有下面的项目结构。

我在js文件夹中有some.js文件,在some.js文件中,我必须引用位于src/main/resources文件夹的properties文件夹中的属性文件。我可以这样做吗?在src/main/resources文件夹的properties文件夹中,我放置了Messages.properties和Messages_en_US.properties。在这两个属性文件中,我都放置了myForm.success.msg=Success属性。现在,我正在尝试访问它,如下所示。但是下面的代码没有得到myForm.success.msg键的值。instead of giving value, it is giving the key itself but not the value。我是不是引用了错误的属性文件?我的属性文件引用是否正确?请帮帮我。
JSP代码:
<script type="text/javascript" src="./public/js/some.js"></script>
<script type="text/javascript" src="./public/js/jquery.i18n.properties-min-1.0.9.js"></script>some.js
jQuery.i18n.properties({
name:'Messages',
path:'properties/', //as i have properties file in properties folder of src/main/resources
mode:'both',
callback: function() {
alert("message "+jQuery.i18n.prop('myForm.success.msg'));
}
});发布于 2014-09-19 00:46:50
我不尝试,但我认为您应该将*.properties文件放在public/resources目录中。
路径应该是:
jQuery.i18n.properties({
name:'Messages',
path:'../resources/', // changed here
mode:'both',
callback: function() {
alert("message "+jQuery.i18n.prop('myForm.success.msg'));
}试试看。
发布于 2015-08-25 16:43:35
将你的应用程序部署到服务器上,例如。Tomcat,然后通过服务器访问页面。问题的根本原因是html页面无法跨域访问属性文件。
发布于 2015-09-22 04:56:25
不幸的是,这是行不通的。JQuery插件将始终查找webcontent文件夹中的属性文件。试着这样做:
resources/custom/i18n/注释-在这里,我将属性文件放在一个i18n文件夹中,并在webapp下放了一个resources文件夹。这将解决您的问题!src/main/resources文件夹中,但作为构建步骤的一部分,请将此属性文件复制到第二个位置(即在webapp文件夹中)。https://stackoverflow.com/questions/18531201
复制相似问题