# HG changeset patch # User jruigrok # Date 1270975217 0 # Node ID 2c6f5e610e86438bbfd20a513ec52afbfb252cc6 # Parent 1dd3592c6159b291a019951cad12f07c6493d303 Merged revisions 465 via svnmerge from http://svn.edgewall.org/repos/babel/trunk ........ r465 | palgarvio | 2008-12-23 02:03:40 +0100 (di, 23 dec 2008) | 3 lines Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145. 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. ........ diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,8 @@ * Use a more explicit error message if no option or argument (command) is passed to pybabel (ticket #81). * Keep the PO-Revision-Date if it is not the default value (ticket #148). + * Make --no-wrap work by reworking --width's default and mimic xgettext's + behaviour of always wrapping comments (ticket #145). Version 0.9.5 diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -243,7 +243,7 @@ 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 @@ 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: @@ -804,7 +804,7 @@ 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') @@ -830,7 +830,7 @@ 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) @@ -865,8 +865,6 @@ 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 " diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py --- a/babel/messages/pofile.py +++ b/babel/messages/pofile.py @@ -378,10 +378,13 @@ 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=''): diff --git a/babel/messages/tests/pofile.py b/babel/messages/tests/pofile.py --- a/babel/messages/tests/pofile.py +++ b/babel/messages/tests/pofile.py @@ -269,6 +269,37 @@ #: 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()