]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Now, the `--width` option, although with a default value of 76, it's not set to any...
authorPedro Algarvio <pedro@algarvio.me>
Tue, 23 Dec 2008 01:03:40 +0000 (01:03 +0000)
committerPedro Algarvio <pedro@algarvio.me>
Tue, 23 Dec 2008 01:03:40 +0000 (01:03 +0000)
With the above bug, another one was found where Babel was not mimic'ing xgtettext's behaviour regarding the `--no-wrap` option where comments are wrapped anyway to the width of 76, and, if `--width` is passed then that value is used to wrap the comments too.

babel/messages/frontend.py
babel/messages/pofile.py
babel/messages/tests/pofile.py

index 9ece5a766b15b2152f0f40cf7a78d2d180d5e3f9..19926510456d7f6fb67645d8f1452cb97867330e 100755 (executable)
@@ -243,7 +243,7 @@ class extract_messages(Command):
         self.omit_header = False
         self.output_file = None
         self.input_dirs = None
-        self.width = 76
+        self.width = None
         self.no_wrap = False
         self.sort_output = False
         self.sort_by_file = False
@@ -267,9 +267,9 @@ class extract_messages(Command):
         if self.no_wrap and self.width:
             raise DistutilsOptionError("'--no-wrap' and '--width' are mutually "
                                        "exclusive")
-        if self.no_wrap:
-            self.width = None
-        else:
+        if not self.no_wrap and not self.width:
+            self.width = 76
+        elif self.width is not None:
             self.width = int(self.width)
 
         if self.sort_output and self.sort_by_file:
@@ -803,7 +803,7 @@ class CommandLineInterface(object):
         parser.add_option('-o', '--output', dest='output',
                           help='path to the output POT file')
         parser.add_option('-w', '--width', dest='width', type='int',
-                          help="set output line width (default %default)")
+                          help="set output line width (default 76)")
         parser.add_option('--no-wrap', dest='no_wrap', action = 'store_true',
                           help='do not break long message lines, longer than '
                                'the output line width, into several lines')
@@ -829,7 +829,7 @@ class CommandLineInterface(object):
 
         parser.set_defaults(charset='utf-8', keywords=[],
                             no_default_keywords=False, no_location=False,
-                            omit_header = False, width=76, no_wrap=False,
+                            omit_header = False, width=None, no_wrap=False,
                             sort_output=False, sort_by_file=False,
                             comment_tags=[], strip_comment_tags=False)
         options, args = parser.parse_args(argv)
@@ -864,8 +864,6 @@ class CommandLineInterface(object):
             parser.error("'--no-wrap' and '--width' are mutually exclusive.")
         elif not options.width and not options.no_wrap:
             options.width = 76
-        elif not options.width and options.no_wrap:
-            options.width = 0
 
         if options.sort_output and options.sort_by_file:
             parser.error("'--sort-output' and '--sort-by-file' are mutually "
index 83cc3080aa8f857dbc3e1721d01a41682ea8b150..dd24735c48c9e491328b7607c7bdd05261e10add 100644 (file)
@@ -388,10 +388,13 @@ def write_po(fileobj, catalog, width=76, no_location=False, omit_header=False,
         fileobj.write(text)
 
     def _write_comment(comment, prefix=''):
-        lines = comment
+        # xgettext always wraps comments even if --no-wrap is passed;
+        # provide the same behaviour
         if width and width > 0:
-            lines = wraptext(comment, width)
-        for line in lines:
+            _width = width
+        else:
+            _width = 76
+        for line in wraptext(comment, _width):
             _write('#%s %s\n' % (prefix, line.strip()))
 
     def _write_message(message, prefix=''):
index 8e85af975314dbdbaa80c73feab5bb69392bda14..c4525fc6c2019b8c59abe0e63622ad79f000103c 100644 (file)
@@ -284,6 +284,37 @@ msgstr ""''', buf.getvalue().strip())
 #: doupy/templates/job-offers/helpers.html:22
 msgid "foo"
 msgstr ""''', buf.getvalue().strip())
+        
+    def test_no_wrap_and_width_behaviour_on_comments(self):
+        catalog = Catalog()
+        catalog.add("Pretty dam long message id, which must really be big "
+                    "to test this wrap behaviour, if not it won't work.",
+                    locations=[("fake.py", n) for n in range(1, 30)])
+        buf = StringIO()
+        pofile.write_po(buf, catalog, width=None, omit_header=True)
+        self.assertEqual("""\
+#: fake.py:1 fake.py:2 fake.py:3 fake.py:4 fake.py:5 fake.py:6 fake.py:7
+#: fake.py:8 fake.py:9 fake.py:10 fake.py:11 fake.py:12 fake.py:13 fake.py:14
+#: fake.py:15 fake.py:16 fake.py:17 fake.py:18 fake.py:19 fake.py:20 fake.py:21
+#: fake.py:22 fake.py:23 fake.py:24 fake.py:25 fake.py:26 fake.py:27 fake.py:28
+#: fake.py:29
+msgid "pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't work."
+msgstr ""
+
+""", buf.getvalue().lower())
+        buf = StringIO()
+        pofile.write_po(buf, catalog, width=100, omit_header=True)
+        self.assertEqual("""\
+#: fake.py:1 fake.py:2 fake.py:3 fake.py:4 fake.py:5 fake.py:6 fake.py:7 fake.py:8 fake.py:9 fake.py:10
+#: fake.py:11 fake.py:12 fake.py:13 fake.py:14 fake.py:15 fake.py:16 fake.py:17 fake.py:18 fake.py:19
+#: fake.py:20 fake.py:21 fake.py:22 fake.py:23 fake.py:24 fake.py:25 fake.py:26 fake.py:27 fake.py:28
+#: fake.py:29
+msgid ""
+"pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't"
+" work."
+msgstr ""
+
+""", buf.getvalue().lower())
 
     def test_pot_with_translator_comments(self):
         catalog = Catalog()