Rev 6133: (jr) Turn on translations for errors. (Jonathan Riddell) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Sep 7 13:52:10 UTC 2011


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6133 [merge]
revision-id: pqm at pqm.ubuntu.com-20110907135207-wjqgpk0qbwtvnbd4
parent: pqm at pqm.ubuntu.com-20110906133507-jxpb08khpc90jvvo
parent: jriddell at canonical.com-20110907114616-korjsxz31zdhyuqi
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2011-09-07 13:52:07 +0000
message:
  (jr) Turn on translations for errors. (Jonathan Riddell)
modified:
  bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
  bzrlib/pack.py                 container.py-20070607160755-tr8zc26q18rn0jnb-1
  bzrlib/tests/test_i18n.py      test_i18n.py-20110517012016-wjj0ai7qrasnj49p-1
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2011-09-05 10:28:30 +0000
+++ b/bzrlib/errors.py	2011-09-07 10:17:23 +0000
@@ -20,7 +20,10 @@
 from bzrlib import (
     osutils,
     symbol_versioning,
+    i18n,
+    trace,
     )
+from bzrlib.i18n import gettext
 from bzrlib.patches import (
     MalformedHunkHeader,
     MalformedLine,
@@ -140,7 +143,11 @@
         """Return format string for this exception or None"""
         fmt = getattr(self, '_fmt', None)
         if fmt is not None:
-            return fmt
+            i18n.install()
+            unicode_fmt = unicode(fmt) #_fmt strings should be ascii
+            if type(fmt) == unicode:
+                trace.mutter("Unicode strings in error.fmt are deprecated")
+            return gettext(unicode_fmt)
         fmt = getattr(self, '__doc__', None)
         if fmt is not None:
             symbol_versioning.warn("%s uses its docstring as a format, "
@@ -2792,7 +2799,7 @@
     _fmt = "Container has multiple records with the same name: %(name)s"
 
     def __init__(self, name):
-        self.name = name
+        self.name = name.decode("utf-8")
 
 
 class NoDestinationAddress(InternalBzrError):

=== modified file 'bzrlib/pack.py'
--- a/bzrlib/pack.py	2011-04-08 14:45:25 +0000
+++ b/bzrlib/pack.py	2011-09-07 11:46:16 +0000
@@ -333,7 +333,7 @@
                 # risk that the same unicode string has been encoded two
                 # different ways.
                 if name_tuple in all_names:
-                    raise errors.DuplicateRecordNameError(name_tuple)
+                    raise errors.DuplicateRecordNameError(name_tuple[0])
                 all_names.add(name_tuple)
         excess_bytes = self.reader_func(1)
         if excess_bytes != '':

=== modified file 'bzrlib/tests/test_i18n.py'
--- a/bzrlib/tests/test_i18n.py	2011-08-25 10:33:14 +0000
+++ b/bzrlib/tests/test_i18n.py	2011-09-07 10:50:09 +0000
@@ -16,7 +16,11 @@
 
 """Tests for bzrlib.i18n"""
 
-from bzrlib import i18n, tests
+from bzrlib import (i18n, 
+                    tests, 
+                    errors, 
+                    workingtree,
+                    )
 
 
 class ZzzTranslations(object):
@@ -28,7 +32,7 @@
     _null_translation = i18n._gettext.NullTranslations()
 
     def zzz(self, s):
-        return u'zz{{%s}}' % s
+        return u'zz\xe5{{%s}}' % s
 
     def ugettext(self, s):
         return self.zzz(self._null_translation.ugettext(s))
@@ -47,18 +51,18 @@
         trans = ZzzTranslations()
 
         t = trans.zzz('msg')
-        self._check_exact(u'zz{{msg}}', t)
+        self._check_exact(u'zz\xe5{{msg}}', t)
 
         t = trans.ugettext('msg')
-        self._check_exact(u'zz{{msg}}', t)
+        self._check_exact(u'zz\xe5{{msg}}', t)
 
         t = trans.ungettext('msg1', 'msg2', 0)
-        self._check_exact(u'zz{{msg2}}', t)
+        self._check_exact(u'zz\xe5{{msg2}}', t)
         t = trans.ungettext('msg1', 'msg2', 2)
-        self._check_exact(u'zz{{msg2}}', t)
+        self._check_exact(u'zz\xe5{{msg2}}', t)
 
         t = trans.ungettext('msg1', 'msg2', 1)
-        self._check_exact(u'zz{{msg1}}', t)
+        self._check_exact(u'zz\xe5{{msg1}}', t)
 
 
 class TestGetText(tests.TestCase):
@@ -68,11 +72,11 @@
         self.overrideAttr(i18n, '_translations', ZzzTranslations())
 
     def test_oneline(self):
-        self.assertEqual(u"zz{{spam ham eggs}}",
+        self.assertEqual(u"zz\xe5{{spam ham eggs}}",
                          i18n.gettext("spam ham eggs"))
 
     def test_multiline(self):
-        self.assertEqual(u"zz{{spam\nham\n\neggs\n}}",
+        self.assertEqual(u"zz\xe5{{spam\nham\n\neggs\n}}",
                          i18n.gettext("spam\nham\n\neggs\n"))
 
 
@@ -83,11 +87,11 @@
         self.overrideAttr(i18n, '_translations', ZzzTranslations())
 
     def test_oneline(self):
-        self.assertEqual(u"zz{{spam ham eggs}}",
+        self.assertEqual(u"zz\xe5{{spam ham eggs}}",
                          i18n.gettext_per_paragraph("spam ham eggs"))
 
     def test_multiline(self):
-        self.assertEqual(u"zz{{spam\nham}}\n\nzz{{eggs\n}}",
+        self.assertEqual(u"zz\xe5{{spam\nham}}\n\nzz\xe5{{eggs\n}}",
                          i18n.gettext_per_paragraph("spam\nham\n\neggs\n"))
 
 
@@ -104,3 +108,20 @@
         self.overrideEnv('LC_MESSAGES', None)
         self.overrideEnv('LANG', None)
         i18n.install()
+
+class TestTranslate(tests.TestCaseWithTransport):
+
+    def setUp(self):
+        super(TestTranslate, self).setUp()
+        self.overrideAttr(i18n, '_translations', ZzzTranslations())
+
+    def test_error_message_translation(self):
+        """do errors get translated?"""
+        err = None
+        tree = self.make_branch_and_tree('.')
+        self.overrideAttr(i18n, '_translations', ZzzTranslations())
+        try:
+            workingtree.WorkingTree.open('./foo')
+        except errors.NotBranchError,e:
+            err = str(e)
+        self.assertContainsRe(err, u"zz\xe5{{Not a branch: .*}}".encode("utf-8"))

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-09-06 13:35:07 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-09-07 09:57:43 +0000
@@ -92,6 +92,9 @@
 * bzr now ships with translations for command help.  (Jonathan
   Riddell, INADA Naoki, #83941)
 
+* bzr now ships with translations for command errors. (Jonathan
+  Riddell, INADA Naoki)
+
 Improvements
 ************
 




More information about the bazaar-commits mailing list