From 578dba56133e0b5bfb2c04a7f8f962aec00f920a Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Wed, 8 Jul 2015 11:55:14 +0200 Subject: [PATCH] [IMP] ir_translation: move web_editor translation logic to module web_editor --- addons/web_editor/models/__init__.py | 1 + addons/web_editor/models/ir_translation.py | 14 ++++++++++++++ openerp/addons/base/ir/ir_translation.py | 17 ++++++----------- 3 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 addons/web_editor/models/ir_translation.py diff --git a/addons/web_editor/models/__init__.py b/addons/web_editor/models/__init__.py index 43522002bfc..e4dbfa5ad4f 100644 --- a/addons/web_editor/models/__init__.py +++ b/addons/web_editor/models/__init__.py @@ -3,5 +3,6 @@ import ir_attachment import ir_qweb import ir_ui_view import ir_http +import ir_translation import test_models diff --git a/addons/web_editor/models/ir_translation.py b/addons/web_editor/models/ir_translation.py new file mode 100644 index 00000000000..d54591908bd --- /dev/null +++ b/addons/web_editor/models/ir_translation.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from openerp import models, api + +class ir_translation(models.Model): + _inherit = 'ir.translation' + + @api.model + def _get_terms_mapping(self, field, records): + if self._context.get('edit_translations'): + self.insert_missing(field, records) + return lambda data: '%(value)s' % data + return super(ir_translation, self)._get_terms_mapping(field, records) diff --git a/openerp/addons/base/ir/ir_translation.py b/openerp/addons/base/ir/ir_translation.py index 37e69fafaf3..1392231bdf2 100644 --- a/openerp/addons/base/ir/ir_translation.py +++ b/openerp/addons/base/ir/ir_translation.py @@ -380,7 +380,7 @@ class ir_translation(osv.osv): @api.model def _get_terms_query(self, field, records): """ Utility function that makes the query for field terms. """ - query = """ SELECT id, res_id, src, value FROM ir_translation + query = """ SELECT * FROM ir_translation WHERE lang=%s AND type=%s AND name=%s AND res_id IN %s """ name = "%s,%s" % (field.model_name, field.name) params = (records.env.lang, 'model', name, tuple(records.ids)) @@ -388,15 +388,10 @@ class ir_translation(osv.osv): @api.model def _get_terms_mapping(self, field, records): - """ Return a function mapping a (trans_id, source, value) to a value. + """ Return a function mapping a ir_translation row (dict) to a value. This method is called before querying the database for translations. """ - if self._context.get('edit_translations'): - # TODO: this part should be moved to module web_editor - self.insert_missing(field, records) - return lambda tid, src, value: '%s' % (tid, value) - else: - return lambda tid, src, value: value + return lambda data: data['value'] @api.model def _get_terms_translations(self, field, records): @@ -409,8 +404,8 @@ class ir_translation(osv.osv): map_trans = self._get_terms_mapping(field, records) query, params = self._get_terms_query(field, records) self._cr.execute(query, params) - for trans_id, res_id, src, value in self._cr.fetchall(): - result[res_id][src] = map_trans(trans_id, src, value) + for data in self._cr.dictfetchall(): + result[data['res_id']][data['src']] = map_trans(data) return result @api.model @@ -648,7 +643,7 @@ class ir_translation(osv.osv): _logger.info('module %s: loading translation file (%s) for language %s', module_name, lang_code, lang) tools.trans_load(cr, trans_file, lang, verbose=False, module_name=module_name, context=context) elif lang_code != 'en_US': - _logger.warning('module %s: no translation for language %s', module_name, lang_code) + _logger.info('module %s: no translation for language %s', module_name, lang_code) trans_extra_file = openerp.modules.get_module_resource(module_name, 'i18n_extra', lang_code + '.po') if trans_extra_file: