Skip to Content
Menu
This question has been flagged
2 Replies
7564 Views

This question in about the frontend side (Website)

var foo = openerp._t('bar')

gives:

#. module: my_module
#. openerp-web
#: code:addons/my_module/static/src/js/main.js:351
#, python-format
msgid "bar"
msgstr ""

in the generated .pot file.

However, the translation does not work.

If I put 'bar' in the, let's say, french translation file (fr.po), restart and update my module, the translation appears in the database. I can see it at Settings/Translation/Translated terms, but not on my custom view, where I insert the javascript string.


But I know that the function works sometimes. Here's a sample from a javascript console:

openerp._t('foo')
> "foo"
openerp._t('Title')
> "Civilité"

Update:

This works in console, but not in code:

var translationDataBase = new openerp.TranslationDataBase(),
    session = new openerp.Session(),
    lang = openerp.website.get_context().lang;
    
translationDataBase.load_translations(session, ['my_module'], lang);
var _t = translationDataBase.build_translation_function();

Update 2:

It seems that it has to do with Deferred objects :/ Because I set a timeout before calling _t('foo'), and that worked!

Avatar
Discard
Author Best Answer

Here's what's working now:

//  define the translation utility
openerp._translate_modules = function(modules) {
    var translationDataBase = new openerp.TranslationDataBase(),
        session = new openerp.Session(),
        lang = openerp.website.get_context().lang;

    var dfd = $.Deferred();

    translationDataBase.load_translations(session, modules, lang).done(function() {
        var _t = translationDataBase.build_translation_function(); console.log(_t);
        dfd.resolve(_t);
    });

    return dfd.promise();
}

//  use the translation utility
$.when( openerp._translate_modules(['my_module']) ).then(
    function(_t) {
        var my_string = _t('Hello world!');

        doSomethingWithIt(my_string);
    });
Avatar
Discard
Best Answer
I encountered the same problem in odoo 9.0. Can you tell me how the translation of Odoo javascript code works? 

I do not understand why my translation is not displayed while it exists in the database. The whole problem is that I do not see anything front side.
Avatar
Discard
Related Posts Replies Views Activity
1
Dec 24
127
2
Nov 24
84
1
Oct 24
264
0
Sep 24
213
2
Sep 24
648