Merge lp:~therp-nl/ocb-server/6.1-lp933496 into lp:ocb-server/6.1

Proposed by Holger Brunn (Therp)
Status: Merged
Merged at revision: 4328
Proposed branch: lp:~therp-nl/ocb-server/6.1-lp933496
Merge into: lp:ocb-server/6.1
Diff against target: 386 lines (+276/-5)
10 files modified
openerp/tests/addons/test_translation_import/__init__.py (+3/-0)
openerp/tests/addons/test_translation_import/__openerp__.py (+16/-0)
openerp/tests/addons/test_translation_import/i18n/fr.po (+52/-0)
openerp/tests/addons/test_translation_import/i18n/test_translation_import.pot (+58/-0)
openerp/tests/addons/test_translation_import/models.py (+21/-0)
openerp/tests/addons/test_translation_import/tests.yml (+13/-0)
openerp/tests/addons/test_translation_import/tests/__init__.py (+10/-0)
openerp/tests/addons/test_translation_import/tests/test_term_count.py (+17/-0)
openerp/tests/addons/test_translation_import/view.xml (+23/-0)
openerp/tools/translate.py (+63/-5)
To merge this branch: bzr merge lp:~therp-nl/ocb-server/6.1-lp933496
Reviewer Review Type Date Requested Status
Lionel Sausin - Initiatives/Numérigraphe (community) Approve
Pedro Manuel Baeza code review and test Approve
Review via email: mp+193011@code.launchpad.net

Description of the change

This is a backport of the fix for translation weirdnesses in 6.1. They are bound to become worse over time, so I think we really need this for 6.1. With 7.0, I didn't run into sort like problems yet, which is why I don't propose the same thing for 7.0.

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

Hi, Holger, thank you very much for the fix. I have tried it, but the issues I was experimenting are already there. You can see here an screenshot:

http://img27.imageshack.us/img27/5065/tem5.png

I'm not sure if the problem is the same, but the beginning of the problem start more or less at the same time of the 7.0 debut.

Sorry for not being more helpful, but I don't know very well translation engine and it's very difficult to me to trace the problem.

Regards.

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

Did you do an --update=all after applying the patch? It changes the way translations are loaded, so without the update, nothing happens.

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

Yeah, I did it also on a fresh DB, so maybe the problem is another. I will investigate further when I have a little time, but do you have any tip about what is happenning?

Regards.

Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Has there been any progress on this issue?

review: Needs Information
Revision history for this message
Alberto Garcia (Factor Libre) (agarcia-flibre) wrote :

After merge there are termns isnt translated like menu purchases. I try with spanish

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

Digging deeply in the problem, I could test that the patch is working correctly. The problem comes from another place: pot files are not correct on official repository, so there's no valid translation source (neither .po nor .pot files). More info on the related bug report.

I give then my approval to this MP, but I'm going to notify the problem (maybe via another bug), and let Olivier know about it.

Regards.

review: Approve (code review and test)
Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

The patch can be further improved by using a TransientModel instead of a Model for testing. In v7.0 this fixes a warning about missing permissions. See http://bazaar.launchpad.net/~numerigraphe-team/ocb-server/7.0-po-targets-933496-vmt/revision/4798
I don't see any other problem than this detail, so I approve.

review: Approve
Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

I proceed with the merge making the change that Lionel has proposed (change to orm.TransientModel). In the unlikely case that OpenERP merge the patch in the upstream, we will have a conflict, but it's very easy to resolve.

Regards.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'openerp/tests/addons/test_translation_import'
2=== added file 'openerp/tests/addons/test_translation_import/__init__.py'
3--- openerp/tests/addons/test_translation_import/__init__.py 1970-01-01 00:00:00 +0000
4+++ openerp/tests/addons/test_translation_import/__init__.py 2013-10-29 08:06:06 +0000
5@@ -0,0 +1,3 @@
6+# -*- coding: utf-8 -*-
7+import models
8+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
9
10=== added file 'openerp/tests/addons/test_translation_import/__openerp__.py'
11--- openerp/tests/addons/test_translation_import/__openerp__.py 1970-01-01 00:00:00 +0000
12+++ openerp/tests/addons/test_translation_import/__openerp__.py 2013-10-29 08:06:06 +0000
13@@ -0,0 +1,16 @@
14+# -*- coding: utf-8 -*-
15+{
16+ 'name': 'test-translation-import',
17+ 'version': '0.1',
18+ 'category': 'Tests',
19+ 'description': """A module to test translation import.""",
20+ 'author': 'OpenERP SA',
21+ 'maintainer': 'OpenERP SA',
22+ 'website': 'http://www.openerp.com',
23+ 'depends': ['base'],
24+ 'data': ['view.xml'],
25+ 'test': ['tests.yml'],
26+ 'installable': True,
27+ 'auto_install': False,
28+}
29+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
30
31=== added directory 'openerp/tests/addons/test_translation_import/i18n'
32=== added file 'openerp/tests/addons/test_translation_import/i18n/fr.po'
33--- openerp/tests/addons/test_translation_import/i18n/fr.po 1970-01-01 00:00:00 +0000
34+++ openerp/tests/addons/test_translation_import/i18n/fr.po 2013-10-29 08:06:06 +0000
35@@ -0,0 +1,52 @@
36+# This is a test PO file, not a true french translation.
37+# See the POT file for further information.
38+msgid ""
39+msgstr ""
40+"Project-Id-Version: OpenERP Server 6.1\n"
41+"Report-Msgid-Bugs-To: \n"
42+"POT-Creation-Date: 2012-10-17 12:36+0000\n"
43+"PO-Revision-Date: 2012-10-17 12:36+0000\n"
44+"Last-Translator: <>\n"
45+"Language-Team: \n"
46+"MIME-Version: 1.0\n"
47+"Content-Type: text/plain; charset=UTF-8\n"
48+"Content-Transfer-Encoding: \n"
49+"Plural-Forms: \n"
50+
51+# Note: there is normally an additional line:
52+# #: code:addons/test_translation_import/models.py:17
53+# This line is present in the POT and removed here to test the translation
54+# import behavior.
55+#. module: test_translation_import
56+#: field:test.translation.import,name:0
57+#, python-format
58+msgid "1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB"
59+msgstr "1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB in french"
60+
61+#. module: test_translation_import
62+#: code:addons/test_translation_import/models.py:14
63+#, python-format
64+msgid "Ijkl"
65+msgstr "Ijkl in french"
66+
67+#. module: test_translation_import
68+#: model:ir.model,name:test_translation_import.model_test_translation_import
69+msgid "test.translation.import"
70+msgstr "test.translation.import in french"
71+
72+#. module: test_translation_import
73+#: help:test.translation.import,name:0
74+msgid "Efgh"
75+msgstr "Efgh in french"
76+
77+#. module: test_translation_import
78+#: model:ir.actions.act_window,name:test_translation_import.action_test_translation_import
79+#: model:ir.ui.menu,name:test_translation_import.menu_test_translation_import
80+msgid "Test translation import"
81+msgstr "Test translation import in french"
82+
83+#. module: test_translation_import
84+#: model:ir.ui.menu,name:test_translation_import.menu_test_translation
85+msgid "Test translation"
86+msgstr "Test translation in french"
87+
88
89=== added file 'openerp/tests/addons/test_translation_import/i18n/test_translation_import.pot'
90--- openerp/tests/addons/test_translation_import/i18n/test_translation_import.pot 1970-01-01 00:00:00 +0000
91+++ openerp/tests/addons/test_translation_import/i18n/test_translation_import.pot 2013-10-29 08:06:06 +0000
92@@ -0,0 +1,58 @@
93+# This is a test POT file, not a true template. It is manually maintained
94+# to test the import translation behavior of OpenERP.
95+#
96+# In particular, the
97+# `1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB` source is
98+# given with two targets (the #: comments): `code` and `field`. The code one is
99+# removed in the fr.po file. Still, the import should generate a database entry
100+# for the `code` one. I.e. the targets defined in the POT must be added to the
101+# targets defined in the PO file. This was done to fix a bug, as reported by
102+# lp:933496.
103+#
104+msgid ""
105+msgstr ""
106+"Project-Id-Version: OpenERP Server 6.1\n"
107+"Report-Msgid-Bugs-To: \n"
108+"POT-Creation-Date: 2012-10-17 12:36+0000\n"
109+"PO-Revision-Date: 2012-10-17 12:36+0000\n"
110+"Last-Translator: <>\n"
111+"Language-Team: \n"
112+"MIME-Version: 1.0\n"
113+"Content-Type: text/plain; charset=UTF-8\n"
114+"Content-Transfer-Encoding: \n"
115+"Plural-Forms: \n"
116+
117+#. module: test_translation_import
118+#: code:addons/test_translation_import/models.py:17
119+#: field:test.translation.import,name:0
120+#, python-format
121+msgid "1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB"
122+msgstr ""
123+
124+#. module: test_translation_import
125+#: code:addons/test_translation_import/models.py:14
126+#, python-format
127+msgid "Ijkl"
128+msgstr ""
129+
130+#. module: test_translation_import
131+#: model:ir.model,name:test_translation_import.model_test_translation_import
132+msgid "test.translation.import"
133+msgstr ""
134+
135+#. module: test_translation_import
136+#: help:test.translation.import,name:0
137+msgid "Efgh"
138+msgstr ""
139+
140+#. module: test_translation_import
141+#: model:ir.actions.act_window,name:test_translation_import.action_test_translation_import
142+#: model:ir.ui.menu,name:test_translation_import.menu_test_translation_import
143+msgid "Test translation import"
144+msgstr ""
145+
146+#. module: test_translation_import
147+#: model:ir.ui.menu,name:test_translation_import.menu_test_translation
148+msgid "Test translation"
149+msgstr ""
150+
151
152=== added file 'openerp/tests/addons/test_translation_import/models.py'
153--- openerp/tests/addons/test_translation_import/models.py 1970-01-01 00:00:00 +0000
154+++ openerp/tests/addons/test_translation_import/models.py 2013-10-29 08:06:06 +0000
155@@ -0,0 +1,21 @@
156+# -*- coding: utf-8 -*-
157+import openerp
158+from openerp.tools.translate import _
159+
160+class m(openerp.osv.osv.Model):
161+ """ A model to provide source strings.
162+ """
163+ _name = 'test.translation.import'
164+
165+ _columns = {
166+ 'name': openerp.osv.fields.char(
167+ '1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB',
168+ size=32, help='Efgh'),
169+ }
170+
171+ _('Ijkl')
172+
173+ # With the name label above, this source string should be generated twice.
174+ _('1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB')
175+
176+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
177
178=== added directory 'openerp/tests/addons/test_translation_import/tests'
179=== added file 'openerp/tests/addons/test_translation_import/tests.yml'
180--- openerp/tests/addons/test_translation_import/tests.yml 1970-01-01 00:00:00 +0000
181+++ openerp/tests/addons/test_translation_import/tests.yml 2013-10-29 08:06:06 +0000
182@@ -0,0 +1,13 @@
183+-
184+ Load the french translation.
185+-
186+ !python {model: ir.translation }: |
187+ import openerp
188+ openerp.tools.trans_load(cr, 'test_translation_import/i18n/fr.po', 'fr_FR', verbose=False)
189+-
190+ Assert we have loaded the correct number of entries for the given source string.
191+-
192+ !python {model: ir.translation }: |
193+ ids = self.search(cr, uid,
194+ [('src', '=', '1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB')])
195+ assert len(ids) == 2, "2 entries are expected, got %s instead." % len(ids)
196
197=== added file 'openerp/tests/addons/test_translation_import/tests/__init__.py'
198--- openerp/tests/addons/test_translation_import/tests/__init__.py 1970-01-01 00:00:00 +0000
199+++ openerp/tests/addons/test_translation_import/tests/__init__.py 2013-10-29 08:06:06 +0000
200@@ -0,0 +1,10 @@
201+# -*- coding: utf-8 -*-
202+import unittest2
203+
204+import test_term_count
205+
206+suite = [
207+ test_term_count
208+ ]
209+
210+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
211
212=== added file 'openerp/tests/addons/test_translation_import/tests/test_term_count.py'
213--- openerp/tests/addons/test_translation_import/tests/test_term_count.py 1970-01-01 00:00:00 +0000
214+++ openerp/tests/addons/test_translation_import/tests/test_term_count.py 2013-10-29 08:06:06 +0000
215@@ -0,0 +1,17 @@
216+# -*- coding: utf-8 -*-
217+
218+import openerp
219+from openerp.tests import common
220+
221+class TestTermCount(common.TransactionCase):
222+
223+ def test_count_term(self):
224+ """
225+ Just make sure we have as many translation entries as we wanted.
226+ """
227+ openerp.tools.trans_load(self.cr, 'test_translation_import/i18n/fr.po', 'fr_FR', verbose=False)
228+ ids = self.registry('ir.translation').search(self.cr, self.uid,
229+ [('src', '=', '1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB')])
230+ self.assertEqual(len(ids), 2)
231+
232+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
233
234=== added file 'openerp/tests/addons/test_translation_import/view.xml'
235--- openerp/tests/addons/test_translation_import/view.xml 1970-01-01 00:00:00 +0000
236+++ openerp/tests/addons/test_translation_import/view.xml 2013-10-29 08:06:06 +0000
237@@ -0,0 +1,23 @@
238+<?xml version="1.0" encoding="utf-8"?>
239+<openerp>
240+ <data>
241+
242+ <record id="action_test_translation_import" model="ir.actions.act_window">
243+ <field name="name">Test translation import</field>
244+ <field name="type">ir.actions.act_window</field>
245+ <field name="res_model">test.translation.import</field>
246+ <field name="view_type">form</field>
247+ <field name="view_mode">tree,form</field>
248+ <field name="target">current</field>
249+ </record>
250+
251+ <menuitem icon="STOCK_PREFERENCES" id="base.menu_tests" name="Tests"/>
252+
253+ <menuitem id="menu_test_translation" parent="base.menu_tests" name="Test translation"/>
254+
255+ <menuitem id="menu_test_translation_import"
256+ name="Test translation import"
257+ action="action_test_translation_import"
258+ parent="menu_test_translation"/>
259+ </data>
260+</openerp>
261
262=== modified file 'openerp/tools/translate.py'
263--- openerp/tools/translate.py 2012-10-08 11:09:46 +0000
264+++ openerp/tools/translate.py 2013-10-29 08:06:06 +0000
265@@ -308,6 +308,10 @@
266 if line.startswith('#~ '):
267 break
268 if line.startswith('#:'):
269+ # Process the `reference` comments. Each line can specify
270+ # multiple targets (e.g. model, view, code, selection,
271+ # ...). For each target, we will return an additional
272+ # entry.
273 for lpart in line[2:].strip().split(' '):
274 trans_info = lpart.strip().split(':',2)
275 if trans_info and len(trans_info) == 2:
276@@ -356,6 +360,9 @@
277 line = self.lines.pop(0).strip()
278
279 if tmp_tnrs and not fuzzy:
280+ # Use the first target for the current entry (returned at the
281+ # end of this next() call), and keep the others to generate
282+ # additional entries (returned the next next() calls).
283 type, name, res_id = tmp_tnrs.pop(0)
284 for t, n, r in tmp_tnrs:
285 self.tnrs.append((t, n, r, source, trad))
286@@ -897,6 +904,10 @@
287 # lets create the language with locale information
288 lang_obj.load_lang(cr, 1, lang=lang, lang_name=lang_name)
289
290+ # Parse also the POT: it will possibly provide additional targets.
291+ # (Because the POT comments are correct on Launchpad but not the
292+ # PO comments due to a Launchpad limitation.)
293+ pot_reader = []
294
295 # now, the serious things: we read the language file
296 fileobj.seek(0)
297@@ -909,19 +920,42 @@
298 elif fileformat == 'po':
299 reader = TinyPoFile(fileobj)
300 f = ['type', 'name', 'res_id', 'src', 'value']
301+
302+ # Make a reade for the POT file and be somewhat defensive for the
303+ # stable branch.
304+ if fileobj.name.endswith('.po'):
305+ try:
306+ # Normally the path looks like /path/to/xxx/i18n/lang.po
307+ # and we try to find the corresponding
308+ # /path/to/xxx/i18n/xxx.pot file.
309+ head, tail = os.path.split(fileobj.name)
310+ head2, tail2 = os.path.split(head)
311+ head3, tail3 = os.path.split(head2)
312+ pot_handle = misc.file_open(os.path.join(head3, tail3, 'i18n', tail3 + '.pot'))
313+ pot_reader = TinyPoFile(pot_handle)
314+ except:
315+ pass
316+
317 else:
318 _logger.error('Bad file format: %s', fileformat)
319 raise Exception(_('Bad file format'))
320
321+ # Read the POT `reference` comments, and keep them indexed by source
322+ # string.
323+ pot_targets = {}
324+ for type, name, res_id, src, _ in pot_reader:
325+ if type is not None:
326+ pot_targets.setdefault(src, {'value': None, 'targets': []})
327+ pot_targets[src]['targets'].append((type, name, res_id))
328+
329 # read the rest of the file
330- line = 1
331 irt_cursor = trans_obj._get_import_cursor(cr, uid, context=context)
332
333- for row in reader:
334- line += 1
335+ def process_row(row):
336+ """Process a single PO (or POT) entry."""
337 # skip empty rows and rows where the translation field (=last fiefd) is empty
338 #if (not row) or (not row[-1]):
339- # continue
340+ # return
341
342 # dictionary which holds values for this line of the csv file
343 # {'lang': ..., 'type': ..., 'name': ..., 'res_id': ...,
344@@ -933,9 +967,17 @@
345 continue
346 dic[f[i]] = row[i]
347
348+ # Get the `reference` comments from the POT.
349+ src = row[3]
350+ if pot_reader and src in pot_targets:
351+ pot_targets[src]['targets'] = filter(lambda x: x != row[:3], pot_targets[src]['targets'])
352+ pot_targets[src]['value'] = row[4]
353+ if not pot_targets[src]['targets']:
354+ del pot_targets[src]
355+
356 # This would skip terms that fail to specify a res_id
357 if not dic.get('res_id', False):
358- continue
359+ return
360
361 res_id = dic.pop('res_id')
362 if res_id and isinstance(res_id, (int, long)) \
363@@ -961,7 +1003,23 @@
364
365 irt_cursor.push(dic)
366
367+ # First process the entries from the PO file (doing so also fill/remove
368+ # the entries from the POT file).
369+ for row in reader:
370+ process_row(row)
371+
372+ # Then process the entries implied by the POT file (which is more
373+ # correct w.r.t. the targets) if some of them remain.
374+ pot_rows = []
375+ for src in pot_targets:
376+ value = pot_targets[src]['value']
377+ for type, name, res_id in pot_targets[src]['targets']:
378+ pot_rows.append((type, name, res_id, src, value))
379+ for row in pot_rows:
380+ process_row(row)
381+
382 irt_cursor.finish()
383+
384 if verbose:
385 _logger.info("translation file loaded succesfully")
386 except IOError:

Subscribers

People subscribed via source and target branches

to status/vote changes: