2017-05-10 8 views
2

私はJavascriptを理解することに苦労しています。 Odooのドキュメントは苦しいものですが、私はここで答えなしでこのトピックについて別の質問をしています:Odoo10 - How to do javascriptOdoo - JavaScriptファイルで文字列を翻訳する方法

私はこれでもっと運がいいと思います。私は今、何をしようとしている

var _t = null; 
odoo.define('mymodule.translate', function (require) { 
"use strict"; 
    var translation = require('web.translation'); 
    _t = translation._t; 
    console.log("_t assigned"); 
}); 

ビュー:

app.categoriesView = Backbone.View.extend({ 
    tagName: 'div', 
    className: 'categoriesView', 
    template: _.template($('#categories_list_template').html()), 
    initialize: function() { 
     this.title = _t('OUR PRODUCTS'); 
     console.log("Initilized title: "+this.title); 
    }, 
}); 

ポーファイル:

#. module: mymodule 
#: code:addons/mymodule/static/js/views.js:8 
#, python-format 
msgid "OUR PRODUCTS" 
msgstr "PRODUKTI" 

私はすべてのエラーと放火魔コンソールを得ることはありませんのみと言う:

_t assigned 
Initilized title: OUR PRODUCTS 

したがって、文字列は翻訳されません。私は間違って何をしていますか?

+0

あなたがにconsole.log(_T( "割り当てを"))を使用should'nt。 – Cherif

+0

いいえ..このconsole.logはちょうどそこにありますので、 "odoo.define(" completed successfully。 – user568021

+0

これをbackend_assetテンプレートに追加しましたか? – Cherif

答えて

0

私の一般的なJavaScriptの問題は残っていますが、少なくとも私は翻訳作業をしています。

この男は、ほとんど私を助け: https://www.odoo.com/forum/help-1/question/8-0-how-does-javascript-translation-tool-works-openerp-t-96934

の作業コード:

var _t = null; 

odoo.define('mymodule', function (require) { 
    "use strict"; 
    lang = $('input[name="website_lang"]').val(); //Added this input via qweb 
    var core = require('web.core'); 
    var session = require('web.session'); _s = session; 
    var utils = require('web.utils'); 
    translation = require('web.translation'); 
    var translationDataBase = new translation.TranslationDataBase(); 
    var dfd = $.Deferred(); 
    translationDataBase.load_translations(session, ['mymodule'], lang).done(function() { 
     _t = translationDataBase.build_translation_function(); 
     dfd.resolve(_t); 
    }); 
}); 
関連する問題