[英]Using jquery i18n plugin for i18n?
我正在使用 jquery i18n 插件( http://code.google.com/p/jquery-i18n-properties/ )來國際化放置在 jquery/js 中的消息。 我有以下項目結構。
我在js
文件夾中有some.js
文件,在some.js
文件中,我必須引用位於src/main/resources
文件夾的properties
文件夾中的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
。 我是否錯誤地引用了屬性文件? 我的屬性文件引用正確嗎? 請幫我。
<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>
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'));
}
});
我不嘗試,但我認為您應該將*.properties
文件放在public/resources
目錄中。
路徑應該是:
jQuery.i18n.properties({
name:'Messages',
path:'../resources/', // changed here
mode:'both',
callback: function() {
alert("message "+jQuery.i18n.prop('myForm.success.msg'));
}
嘗試一下。
將您的應用程序部署到服務器,例如。 Tomcat,然后通過服務器訪問頁面。 問題的根本原因是 html 頁面無法跨域訪問屬性文件。
不幸的是,這行不通。 JQuery 插件將始終查找webcontent
文件夾中的屬性文件。 試試這個:
將這些屬性文件復制到您的 webapp 文件夾中,並使用實際路徑對其進行測試。 例如resources/custom/i18n/
[注意 - 這里我將屬性文件放在i18n
文件夾中,並將resources
文件夾放在webapp
下]。 這將解決您的問題!
現在我們可以管理兩個文件,但我們真的需要它嗎? 最簡單的方法是將您的文件僅放在src/main/resources
文件夾中,但作為構建步驟的一部分,將此屬性文件復制到您的第二個位置(即webapp
文件夾內)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.