[FIX] web_editor: translation feature for all string fields on website
* add the branding in translation mode * change javascript to add the lang in the context (automatically removed in the rte => allow to create record and edit when use an other default language of en_US) * avoid double saved
This commit is contained in:
@@ -28,6 +28,7 @@ from openerp.osv import orm, fields
|
||||
from openerp.tools import ustr, DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
|
||||
from openerp.tools import html_escape as escape
|
||||
from openerp.addons.base.ir import ir_qweb
|
||||
from openerp.tools.translate import translate
|
||||
|
||||
REMOTE_CONNECTION_TIMEOUT = 2.5
|
||||
|
||||
@@ -82,6 +83,12 @@ class Field(orm.AbstractModel):
|
||||
if placeholder:
|
||||
attrs.append(('placeholder', placeholder))
|
||||
|
||||
if context and context.get('edit_translations') and context.get('translatable') and field.type in ('char', 'text') and field.translate:
|
||||
name = "%s,%s" % (record._model._name, field_name)
|
||||
domain = [('name', '=', name), ('res_id', '=', record.id), ('type', '=', 'model'), ('lang', '=', context.get('lang'))]
|
||||
translation = record.env['ir.translation'].search(domain, limit=1)
|
||||
attrs.append(('data-oe-translation-state', translation and translation.state or 'to_translate'))
|
||||
|
||||
return itertools.chain(
|
||||
super(Field, self).attributes(cr, uid, field_name, record, options,
|
||||
source_element, g_att, t_att,
|
||||
|
||||
@@ -37,10 +37,12 @@ $.fn.extend({
|
||||
var RTE_Translate = rte.Class.extend({
|
||||
saveElement: function ($el, context) {
|
||||
// remove multi edition
|
||||
var key = $el.data('oe-translation-id') ? 'translation:'+$el.data('oe-translation-id') :
|
||||
($el.data('oe-model') ? $el.data('oe-model')+":"+$el.data('oe-id')+":"+$el.data('oe-field')+":"+$el.data('oe-type')+":"+$el.data('oe-expression') : false);
|
||||
if (!key || this.__saved[key]) return true;
|
||||
this.__saved[key] = true;
|
||||
|
||||
if ($el.data('oe-translation-id')) {
|
||||
var key = 'translation:'+$el.data('oe-translation-id');
|
||||
if (this.__saved[key]) return true;
|
||||
this.__saved[key] = true;
|
||||
var translation_content = this.getEscapedElement($el).html();
|
||||
|
||||
return ajax.jsonRpc('/web/dataset/call', 'call', {
|
||||
@@ -48,13 +50,24 @@ var RTE_Translate = rte.Class.extend({
|
||||
method: 'write',
|
||||
args: [
|
||||
[+$el.data('oe-translation-id')],
|
||||
{value: translation_content, state: 'translated'},
|
||||
{'value': translation_content, 'state': 'translated'},
|
||||
context || base.get_context()
|
||||
],
|
||||
});
|
||||
} else {
|
||||
var markup = this.getEscapedElement($el).prop('outerHTML');
|
||||
|
||||
return ajax.jsonRpc('/web/dataset/call', 'call', {
|
||||
model: 'ir.ui.view',
|
||||
method: 'save',
|
||||
args: [
|
||||
$el.data('oe-id'),
|
||||
markup,
|
||||
$el.data('oe-xpath') || null,
|
||||
context || base.get_context()
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -107,7 +120,10 @@ var Translate = Widget.extend({
|
||||
return this.edit();
|
||||
},
|
||||
setTarget: function ($target) {
|
||||
this.$target = $target.find('[data-oe-translation-id], [data-oe-model][data-oe-id][data-oe-field]');
|
||||
var $edit = $target.find('[data-oe-translation-id], [data-oe-model][data-oe-id][data-oe-field]');
|
||||
$edit.filter(':has([data-oe-translation-id], [data-oe-model][data-oe-id][data-oe-field])').attr('data-oe-readonly', true);
|
||||
|
||||
this.$target = $edit.not('[data-oe-readonly]');
|
||||
|
||||
// attributes
|
||||
|
||||
@@ -192,7 +208,7 @@ var Translate = Widget.extend({
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (event.type !== 'click') {
|
||||
if (event.type !== 'mousedown') {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -302,6 +318,8 @@ if (edit_translations) {
|
||||
$('form[action*=edit_translations]').each(function () {
|
||||
this.action = this.action.replace(/[$?]edit_translations[^&?]+/, '');
|
||||
});
|
||||
|
||||
$('title').html($('title').html().replace(/<span data-oe-translation-id.+?>(.+?)<\/span>/, '\$1'));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -635,7 +635,9 @@ class FieldConverter(osv.AbstractModel):
|
||||
if not inherit_branding and context and context.get('inherit_branding_auto'):
|
||||
inherit_branding = self.pool['ir.model.access'].check(cr, uid, record._name, 'write', False, context=context)
|
||||
|
||||
if inherit_branding:
|
||||
translate = context and context.get('edit_translations') and context.get('translatable') and record._columns[field_name].translate
|
||||
|
||||
if inherit_branding or translate:
|
||||
# add branding attributes
|
||||
g_att += ''.join(
|
||||
_build_attribute(name, value)
|
||||
|
||||
Reference in New Issue
Block a user