[IMP] ir_translation: move web_editor translation logic to module web_editor
This commit is contained in:
committed by
Christophe Matthieu
parent
8c559044a5
commit
578dba5613
@@ -3,5 +3,6 @@ import ir_attachment
|
||||
import ir_qweb
|
||||
import ir_ui_view
|
||||
import ir_http
|
||||
import ir_translation
|
||||
|
||||
import test_models
|
||||
|
||||
@@ -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: '<span data-oe-translation-id="%(id)s" data-oe-translation-state="%(state)s">%(value)s</span>' % data
|
||||
return super(ir_translation, self)._get_terms_mapping(field, records)
|
||||
@@ -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: '<span data-oe-translation-id="%s">%s</span>' % (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:
|
||||
|
||||
Reference in New Issue
Block a user