diff options
| author | Fabien Meghazi <fme@openerp.com> | 2013-09-24 21:06:37 +0200 |
|---|---|---|
| committer | Fabien Meghazi <fme@openerp.com> | 2013-09-24 21:06:37 +0200 |
| commit | f79d27e9a3a9fb1d16d2af44d3f0f8a1eb4abf1a (patch) | |
| tree | 5aea34014993e5f77fa0590c16d85a8357823e60 /addons/website/static/src | |
| parent | bcd3f471ad16f4a9a2ebe7c75e12d3cc1eaf6e73 (diff) | |
[FIX] Update translations
bzr revid: fme@openerp.com-20130924190637-0qgzp58lzan8j1oc
Diffstat (limited to 'addons/website/static/src')
| -rw-r--r-- | addons/website/static/src/css/editor.css | 4 | ||||
| -rw-r--r-- | addons/website/static/src/css/editor.sass | 2 | ||||
| -rw-r--r-- | addons/website/static/src/js/website.translator.js | 48 |
3 files changed, 35 insertions, 19 deletions
diff --git a/addons/website/static/src/css/editor.css b/addons/website/static/src/css/editor.css index b6cc8505fed..da15826cd2d 100644 --- a/addons/website/static/src/css/editor.css +++ b/addons/website/static/src/css/editor.css @@ -124,6 +124,10 @@ table.editorbar-panel td.selected { outline-color: red; } +.oe_translatable_text.oe_dirty:empty { + padding: 0 10px; +} + .oe_translatable_todo { background: #ffffb6; } diff --git a/addons/website/static/src/css/editor.sass b/addons/website/static/src/css/editor.sass index b5c0b21a197..00ee3df5014 100644 --- a/addons/website/static/src/css/editor.sass +++ b/addons/website/static/src/css/editor.sass @@ -103,6 +103,8 @@ table.editorbar-panel outline: 1px dashed black .oe_translatable_text.oe_dirty, .oe_translatable_field.oe_dirty outline-color: red +.oe_translatable_text.oe_dirty:empty + padding: 0 10px .oe_translatable_todo background: rgb(255, 255, 182) // }}} diff --git a/addons/website/static/src/js/website.translator.js b/addons/website/static/src/js/website.translator.js index d1701db5b2f..39408234b6f 100644 --- a/addons/website/static/src/js/website.translator.js +++ b/addons/website/static/src/js/website.translator.js @@ -40,7 +40,7 @@ this.translations = null; openerp.jsonRpc('/website/get_view_translations', 'call', { 'xml_id': $(document.documentElement).data('view-xmlid'), - 'context': website.get_context(), + 'lang': website.get_context().lang, }).then(function (translations) { self.translations = translations; self.processTranslatableNodes(); @@ -48,12 +48,13 @@ }, processTranslatableNodes: function () { var self = this; - var $editables = $('[data-oe-model]') + var $editables = $('[data-oe-model="ir.ui.view"]') .not('link, script') .not('.oe_snippets,.oe_snippet, .oe_snippet *') .not('[data-oe-type]'); + $editables.each(function () { - self.transNode(this); + self.transNode(this, $(this).attr('data-oe-id')|0); }); $('.oe_translatable_text').prop('contenteditable', true).on('paste', function () { var node = $(this); @@ -64,7 +65,7 @@ $(document).on('blur keyup paste', '.oe_translatable_text[contenteditable]', function(ev) { var $node = $(this); setTimeout(function () { - // Doing stuff next tick because past and keyup are + // Doing stuff next tick because paste and keyup events are // fired before the content is changed if (ev.type == 'paste') { self.sanitizeNode($node[0]); @@ -84,26 +85,35 @@ isTranslatable: function (text) { return text && _.str.trim(text) !== ''; }, - markTranslatableNode: function (node) { + markTranslatableNode: function (node, view_id) { // TODO: link nodes with same content - node.className += ' oe_translatable_text oe_translatable_todo'; + node.className += ' oe_translatable_text'; + node.setAttribute('data-oe-translation-view-id', view_id); + var content = node.childNodes[0].data.trim(); + var trans = this.translations.filter(function (t) { + return t.res_id === view_id && t.value === content; + }); + if (trans.length) { + node.setAttribute('data-oe-translation-id', trans[0].id); + } else { + node.className += ' oe_translatable_todo'; + } node.contentEditable = true; - $(node).data('initial_content', node.childNodes[0].data); + $(node).data('initial_content', content); }, save: function () { var trans = {}; // this._super.apply(this, arguments); $('.oe_translatable_text.oe_dirty').each(function () { var $node = $(this); - var text = $node.text(); - var view_id = $(this).parents('[data-oe-model="ir.ui.view"]') - .not('[data-oe-type]').first().data().oeId; - if (!trans[view_id]) { - trans[view_id] = []; + var data = $node.data(); + if (!trans[data.oeTranslationViewId]) { + trans[data.oeTranslationViewId] = []; } - trans[view_id].push({ - initial_content: $node.data('initial_content'), - new_content: text + trans[data.oeTranslationViewId].push({ + initial_content: data.initial_content, + new_content: $node.text(), + translation_id: data.oeTranslationId || null }); }); openerp.jsonRpc('/website/set_translations', 'call', { @@ -116,11 +126,11 @@ alert("Could not save translation"); }); }, - transNode: function (node, context) { + transNode: function (node, view_id) { if (node.childNodes.length === 1 && this.isTextNode(node.childNodes[0]) && !node.getAttribute('data-oe-model')) { - this.markTranslatableNode(node); + this.markTranslatableNode(node, view_id); } else { for (var i = 0, l = node.childNodes.length; i < l; i ++) { var n = node.childNodes[i]; @@ -129,10 +139,10 @@ var container = document.createElement('span'); node.insertBefore(container, n); container.appendChild(n); - this.markTranslatableNode(container); + this.markTranslatableNode(container, view_id); } } else { - this.transNode(n); + this.transNode(n, view_id); } } } |
