diff options
| author | Vo Minh Thu <vmt@openerp.com> | 2014-08-13 22:59:13 +0200 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2014-08-13 23:07:40 +0200 |
| commit | 680214c47e80f30d2fd62cd56dfd6169dd9f2fbb (patch) | |
| tree | 97fbd6353e17dce1f14278932985ef373779d914 /openerp/tests/addons | |
| parent | 23cffab1f8cab7f456df56e6f1b002f4fa9b2ef0 (diff) | |
[FIX] tools.translate: when loading entries from a PO file, use also the POT.
On Launchpad, as commented on bug 933496, PO entries (and their comments) are
shared between series. This mean that e.g. the 7.0 series can have the wrong
`reference` comments (those beginning with #:) as they would be copied from say
the trunk series. Those `reference` comments are used to import translations
and look them up.
This patch adds a few lines of code to tools.translate so that targets
defined in the POT `reference` comments are used in addition to those from the
PO file.
Also adds a test module to validate the new behavior.
This patch stems from:
- the 6.1 branch by Vo Minh Thu:
https://code.launchpad.net/+branch/~openerp-dev/openobject-server/6.1-fix-po-targets-933496-vmt
- the 7.0 port by Numerigraphe:
https://code.launchpad.net/~numerigraphe-team/openobject-server/7.0-fix-po-targets-933496-vmt
Diffstat (limited to 'openerp/tests/addons')
9 files changed, 208 insertions, 0 deletions
diff --git a/openerp/tests/addons/test_translation_import/__init__.py b/openerp/tests/addons/test_translation_import/__init__.py new file mode 100644 index 00000000000..89d26e2f597 --- /dev/null +++ b/openerp/tests/addons/test_translation_import/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +import models diff --git a/openerp/tests/addons/test_translation_import/__openerp__.py b/openerp/tests/addons/test_translation_import/__openerp__.py new file mode 100644 index 00000000000..29c3c596396 --- /dev/null +++ b/openerp/tests/addons/test_translation_import/__openerp__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +{ + 'name': 'test-translation-import', + 'version': '0.1', + 'category': 'Tests', + 'description': """A module to test translation import.""", + 'author': 'OpenERP SA', + 'maintainer': 'OpenERP SA', + 'website': 'http://www.openerp.com', + 'depends': ['base'], + 'data': ['view.xml'], + 'test': ['tests.yml'], + 'installable': True, + 'auto_install': False, +} diff --git a/openerp/tests/addons/test_translation_import/i18n/fr.po b/openerp/tests/addons/test_translation_import/i18n/fr.po new file mode 100644 index 00000000000..f179cc1eefd --- /dev/null +++ b/openerp/tests/addons/test_translation_import/i18n/fr.po @@ -0,0 +1,52 @@ +# This is a test PO file, not a true french translation. +# See the POT file for further information. +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 6.1\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-10-17 12:36+0000\n" +"PO-Revision-Date: 2012-10-17 12:36+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +# Note: there is normally an additional line: +# #: code:addons/test_translation_import/models.py:17 +# This line is present in the POT and removed here to test the translation +# import behavior. +#. module: test_translation_import +#: field:test.translation.import,name:0 +#, python-format +msgid "1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB" +msgstr "1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB in french" + +#. module: test_translation_import +#: code:addons/test_translation_import/models.py:14 +#, python-format +msgid "Ijkl" +msgstr "Ijkl in french" + +#. module: test_translation_import +#: model:ir.model,name:test_translation_import.model_test_translation_import +msgid "test.translation.import" +msgstr "test.translation.import in french" + +#. module: test_translation_import +#: help:test.translation.import,name:0 +msgid "Efgh" +msgstr "Efgh in french" + +#. module: test_translation_import +#: model:ir.actions.act_window,name:test_translation_import.action_test_translation_import +#: model:ir.ui.menu,name:test_translation_import.menu_test_translation_import +msgid "Test translation import" +msgstr "Test translation import in french" + +#. module: test_translation_import +#: model:ir.ui.menu,name:test_translation_import.menu_test_translation +msgid "Test translation" +msgstr "Test translation in french" + diff --git a/openerp/tests/addons/test_translation_import/i18n/test_translation_import.pot b/openerp/tests/addons/test_translation_import/i18n/test_translation_import.pot new file mode 100644 index 00000000000..034fa5254dc --- /dev/null +++ b/openerp/tests/addons/test_translation_import/i18n/test_translation_import.pot @@ -0,0 +1,58 @@ +# This is a test POT file, not a true template. It is manually maintained +# to test the import translation behavior of OpenERP. +# +# In particular, the +# `1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB` source is +# given with two targets (the #: comments): `code` and `field`. The code one is +# removed in the fr.po file. Still, the import should generate a database entry +# for the `code` one. I.e. the targets defined in the POT must be added to the +# targets defined in the PO file. This was done to fix a bug, as reported by +# lp:933496. +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 6.1\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-10-17 12:36+0000\n" +"PO-Revision-Date: 2012-10-17 12:36+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: test_translation_import +#: code:addons/test_translation_import/models.py:17 +#: field:test.translation.import,name:0 +#, python-format +msgid "1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB" +msgstr "" + +#. module: test_translation_import +#: code:addons/test_translation_import/models.py:14 +#, python-format +msgid "Ijkl" +msgstr "" + +#. module: test_translation_import +#: model:ir.model,name:test_translation_import.model_test_translation_import +msgid "test.translation.import" +msgstr "" + +#. module: test_translation_import +#: help:test.translation.import,name:0 +msgid "Efgh" +msgstr "" + +#. module: test_translation_import +#: model:ir.actions.act_window,name:test_translation_import.action_test_translation_import +#: model:ir.ui.menu,name:test_translation_import.menu_test_translation_import +msgid "Test translation import" +msgstr "" + +#. module: test_translation_import +#: model:ir.ui.menu,name:test_translation_import.menu_test_translation +msgid "Test translation" +msgstr "" + diff --git a/openerp/tests/addons/test_translation_import/models.py b/openerp/tests/addons/test_translation_import/models.py new file mode 100644 index 00000000000..3dc3f1c71cc --- /dev/null +++ b/openerp/tests/addons/test_translation_import/models.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +import openerp +from openerp.tools.translate import _ + +class m(openerp.osv.orm.TransientModel): + """ A model to provide source strings. + """ + _name = 'test.translation.import' + + _columns = { + 'name': openerp.osv.fields.char( + '1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB', + size=32, help='Efgh'), + } + + _('Ijkl') + + # With the name label above, this source string should be generated twice. + _('1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB') + diff --git a/openerp/tests/addons/test_translation_import/tests.yml b/openerp/tests/addons/test_translation_import/tests.yml new file mode 100644 index 00000000000..8ccae43f6ee --- /dev/null +++ b/openerp/tests/addons/test_translation_import/tests.yml @@ -0,0 +1,13 @@ +- + Load the french translation. +- + !python {model: ir.translation }: | + import openerp + openerp.tools.trans_load(cr, 'test_translation_import/i18n/fr.po', 'fr_FR', verbose=False) +- + Assert we have loaded the correct number of entries for the given source string. +- + !python {model: ir.translation }: | + ids = self.search(cr, uid, + [('src', '=', '1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB')]) + assert len(ids) == 2, "2 entries are expected, got %s instead." % len(ids) diff --git a/openerp/tests/addons/test_translation_import/tests/__init__.py b/openerp/tests/addons/test_translation_import/tests/__init__.py new file mode 100644 index 00000000000..09e712b0f80 --- /dev/null +++ b/openerp/tests/addons/test_translation_import/tests/__init__.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +import unittest2 + +import test_term_count + +suite = [ + test_term_count + ] + diff --git a/openerp/tests/addons/test_translation_import/tests/test_term_count.py b/openerp/tests/addons/test_translation_import/tests/test_term_count.py new file mode 100644 index 00000000000..2d065b05f18 --- /dev/null +++ b/openerp/tests/addons/test_translation_import/tests/test_term_count.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- + +import openerp +from openerp.tests import common + +class TestTermCount(common.TransactionCase): + + def test_count_term(self): + """ + Just make sure we have as many translation entries as we wanted. + """ + openerp.tools.trans_load(self.cr, 'test_translation_import/i18n/fr.po', 'fr_FR', verbose=False) + ids = self.registry('ir.translation').search(self.cr, self.uid, + [('src', '=', '1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB')]) + self.assertEqual(len(ids), 2) + diff --git a/openerp/tests/addons/test_translation_import/view.xml b/openerp/tests/addons/test_translation_import/view.xml new file mode 100644 index 00000000000..2fb26fbbdc5 --- /dev/null +++ b/openerp/tests/addons/test_translation_import/view.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<openerp> + <data> + + <record id="action_test_translation_import" model="ir.actions.act_window"> + <field name="name">Test translation import</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">test.translation.import</field> + <field name="view_type">form</field> + <field name="view_mode">tree,form</field> + <field name="target">current</field> + </record> + + <menuitem icon="STOCK_PREFERENCES" id="base.menu_tests" name="Tests"/> + + <menuitem id="menu_test_translation" parent="base.menu_tests" name="Test translation"/> + + <menuitem id="menu_test_translation_import" + name="Test translation import" + action="action_test_translation_import" + parent="menu_test_translation"/> + </data> +</openerp> |
