"'<output_dir>/<locale>/LC_MESSAGES/<domain>.po')"),
('locale=', 'l',
'locale for the new localized catalog'),
+ ('width=', 'w',
+ 'set output line width (default 76)'),
('no-wrap', None,
'do not break long message lines, longer than the output line width, '
'into several lines'),
if not os.path.exists(os.path.dirname(self.output_file)):
os.makedirs(os.path.dirname(self.output_file))
- if not self.no_wrap:
+ if not self.no_wrap and not self.width:
self.width = 76
+ elif self.width is not None:
+ self.width = int(self.width)
def run(self):
log.info('creating catalog %r based on %r', self.output_file,
"<domain>.po')")
parser.add_option('--locale', '-l', dest='locale', metavar='LOCALE',
help='locale for the new localized catalog')
+ parser.add_option('-w', '--width', dest='width', type='int',
+ 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')
options.domain + '.po')
if not os.path.exists(os.path.dirname(options.output_file)):
os.makedirs(os.path.dirname(options.output_file))
- width = 76
- if options.no_wrap:
- width = None
+ if options.width and options.no_wrap:
+ parser.error("'--no-wrap' and '--width' are mutually exclusive.")
+ elif not options.width and not options.no_wrap:
+ options.width = 76
infile = open(options.input_file, 'r')
try:
outfile = open(options.output_file, 'w')
try:
- write_po(outfile, catalog, width=width)
+ write_po(outfile, catalog, width=options.width)
finally:
outfile.close()
msgstr[0] ""
msgstr[1] ""
+""" % {'version': VERSION,
+ 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
+ tzinfo=LOCALTZ, locale='en_US'),
+ 'long_message': long_message},
+ open(po_file, 'U').read())
+
+ def test_supports_width(self):
+ self.cmd.input_file = 'project/i18n/long_messages.pot'
+ self.cmd.locale = 'en_US'
+ self.cmd.output_dir = 'project/i18n'
+
+ long_message = '"'+ 'xxxxx '*15 + '"'
+
+ pot_contents = open('project/i18n/messages.pot', 'U').read()
+ pot_with_very_long_line = pot_contents.replace('"bar"', long_message)
+ open(self.cmd.input_file, 'wb').write(pot_with_very_long_line)
+ self.cmd.width = 120
+ self.cmd.finalize_options()
+ self.cmd.run()
+
+ po_file = self._po_file('en_US')
+ assert os.path.isfile(po_file)
+ self.assertEqual(
+r"""# English (United States) translations for TestProject.
+# Copyright (C) 2007 FooBar, Inc.
+# This file is distributed under the same license as the TestProject
+# project.
+# FIRST AUTHOR <EMAIL@ADDRESS>, 2007.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: TestProject 0.1\n"
+"Report-Msgid-Bugs-To: bugs.address@email.tld\n"
+"POT-Creation-Date: 2007-04-01 15:30+0200\n"
+"PO-Revision-Date: %(date)s\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: en_US <LL@li.org>\n"
+"Plural-Forms: nplurals=2; plural=(n != 1)\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: Babel %(version)s\n"
+
+#. This will be a translator coment,
+#. that will include several lines
+#: project/file1.py:8
+msgid %(long_message)s
+msgstr ""
+
+#: project/file2.py:9
+msgid "foobar"
+msgid_plural "foobars"
+msgstr[0] ""
+msgstr[1] ""
+
""" % {'version': VERSION,
'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
tzinfo=LOCALTZ, locale='en_US'),