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
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:
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')
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)
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 "
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=''):
#: 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()