2011-06-06 40 views
2

我需要在我的web應用程序基於Spring MVC的JavaScript i18n。如何在spring中加載javascript i18n屬性文件?

對於JavaScript 18n的我使用jQuery.i18n.properties並在那裏我發現它是http://code.google.com/p/jquery-i18n-properties/

當我運行一個示例應用程序的URL,它工作正常,但是當我在我的應用程序將它集成這是行不通的。

基本上我的JavaScript代碼無法加載js屬性文件。當我使用密鑰顯示警報時,它始終顯示密鑰,但不顯示密鑰值。

這是我的項目結構。

└── 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消息文件。

在網絡inf我有一個jsp文件夾有我的家jsp文件。它有以下代碼

jQuery(document).ready(function() { 
    loadBundles('en'); 
}); 

function loadBundles(lang) { 
jQuery.i18n.properties({ 
    name:'resources/scripts/i18n/resourceBundles/Messages', 
    mode:'both', 
    language:lang 
}); 

} 

請幫忙。

回答

0

試圖通過添加path: -

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

嗨。謝謝回覆。我嘗試過,但即使它不工作。當我看到日誌時,它給出這個錯誤「ResourceHttpRequestHandler:handleRequest - 找不到ServletContext資源的媒體類型[/resources/scripts/i18n/resourceBundles/Messages_en.properties] - 返回404 - (ResourceHttpRequestHandler.java,第117行)」 。有任何想法嗎? – ashishjmeshram 2011-06-06 04:45:54

+0

@Ashish - 你是想用'mvc:resources'來讀取它,還是使用jQuery將它加載到java腳本中? – CoolBeans 2011-06-06 20:46:40

+0

嗨。我正在使用jQuery爲Java腳本加載它。 – ashishjmeshram 2011-06-07 03:54:25

2

嘗試增加mime-type的web.xml文件(在Tomcat中6測試)

<mime-mapping> 
    <extension>properties</extension> 
    <mime-type>text/plain</mime-type> 
</mime-mapping> 
相關問題