How to load a javascript i18n properties file in spring?

。_饼干妹妹 提交于 2020-01-15 04:24:29

问题


I need javascript i18n in my web application which is based on Spring MVC.

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.

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.

Here is my project structure.

 └── 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

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.

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
});

}

Please help.


回答1:


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>



回答2:


Try by adding the path :-

name:'Messages', 
path:'resources/scripts/i18n/resourceBundles/', 
mode:'both',
language:'en'


来源:https://stackoverflow.com/questions/6247752/how-to-load-a-javascript-i18n-properties-file-in-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!