0
修訂 現在我嘗試做這在我的應用程序(感謝Akshat)如何翻譯流星中的模板?
//共同
LANG = 'ru';
Dictionary = new Meteor.Collection("dictionary");
//if server
Meteor.startup(function() {
if (Dictionary.find().count() === 0) {
// code to fill the Dictionary
}
});
Meteor.publish('dictionary', function() {
return Dictionary.find();
});
//endif
//客戶
t = function(text) {
if (typeof Dictionary === 'undefined') return text;
var res = Dictionary.find({o:text}).fetch()[0];
return res && res.t;
}
Meteor.subscribe('dictionary', function(){
document.title = t('Let the game starts!');
});
Template.help.text = t('How to play');
// HTML
<body>
{{> help}}
</body>
<template name="help">
{{text}}
</template>
Still無法正常工作:模板呈現時字典未定義。但是在控制檯中的t('How to play')
完美)
DICTIONARY.insert({o:split [0],t:split [1]});我用Dictionary.insert替換({o:split [0],t:split [1]});但在客戶端Dictionary.find()。count()仍然是zer0 – Vasiliy
您是否刪除了自動發佈?另外你在哪裏運行'Dictionary.find()。count()'?如果它在初始運行代碼中的任何位置(不在模板幫助程序中),它將返回0,因爲客戶端在運行時尚未提供數據(它幾秒後到達) – Akshat
yeap,在我添加發布和訂閱,我的收藏被轉移,發現({o:smth})的作品。以獲取屬性我使用.fetch()[0] 感謝 – Vasiliy