[i18n] properly translate error messages related to violated unicity constraint.
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 18 Mar 2015 22:43:51 +0100
changeset 10280 2cdab5e33542
parent 10279 d7479a5ac553
child 10281 cc9eb88377f4
[i18n] properly translate error messages related to violated unicity constraint. Closes #5100373
_exceptions.py
entities/adapters.py
entities/test/unittest_wfobjs.py
i18n/de.po
i18n/en.po
i18n/es.po
i18n/fr.po
server/test/unittest_repository.py
--- a/_exceptions.py	Wed Feb 04 15:13:36 2015 +0100
+++ b/_exceptions.py	Wed Mar 18 22:43:51 2015 +0100
@@ -23,7 +23,7 @@
 
 from logilab.common.decorators import cachedproperty
 
-from yams import ValidationError as ValidationError
+from yams import ValidationError
 
 # abstract exceptions #########################################################
 
--- a/entities/adapters.py	Wed Feb 04 15:13:36 2015 +0100
+++ b/entities/adapters.py	Wed Mar 18 22:43:51 2015 +0100
@@ -20,6 +20,7 @@
 """
 
 __docformat__ = "restructuredtext en"
+_ = unicode
 
 from itertools import chain
 from warnings import warn
@@ -359,11 +360,13 @@
     __select__ = match_exception(UniqueTogetherError)
 
     def raise_user_exception(self):
-        _ = self._cw._
         rtypes = self.exc.rtypes
-        rtypes_msg = {}
+        errors = {}
+        msgargs = {}
+        i18nvalues = []
         for rtype in rtypes:
-            rtypes_msg[rtype] = _('%s is part of violated unicity constraint') % rtype
-        globalmsg = _('some relations violate a unicity constraint')
-        rtypes_msg['unicity constraint'] = globalmsg
-        raise ValidationError(self.entity.eid, rtypes_msg)
+            errors[rtype] = _('%(KEY-rtype)s is part of violated unicity constraint')
+            msgargs[rtype + '-rtype'] = rtype
+            i18nvalues.append(rtype + '-rtype')
+        errors[''] = _('some relations violate a unicity constraint')
+        raise ValidationError(self.entity.eid, errors, msgargs=msgargs, i18nvalues=i18nvalues)
--- a/entities/test/unittest_wfobjs.py	Wed Feb 04 15:13:36 2015 +0100
+++ b/entities/test/unittest_wfobjs.py	Wed Mar 18 22:43:51 2015 +0100
@@ -52,9 +52,9 @@
             shell.commit()
             with self.assertRaises(ValidationError) as cm:
                 wf.add_state(u'foo')
-            self.assertEqual({'name': u'name is part of violated unicity constraint',
-                              'state_of': u'state_of is part of violated unicity constraint',
-                              'unicity constraint': u'some relations violate a unicity constraint'},
+            self.assertEqual({'name': u'%(KEY-rtype)s is part of violated unicity constraint',
+                              'state_of': u'%(KEY-rtype)s is part of violated unicity constraint',
+                              '': u'some relations violate a unicity constraint'},
                              cm.exception.errors)
             shell.rollback()
             # no pb if not in the same workflow
@@ -67,9 +67,9 @@
             with self.assertRaises(ValidationError) as cm:
                 bar.cw_set(name=u'foo')
             shell.rollback()
-            self.assertEqual({'name': u'name is part of violated unicity constraint',
-                              'state_of': u'state_of is part of violated unicity constraint',
-                              'unicity constraint': u'some relations violate a unicity constraint'},
+            self.assertEqual({'name': u'%(KEY-rtype)s is part of violated unicity constraint',
+                              'state_of': u'%(KEY-rtype)s is part of violated unicity constraint',
+                              '': u'some relations violate a unicity constraint'},
                              cm.exception.errors)
 
     def test_duplicated_transition(self):
@@ -80,9 +80,9 @@
             wf.add_transition(u'baz', (foo,), bar, ('managers',))
             with self.assertRaises(ValidationError) as cm:
                 wf.add_transition(u'baz', (bar,), foo)
-            self.assertEqual({'name': u'name is part of violated unicity constraint',
-                              'transition_of': u'transition_of is part of violated unicity constraint',
-                              'unicity constraint': u'some relations violate a unicity constraint'},
+            self.assertEqual({'name': u'%(KEY-rtype)s is part of violated unicity constraint',
+                              'transition_of': u'%(KEY-rtype)s is part of violated unicity constraint',
+                              '': u'some relations violate a unicity constraint'},
                              cm.exception.errors)
             shell.rollback()
             # no pb if not in the same workflow
@@ -97,9 +97,9 @@
             with self.assertRaises(ValidationError) as cm:
                 biz.cw_set(name=u'baz')
             shell.rollback()
-            self.assertEqual({'name': u'name is part of violated unicity constraint',
-                              'transition_of': u'transition_of is part of violated unicity constraint',
-                              'unicity constraint': u'some relations violate a unicity constraint'},
+            self.assertEqual({'name': u'%(KEY-rtype)s is part of violated unicity constraint',
+                              'transition_of': u'%(KEY-rtype)s is part of violated unicity constraint',
+                              '': u'some relations violate a unicity constraint'},
                              cm.exception.errors)
 
 
--- a/i18n/de.po	Wed Feb 04 15:13:36 2015 +0100
+++ b/i18n/de.po	Wed Mar 18 22:43:51 2015 +0100
@@ -54,6 +54,10 @@
 msgstr ""
 
 #, python-format
+msgid "%(KEY-rtype)s is part of violated unicity constraint"
+msgstr ""
+
+#, python-format
 msgid "%(KEY-value)r doesn't match the %(KEY-regexp)r regular expression"
 msgstr ""
 
@@ -114,10 +118,6 @@
 msgstr "%s Fehlerbericht"
 
 #, python-format
-msgid "%s is part of violated unicity constraint"
-msgstr ""
-
-#, python-format
 msgid "%s software version of the database"
 msgstr "Software-Version der Datenbank %s"
 
--- a/i18n/en.po	Wed Feb 04 15:13:36 2015 +0100
+++ b/i18n/en.po	Wed Mar 18 22:43:51 2015 +0100
@@ -46,6 +46,10 @@
 msgstr ""
 
 #, python-format
+msgid "%(KEY-rtype)s is part of violated unicity constraint"
+msgstr ""
+
+#, python-format
 msgid "%(KEY-value)r doesn't match the %(KEY-regexp)r regular expression"
 msgstr ""
 
@@ -106,10 +110,6 @@
 msgstr ""
 
 #, python-format
-msgid "%s is part of violated unicity constraint"
-msgstr ""
-
-#, python-format
 msgid "%s software version of the database"
 msgstr ""
 
--- a/i18n/es.po	Wed Feb 04 15:13:36 2015 +0100
+++ b/i18n/es.po	Wed Mar 18 22:43:51 2015 +0100
@@ -60,6 +60,10 @@
 msgstr "%(KEY-cstr)s restricción errónea para el valor %(KEY-value)r"
 
 #, python-format
+msgid "%(KEY-rtype)s is part of violated unicity constraint"
+msgstr "%(KEY-rtype)s pertenece a una restricción de unidad no respectada"
+
+#, python-format
 msgid "%(KEY-value)r doesn't match the %(KEY-regexp)r regular expression"
 msgstr "%(KEY-value)r no corresponde a la expresión regular %(KEY-regexp)r"
 
@@ -120,10 +124,6 @@
 msgstr "%s reporte de errores"
 
 #, python-format
-msgid "%s is part of violated unicity constraint"
-msgstr "%s pertenece a una restricción de unidad no respectada"
-
-#, python-format
 msgid "%s software version of the database"
 msgstr "versión sistema de la base para %s"
 
--- a/i18n/fr.po	Wed Feb 04 15:13:36 2015 +0100
+++ b/i18n/fr.po	Wed Mar 18 22:43:51 2015 +0100
@@ -54,6 +54,10 @@
 msgstr "la valeur %(KEY-value)r ne satisfait pas la contrainte %(KEY-cstr)s"
 
 #, python-format
+msgid "%(KEY-rtype)s is part of violated unicity constraint"
+msgstr "%(KEY-rtype)s appartient à une contrainte d'unicité transgressée"
+
+#, python-format
 msgid "%(KEY-value)r doesn't match the %(KEY-regexp)r regular expression"
 msgstr ""
 "%(KEY-value)r ne correspond pas à l'expression régulière %(KEY-regexp)r"
@@ -115,10 +119,6 @@
 msgstr "%s rapport d'erreur"
 
 #, python-format
-msgid "%s is part of violated unicity constraint"
-msgstr "%s appartient à une contrainte d'unicité transgressée"
-
-#, python-format
 msgid "%s software version of the database"
 msgstr "version logicielle de la base pour %s"
 
--- a/server/test/unittest_repository.py	Wed Feb 04 15:13:36 2015 +0100
+++ b/server/test/unittest_repository.py	Wed Mar 18 22:43:51 2015 +0100
@@ -52,10 +52,10 @@
             with self.assertRaises(ValidationError) as wraperr:
                 cnx.execute('INSERT Societe S: S nom "Logilab", S type "SSLL", S cp "75013"')
             self.assertEqual(
-                {'cp': u'cp is part of violated unicity constraint',
-                 'nom': u'nom is part of violated unicity constraint',
-                 'type': u'type is part of violated unicity constraint',
-                 'unicity constraint': u'some relations violate a unicity constraint'},
+                {'cp': u'%(KEY-rtype)s is part of violated unicity constraint',
+                 'nom': u'%(KEY-rtype)s is part of violated unicity constraint',
+                 'type': u'%(KEY-rtype)s is part of violated unicity constraint',
+                 '': u'some relations violate a unicity constraint'},
                 wraperr.exception.args[1])
 
     def test_unique_together_schema(self):