【发布时间】:2014-05-30 12:18:58
【问题描述】:
我无法让 wikimedia 的 jquery.i18n 插件处理外部文件。
这个:
// Localisation
$.i18n.debug = true;
$.i18n().load( {
'fr' : {
'message-hello' : 'bonjour!'
},
'en': '/assets/i18n/en.json'
} );
$.i18n().locale = 'fr';
console.log($.i18n('message-hello'));
运行良好。控制台说:
Loading messages from: /assets/i18n/en.json jquery.i18n.js:269
bonjour!
但是这个:
// Localisation
$.i18n.debug = true;
$.i18n().load( {
'fr' : {
'message-hello' : 'bonjour!'
},
'en': '/assets/i18n/en.json'
} );
$.i18n().locale = 'en';
console.log($.i18n('message-hello'));
不是。控制台说:
Loading messages from: /assets/i18n/en.json jquery.i18n.js:269
message-hello
我错过了什么?
这是我的/assets/i18n/en.json 文件:
{
"@metadata": {
"authors": [
"Alice",
"David",
"Santhosh"
],
"last-updated": "2012-09-21",
"locale": "en",
"message-documentation": "qqq",
"AnotherMetadata": "AnotherMedatadataValue"
},
"appname-title": "Example Application",
"appname-sub-title": "An example application with jquery.i18n",
"appname-header-introduction": "Introduction",
"appname-about": "About this application",
"appname-footer": "Footer text",
"message-hello": "hello!"
}
编辑:如果我从控制台执行$.i18n('message-hello'),它可以工作。这可能是因为当我从脚本调用$.i18n('message-hello') 时,json 文件尚未加载?如果是这样,我怎么能告诉脚本等到它呢?
【问题讨论】:
-
如果你这样做
$.i18n.prop('message-hello')会发生什么? -
我收到
TypeError: undefined is not a function
标签: javascript jquery internationalization wikimedia