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!