如何在spring中加载javascript i18n属性文件? [英] How to load a javascript i18n properties file in spring?
问题描述
我的Web应用程序中需要javascript i18n,它基于Spring MVC。
I need javascript i18n in my web application which is based on Spring MVC.
对于javascript 18n,我使用的是jQuery.i18n.properties,我发现它的URL是 http://code.google.com/p/jquery-i18n-properties/
For javascript 18n I am using jQuery.i18n.properties and the URL where I found it is http://code.google.com/p/jquery-i18n-properties/
当我运行示例应用程序时,它可以正常工作,但是当我将它集成到我的应用程序中时,它不起作用。
When I run a sample application, it works properly but when I integrate it in my application it does not work.
基本上我的javascript代码无法加载js属性文件。当我使用键显示警报时,它始终显示键但不显示键值。
Basically my javascript code is not able to load the js properties files. When I show a alert using keys, it always shows key but not the key values.
这是我的项目结构。
└── WebRoot
├── resources
│ └── scripts
│ ├── i18n
├ ├── resourceBundles
├ ├ ├── Messages_en
├ ├ ├── Messages_fr
├ ├── jquery.i18n
├ ├── jquery.i18n.properties
├──jquery-1.4.min
├──jquery-ui-1.8.2.custom.min
└── WEB-INF
├── spring
│ ├── app
│ │ ├── controllers.xml
│ │ └── servlet-context.xml
├── jsp
│ ├── home.jsp
│
└── web.xml
我有一个资源文件夹,我有一个脚本文件夹,我有我的jquery js文件。脚本文件夹还有一个i18n文件夹,我有我的i18n js文件。 i18n文件夹还有资源包文件夹,我有en和fr消息文件。
I have a resources folder where I have a scripts folder where I have my jquery js files. scripts folder also has a i18n folder where I have my i18n js files. i18n folder also has resource bundles folder where I have en and fr messages files.
在web inf中,我有一个jsp文件夹,里面有我的home jsp文件。它有以下代码
In web inf I have a jsp folder which has my home jsp file. It has following code
jQuery(document).ready(function() {
loadBundles('en');
});
function loadBundles(lang) {
jQuery.i18n.properties({
name:'resources/scripts/i18n/resourceBundles/Messages',
mode:'both',
language:lang
});
}
请帮忙。
推荐答案
尝试将 mime-type
添加到 web.xml 文件中(已测试) Tomcat 6)
Try adding mime-type
to the web.xml file (Tested in Tomcat 6)
<mime-mapping>
<extension>properties</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>
这篇关于如何在spring中加载javascript i18n属性文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!