Merge lp:~camptocamp/web-addons/7.0-web_translate_dialog_page into lp:~webaddons-core-editors/web-addons/7.0

Proposed by Guewen Baconnier @ Camptocamp
Status: Merged
Approved by: Pedro Manuel Baeza
Approved revision: 33
Merged at revision: 20
Proposed branch: lp:~camptocamp/web-addons/7.0-web_translate_dialog_page
Merge into: lp:~webaddons-core-editors/web-addons/7.0
Diff against target: 450 lines (+404/-0)
8 files modified
web_translate_dialog/__init__.py (+1/-0)
web_translate_dialog/__openerp__.py (+44/-0)
web_translate_dialog/i18n/es.po (+36/-0)
web_translate_dialog/i18n/fr.po (+36/-0)
web_translate_dialog/i18n/web_translate_dialog.pot (+36/-0)
web_translate_dialog/static/src/css/base.css (+6/-0)
web_translate_dialog/static/src/js/web_translate_dialog.js (+211/-0)
web_translate_dialog/static/src/xml/base.xml (+34/-0)
To merge this branch: bzr merge lp:~camptocamp/web-addons/7.0-web_translate_dialog_page
Reviewer Review Type Date Requested Status
Pedro Manuel Baeza code review and test Approve
Holger Brunn (Therp) code review Approve
Joël Grand-Guillaume @ camptocamp code review, no tests Approve
Review via email: mp+198063@code.launchpad.net

Commit message

[ADD] web_translate_dialog: replace the translation view by a translation dialog like in OpenERP 6.1

Description of the change

Hello,

Here is a replacement for the translations, restoring a dialog more or less like the 6.1 one.
It also support the HTML fields.

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Guewen, what a great addition! I don't know why OpenERP changes this behaviour to an ugly one, but here it's again the community to fix it!

I have extensively tested the module and it seems to work perfectly (large texts, multiple translatable fields, three or more languages, etc). The only problem I have found is that when the height of the popup is higher than the screen height, it's not possible to make click on scrollbars. You can only scroll with the mouse scroll wheel. Is there any possibility to fix this? BTW, excelent job.

Another thing you can do is to include translation template file.

Regards.

review: Needs Fixing (code review and test)
28. By Guewen Baconnier @ Camptocamp

[FIX] display title

29. By Guewen Baconnier @ Camptocamp

[ADD] pot file

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Thanks for the test and review.

Regarding the scrollbar, it happens only on Chrome, and not on Firefox. I have to admit that I have no idea how to fix that.

I included the .pot file, but the only term that should be translated ('Translations') does not appear in the file.

Does anyone have an idea for theses 2 issues?

Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi,

Unfortunately, I do not have any idea about those 2 troubles. I've tested the solution and it really works like a charm. I had the same trouble than Pedro reported on Chrome, but no idea why... Though the mouse wheel does the trick, so I see no reason to block that MP.

That's why I'm approving it.

review: Approve (code review, no tests)
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

I have manually extracted translatable strings and make an MP with the corresponding files: https://code.launchpad.net/~pedro.baeza/web-addons/7.0-web_translate_dialog_imp/+merge/199304. Please check it.

There's is another last thing that it would be desirable to have to complete i18n: languages appear in english and in the native language, but not in the interface language. This can be for the context passed to the method that retrieves res.lang, but I have tried to change it and I got lost on JS code. Can you please see if you can improve this?

Thank you.

Regards.

review: Needs Fixing
30. By Pedro Manuel Baeza

[IMP] Translations files

31. By Guewen Baconnier @ Camptocamp

[ADD] fr translation

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

> I have manually extracted translatable strings and make an MP with the
> corresponding files: https://code.launchpad.net/~pedro.baeza/web-
> addons/7.0-web_translate_dialog_imp/+merge/199304. Please check it.
>

Thanks for the translation files, that's great. I added the french translation as well.

> There's is another last thing that it would be desirable to have to complete
> i18n: languages appear in english and in the native language, but not in the
> interface language. This can be for the context passed to the method that
> retrieves res.lang, but I have tried to change it and I got lost on JS code.
> Can you please see if you can improve this?

What do you mean by interface language?
Actually, it displays all the languages having the "translatable" boolean to True.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

I mean that in my interface (spanish) it appears:

English , Spanish/Español, French/Français, German/Deutsch ...

That it's to say: Language in english/Language in native language, where it should be:

Inglés/English, Español, Francés,/Français, Alemán/Deutsch ...

Do you understand me now?

Regards.

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

> I mean that in my interface (spanish) it appears:
>
> English , Spanish/Español, French/Français, German/Deutsch ...
>
> That it's to say: Language in english/Language in native language, where it
> should be:
>
> Inglés/English, Español, Francés,/Français, Alemán/Deutsch ...
>
> Do you understand me now?
>
> Regards.

Oh yes I got you, thanks for the precision. I first understood that a language *column* was missing ;-)
I will check that.

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

small nits:

#368, #370: trad* seem to be frenchisms to me, maybe change that to 'translation'?

review: Approve (code review)
32. By Guewen Baconnier @ Camptocamp

merge from main

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

> I mean that in my interface (spanish) it appears:
>
> English , Spanish/Español, French/Français, German/Deutsch ...
>
> That it's to say: Language in english/Language in native language, where it
> should be:
>
> Inglés/English, Español, Francés,/Français, Alemán/Deutsch ...
>
> Do you understand me now?
>
> Regards.

I checked this remark that I kept overdue for too long time.
In fact this has nothing to do with the translations.
The name on the top of the column is `res_lang.name` that is *not* a translatable field. I think that's why OpenERP put things like Spanish/Español. This is an issue that is global to OpenERP and I won't fix it there.

In my case I renamed the languages to appear only in the language's language (English / Français / Deutsch).

Can you review again so we can move forward with this proposal? Thanks

33. By Guewen Baconnier @ Camptocamp

Rename the frenchisms 'word' trads to translation

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

> small nits:
>
> #368, #370: trad* seem to be frenchisms to me, maybe change that to
> 'translation'?

For sure. That's done.

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Pedro, you still have a Needs Fixing vote. Can you review again please?

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Sorry, you have my approval, because there's nothing we can do with language names as you have remarked.

I'm going to proceed with the merge.

Thanks again for this contribution.

Regards.

review: Approve (code review and test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'web_translate_dialog'
=== added file 'web_translate_dialog/__init__.py'
--- web_translate_dialog/__init__.py 1970-01-01 00:00:00 +0000
+++ web_translate_dialog/__init__.py 2014-02-25 14:30:24 +0000
@@ -0,0 +1,1 @@
1# -*- coding: utf-8 -*-
02
=== added file 'web_translate_dialog/__openerp__.py'
--- web_translate_dialog/__openerp__.py 1970-01-01 00:00:00 +0000
+++ web_translate_dialog/__openerp__.py 2014-02-25 14:30:24 +0000
@@ -0,0 +1,44 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Guewen Baconnier
5# Copyright 2012 Camptocamp SA
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22{"name": "Web Translate Dialog",
23 "category": "Hidden",
24 "description": """
25Replace the standard translation view by an alternative one:
26
27 * Add a "Translate" button item in the "More" menu
28 * The translations are displayed in a dialog (much like the OpenERP
29 6.1's one)
30 * Support HTML fields
31 * Autosize the textareas to the size of the content
32
33""",
34 "version": "1.0",
35 "depends": ['web',
36 ],
37 'js': ['static/src/js/web_translate_dialog.js',
38 ],
39 'css': ['static/src/css/base.css',
40 ],
41 'qweb': ["static/src/xml/base.xml",
42 ],
43 'auto_install': False,
44 }
045
=== added directory 'web_translate_dialog/i18n'
=== added file 'web_translate_dialog/i18n/es.po'
--- web_translate_dialog/i18n/es.po 1970-01-01 00:00:00 +0000
+++ web_translate_dialog/i18n/es.po 2014-02-25 14:30:24 +0000
@@ -0,0 +1,36 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3#
4msgid ""
5msgstr ""
6"Project-Id-Version: OpenERP Server 7.0\n"
7"Report-Msgid-Bugs-To: \n"
8"POT-Creation-Date: 2013-12-09 07:15+0000\n"
9"PO-Revision-Date: 2013-12-13 14:09+0100\n"
10"Last-Translator: Pedro Manuel Baeza <pedro.baeza@serviciosbaeza.com>\n"
11"Language-Team: \n"
12"MIME-Version: 1.0\n"
13"Content-Type: text/plain; charset=UTF-8\n"
14"Content-Transfer-Encoding: 8bit\n"
15"Plural-Forms: \n"
16
17#. module: web_translate_dialog
18#. openerp-web
19#: code:addons/web_translate_dialog/static/src/js/web_translate_dialog.js:15
20#, python-format
21msgid "Translate"
22msgstr "Traducir"
23
24#. module: web_translate_dialog
25#. openerp-web
26#: code:addons/web_translate_dialog/static/src/js/web_translate_dialog.js:37
27#, python-format
28msgid "Translations"
29msgstr "Traducciones"
30
31#. module: web_translate_dialog
32#. openerp-web
33#: code:addons/web_translate_dialog/static/src/xml/base.xml:7
34#, python-format
35msgid "Field"
36msgstr "Campo"
037
=== added file 'web_translate_dialog/i18n/fr.po'
--- web_translate_dialog/i18n/fr.po 1970-01-01 00:00:00 +0000
+++ web_translate_dialog/i18n/fr.po 2014-02-25 14:30:24 +0000
@@ -0,0 +1,36 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3#
4msgid ""
5msgstr ""
6"Project-Id-Version: OpenERP Server 7.0\n"
7"Report-Msgid-Bugs-To: \n"
8"POT-Creation-Date: 2013-12-09 07:15+0000\n"
9"PO-Revision-Date: 2013-12-18 09:41+0100\n"
10"Last-Translator: Guewen Baconnier <guewen.baconnier@camptocamp.com>\n"
11"Language-Team: \n"
12"MIME-Version: 1.0\n"
13"Content-Type: text/plain; charset=UTF-8\n"
14"Content-Transfer-Encoding: 8bit\n"
15"Plural-Forms: \n"
16
17#. module: web_translate_dialog
18#. openerp-web
19#: code:addons/web_translate_dialog/static/src/js/web_translate_dialog.js:15
20#, python-format
21msgid "Translate"
22msgstr "Traduire"
23
24#. module: web_translate_dialog
25#. openerp-web
26#: code:addons/web_translate_dialog/static/src/js/web_translate_dialog.js:37
27#, python-format
28msgid "Translations"
29msgstr "Traductions"
30
31#. module: web_translate_dialog
32#. openerp-web
33#: code:addons/web_translate_dialog/static/src/xml/base.xml:7
34#, python-format
35msgid "Field"
36msgstr "Champ"
037
=== added file 'web_translate_dialog/i18n/web_translate_dialog.pot'
--- web_translate_dialog/i18n/web_translate_dialog.pot 1970-01-01 00:00:00 +0000
+++ web_translate_dialog/i18n/web_translate_dialog.pot 2014-02-25 14:30:24 +0000
@@ -0,0 +1,36 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3#
4msgid ""
5msgstr ""
6"Project-Id-Version: OpenERP Server 7.0\n"
7"Report-Msgid-Bugs-To: \n"
8"POT-Creation-Date: 2013-12-09 07:15+0000\n"
9"PO-Revision-Date: 2013-12-09 07:15+0000\n"
10"Last-Translator: <>\n"
11"Language-Team: \n"
12"MIME-Version: 1.0\n"
13"Content-Type: text/plain; charset=UTF-8\n"
14"Content-Transfer-Encoding: \n"
15"Plural-Forms: \n"
16
17#. module: web_translate_dialog
18#. openerp-web
19#: code:addons/web_translate_dialog/static/src/js/web_translate_dialog.js:15
20#, python-format
21msgid "Translate"
22msgstr ""
23
24#. module: web_translate_dialog
25#. openerp-web
26#: code:addons/web_translate_dialog/static/src/js/web_translate_dialog.js:37
27#, python-format
28msgid "Translations"
29msgstr ""
30
31#. module: web_translate_dialog
32#. openerp-web
33#: code:addons/web_translate_dialog/static/src/xml/base.xml:7
34#, python-format
35msgid "Field"
36msgstr ""
037
=== added directory 'web_translate_dialog/static'
=== added directory 'web_translate_dialog/static/src'
=== added directory 'web_translate_dialog/static/src/css'
=== added file 'web_translate_dialog/static/src/css/base.css'
--- web_translate_dialog/static/src/css/base.css 1970-01-01 00:00:00 +0000
+++ web_translate_dialog/static/src/css/base.css 2014-02-25 14:30:24 +0000
@@ -0,0 +1,6 @@
1.openerp .oe_translation_field {
2 width: 95%;
3}
4.openerp .oe_translation_field.touched {
5 border: 1px solid green !important;
6}
07
=== added directory 'web_translate_dialog/static/src/js'
=== added file 'web_translate_dialog/static/src/js/web_translate_dialog.js'
--- web_translate_dialog/static/src/js/web_translate_dialog.js 1970-01-01 00:00:00 +0000
+++ web_translate_dialog/static/src/js/web_translate_dialog.js 2014-02-25 14:30:24 +0000
@@ -0,0 +1,211 @@
1openerp.web_translate_dialog = function (instance) {
2
3 "use strict";
4
5 var QWeb = instance.web.qweb,
6 _t = instance.web._t,
7 _lt = instance.web._lt;
8
9 instance.web.FormView.include({
10 load_form: function(data) {
11 var self = this;
12 this._super(data);
13 if (this.sidebar) {
14 this.sidebar.add_items('other', _.compact([
15 self.is_action_enabled('edit') && { label: _t('Translate'), callback: self.on_button_translate },
16 ]));
17 }
18 },
19 on_button_translate: function() {
20 var self = this;
21 $.when(this.has_been_loaded).then(function() {
22 self.open_translate_dialog(this);
23 });
24 },
25 });
26
27 instance.web.View.include({
28 open_translate_dialog: function() {
29 new instance.web_translate_dialog.TranslateDialog(this).open();
30 }
31 });
32
33 instance.web_translate_dialog.TranslateDialog = instance.web.Dialog.extend({
34 template: "TranslateDialog",
35 init: function(parent, options, content) {
36 this._super(parent,
37 {title: _t("Translations"),
38 width: '90%',
39 height: '80%'},
40 content);
41 this.view_language = this.session.user_context.lang;
42 this.view = parent;
43 this.view_type = parent.fields_view.type || '';
44 this.$view_form = null;
45 this.$sidebar_form = null;
46 this.translatable_fields_keys = _.map(this.view.translatable_fields || [], function(i) { return i.name;});
47 this.languages = null;
48 this.languages_loaded = $.Deferred();
49 (new instance.web.DataSetSearch(this,
50 'res.lang',
51 this.view.dataset.get_context(),
52 [['translatable', '=', '1']]))
53 .read_slice(['code', 'name'], { sort: 'id' })
54 .then(this.on_languages_loaded);
55 },
56 on_languages_loaded: function(langs) {
57 this.languages = langs;
58 this.languages_loaded.resolve();
59 },
60 open: function() {
61 var self = this,
62 sup = this._super;
63 // the template needs the languages
64 $.when(this.languages_loaded).then(function() {
65 return sup.call(self);
66 });
67 },
68 start: function() {
69 var self = this;
70 this.$el.find('.oe_translation_field').change(function() {
71 $(this).toggleClass('touched', ($(this).val() != $(this).attr('data-value')));
72 });
73 this.$buttons.html(QWeb.render("TranslateDialog.buttons"));
74 this.$buttons.find(".oe_form_translate_dialog_save_button").click(function(){
75 self.on_button_save();
76 self.on_button_close();
77 });
78 this.$buttons.find(".oe_form_translate_dialog_cancel_button").click(function(){
79 self.on_button_close();
80 });
81 this.initialize_html_fields();
82
83 this.do_load_fields_values();
84 },
85 initialize_html_fields: function() {
86 this.$el.find('.oe_form_field_html textarea').each(function() {
87 var $textarea = $(this);
88 var width = 100; // forced to fixed size on initialization
89 // will be changed to percentage right after
90 // the creation
91 var height = 250;
92 $textarea.cleditor({
93 width: width, // width not including margins, borders or padding
94 height: height, // height not including margins, borders or padding
95 controls: // controls to add to the toolbar
96 "bold italic underline strikethrough " +
97 "| removeformat | bullets numbering | outdent " +
98 "indent | link unlink | source",
99 bodyStyle: // style to assign to document body contained within the editor
100 "margin:4px; color:#4c4c4c; font-size:13px; font-family:'Lucida Grande',Helvetica,Verdana,Arial,sans-serif; cursor:text"
101 });
102
103 var $cleditor = $textarea.cleditor()[0];
104 // Down to -- end, this is a workaround for the bug
105 // https://bugs.launchpad.net/openerp-web/+bug/1258463
106 // The editor is initially created with a fixed size so
107 // the buggy event is not bound to $(window), then we restore
108 // a percentage width and bind the "normal" event without the
109 // CHM's buggy change.
110 $cleditor.$main.width('95%');
111 $cleditor.options.width = '95%';
112 $(window).resize(function() {
113 //Forcefully blurred iframe contentWindow, chrome, IE, safari doesn't trigger blur on window resize and due to which text disappears
114 var contentWindow = $cleditor.$frame[0].contentWindow;
115 if(!$.browser.mozilla && contentWindow){
116 $(contentWindow).trigger('blur');
117 }
118 });
119 $cleditor.refresh();
120 // -- end
121
122 $cleditor.change(function() {
123 this.updateTextArea();
124 this.$area.toggleClass('touched',
125 (this.$area.val() != this.$area.attr('data-value')));
126 });
127 });
128 },
129 // use a `read_translations` method instead of a `read`
130 // this latter leave the fields empty if there is no
131 // translation for a field instead of taking the src field
132 do_load_fields_values: function(callback) {
133 var self = this,
134 deferred = [];
135
136 this.$el.find('.oe_translation_field').val('').removeClass('touched');
137 _.each(self.languages, function(lg) {
138 var deff = $.Deferred();
139 deferred.push(deff);
140 var callback = function(values) {
141 };
142 self.view.dataset.call(
143 'read',
144 [[self.view.datarecord.id],
145 self.translatable_fields_keys,
146 self.view.dataset.get_context({
147 'lang': lg.code
148 })]).done(function (values) {
149 _.each(self.translatable_fields_keys, function(f) {
150 self.$el.find('.oe_translation_field[name="' + lg.code + '-' + f + '"]')
151 .val(values[0][f] || '')
152 .attr('data-value', values[0][f] || '');
153
154 var $tarea = self.$el.find('.oe_form_field_html .oe_translation_field[name="' + lg.code + '-' + f + '"]');
155 if ($tarea.length) {
156 $tarea.cleditor()[0].updateFrame();
157 }
158 });
159 var $textarea = self.$el.find('textarea.oe_translation_field');
160 $textarea.css({minHeight:'100px'});
161 $textarea.autosize();
162 $(window).resize(); // triggers the autosize
163 deff.resolve();
164 });
165 });
166 return deferred;
167 },
168 on_button_save: function() {
169 var translations = {},
170 self = this,
171 translation_mutex = new $.Mutex();
172 self.$el.find('.oe_translation_field.touched').each(function() {
173 var field = $(this).attr('name').split('-');
174 if (!translations[field[0]]) {
175 translations[field[0]] = {};
176 }
177 translations[field[0]][field[1]] = $(this).val();
178 });
179 _.each(translations, function(data, code) {
180 if (code === self.view_language) {
181 _.each(data, function(value, field) {
182 var view_field = self.view.fields[field];
183 var is_dirty = view_field.view.$el.hasClass('oe_form_dirty');
184 // update the field on the view
185 view_field.set_value(value);
186 if ( !is_dirty ) {
187 // Avoid to set the view dirty when not necessary:
188 // values have already been saved.
189 view_field.view.$el.removeClass('oe_form_dirty');
190 }
191 });
192 }
193 translation_mutex.exec(function() {
194 return new instance.web.DataSet(self, self.view.dataset.model, self.view.dataset.get_context()).write(self.view.datarecord.id, data, { context : { 'lang': code }});
195 });
196 });
197 this.close();
198 },
199 on_button_close: function() {
200 this.close();
201 },
202
203 });
204
205 instance.web.form.AbstractField.include({
206 on_translate: function() {
207 // the image next to the fields opens the translate dialog
208 this.view.open_translate_dialog();
209 },
210 });
211};
0212
=== added directory 'web_translate_dialog/static/src/xml'
=== added file 'web_translate_dialog/static/src/xml/base.xml'
--- web_translate_dialog/static/src/xml/base.xml 1970-01-01 00:00:00 +0000
+++ web_translate_dialog/static/src/xml/base.xml 2014-02-25 14:30:24 +0000
@@ -0,0 +1,34 @@
1<templates>
2
3 <t t-name="TranslateDialog">
4 <table t-if="widget.view.translatable_fields" class="oe_frame oe_forms oe_translation_form" border="0" cellpadding="0" cellspacing="0" width="100%">
5 <tr>
6 <td class="oe_form_separator" width="1%" nowrap="nowrap">
7 <div class="separator horizontal">Field</div>
8 </td>
9 <th t-foreach="widget.languages" align="left">
10 <div class="separator horizontal"><t t-esc="name"/></div>
11 </th>
12 </tr>
13 <tr t-foreach="widget.view.translatable_fields" t-as="field" t-att-data-field="field.name">
14 <td class="oe_form_frame_cell" width="1%" nowrap="nowrap">
15 <label class="oe_label"><t t-esc="field.string"/>:</label>
16 </td>
17 <td t-foreach="widget.languages" t-as="lg" class="oe_form_frame_cell">
18 <input t-if="field.field.type == 'char' || field.field.type == 'url'" type="text" t-attf-name="#{lg.code}-#{field.name}" value="" data-value="" class="oe_translation_field"/>
19 <textarea t-if="field.field.type == 'text'" t-attf-name="#{lg.code}-#{field.name}" data-value="" class="oe_translation_field" ></textarea>
20 <div t-if="field.field.type == 'html'" class="oe_form_field_html">
21 <textarea class="oe_translation_field oe_form_field" t-attf-name="#{lg.code}-#{field.name}" data-value=""/>
22 </div>
23 </td>
24 </tr>
25 </table>
26 </t>
27
28 <t t-name="TranslateDialog.buttons">
29 <button class="oe_form_translate_dialog_save_button oe_button oe_highlight">Save</button>
30 <button class="oe_form_translate_dialog_cancel_button oe_button">Cancel</button>
31 </t>
32
33</templates>
34

Subscribers

People subscribed via source and target branches