"'<output_dir>/<locale>/LC_MESSAGES/<domain>.po')"),
('locale=', 'l',
'locale for the new localized catalog'),
+ ('no-wrap', None,
+ 'do not break long message lines, longer than the output line width, '
+ 'into several lines'),
]
+ boolean_options = ['no-wrap']
def initialize_options(self):
self.output_dir = None
self.input_file = None
self.locale = None
self.domain = 'messages'
+ self.no_wrap = False
+ self.width = None
def finalize_options(self):
if not self.input_file:
if not os.path.exists(os.path.dirname(self.output_file)):
os.makedirs(os.path.dirname(self.output_file))
+ if not self.no_wrap:
+ self.width = 76
def run(self):
log.info('creating catalog %r based on %r', self.output_file,
outfile = open(self.output_file, 'w')
try:
- write_po(outfile, catalog)
+ write_po(outfile, catalog, width=self.width)
finally:
outfile.close()
"'<output_dir>/<locale>/LC_MESSAGES/<domain>.po')"),
('locale=', 'l',
'locale of the catalog to compile'),
+ ('no-wrap', None,
+ 'do not break long message lines, longer than the output line width, '
+ 'into several lines'),
('ignore-obsolete=', None,
'whether to omit obsolete messages from the output'),
('no-fuzzy-matching', 'N',
self.output_dir = None
self.output_file = None
self.locale = None
+ self.no_wrap = False
self.ignore_obsolete = False
self.no_fuzzy_matching = False
self.previous = False
if not po_files:
raise DistutilsOptionError('no message catalogs found')
+ extra_params = {}
+ if self.no_wrap:
+ extra_params['width'] = None
+
for locale, filename in po_files:
log.info('updating catalog %r based on %r', filename,
self.input_file)
try:
write_po(tmpfile, catalog,
ignore_obsolete=self.ignore_obsolete,
- include_previous=self.previous)
+ include_previous=self.previous, **extra_params)
finally:
tmpfile.close()
except:
"<domain>.po')")
parser.add_option('--locale', '-l', dest='locale', metavar='LOCALE',
help='locale for the new localized catalog')
+ 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(domain='messages')
options, args = parser.parse_args(argv)
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
infile = open(options.input_file, 'r')
try:
outfile = open(options.output_file, 'w')
try:
- write_po(outfile, catalog)
+ write_po(outfile, catalog, width=width)
finally:
outfile.close()
"<domain>.po')")
parser.add_option('--locale', '-l', dest='locale', metavar='LOCALE',
help='locale of the translations catalog')
+ 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.add_option('--ignore-obsolete', dest='ignore_obsolete',
action='store_true',
help='do not include obsolete messages in the output '
if not po_files:
parser.error('no message catalogs found')
+ extra_params = {}
+ if options.no_wrap:
+ extra_params['width'] = None
for locale, filename in po_files:
self.log.info('updating catalog %r based on %r', filename,
options.input_file)
try:
write_po(tmpfile, catalog,
ignore_obsolete=options.ignore_obsolete,
- include_previous=options.previous)
+ include_previous=options.previous, **extra_params)
finally:
tmpfile.close()
except:
'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ',
tzinfo=LOCALTZ, locale='ja_JP')},
open(po_file, 'U').read())
+
+ def test_supports_no_wrap(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.no_wrap = True
+
+ 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'),
+ 'long_message': long_message},
+ open(po_file, 'U').read())
class CommandLineInterfaceTestCase(unittest.TestCase):