mappings = self._get_mappings()
outfile = open(self.output_file, 'w')
try:
- catalog = Catalog(msgid_bugs_address=self.msgid_bugs_address)
+ catalog = Catalog(project=self.distribution.get_name(),
+ version=self.distribution.get_version(),
+ msgid_bugs_address=self.msgid_bugs_address,
+ charset=self.charset)
+
for dirname, (method_map, options_map) in mappings.items():
def callback(filename, method, options):
if method == 'ignore':
comments=comments)
log.info('writing PO template file to %s' % self.output_file)
- write_pot(outfile, catalog, project=self.distribution.get_name(),
- version=self.distribution.get_version(), width=self.width,
- charset=self.charset, no_location=self.no_location,
- omit_header=self.omit_header, sort_output=self.sort_output,
- sort_by_file=self.sort_by_file,
- copyright_holder=self.copyright_holder)
+ write_pot(outfile, catalog, width=self.width,
+ no_location=self.no_location,
+ omit_header=self.omit_header,
+ sort_output=self.sort_output,
+ sort_by_file=self.sort_by_file,
+ copyright_holder=self.copyright_holder)
finally:
outfile.close()
"exclusive")
try:
- catalog = Catalog(msgid_bugs_address=options.msgid_bugs_address)
+ catalog = Catalog(msgid_bugs_address=options.msgid_bugs_address,
+ charset=options.charset)
+
for dirname in args:
if not os.path.isdir(dirname):
parser.error('%r is not a directory' % dirname)
comments=comments)
write_pot(outfile, catalog, width=options.width,
- charset=options.charset, no_location=options.no_location,
+ no_location=options.no_location,
omit_header=options.omit_header,
sort_output=options.sort_output,
sort_by_file=options.sort_by_file,
lines[-1] += '\n'
return u'""\n' + u'\n'.join([escape(l) for l in lines])
-def write_pot(fileobj, catalog, project='PROJECT', version='VERSION', width=76,
- charset='utf-8', no_location=False, omit_header=False,
+def write_pot(fileobj, catalog, width=76, no_location=False, omit_header=False,
sort_output=False, sort_by_file=False, copyright_holder=None):
r"""Write a ``gettext`` PO (portable object) template file for a given
message catalog to the provided file-like object.
:param fileobj: the file-like object to write to
:param catalog: the `Catalog` instance
- :param project: the project name
- :param version: the project version
:param width: the maximum line width for the generated output; use `None`,
0, or a negative number to completely disable line wrapping
- :param charset: the encoding
:param no_location: do not emit a location comment for every message
:param omit_header: do not include the ``msgid ""`` entry at the top of the
output
:param copyright_holder: sets the copyright holder in the output
"""
def _normalize(key):
- return normalize(key, width=width).encode(charset, 'backslashreplace')
+ return normalize(key, width=width).encode(catalog.charset,
+ 'backslashreplace')
def _write(text):
if isinstance(text, unicode):
- text = text.encode(charset)
+ text = text.encode(catalog.charset)
fileobj.write(text)
- catalog.project = project
- catalog.version = version
- catalog.charset = charset
-
if sort_output:
messages = list(catalog)
messages.sort(lambda x,y: cmp(x.id, y.id))
messages.sort(lambda x,y: cmp(x.locations, y.locations))
else:
messages = catalog
-
+
_copyright_holder = copyright_holder or 'ORGANIZATION'
for message in messages:
continue
_write(POT_HEADER % {
'year': date.today().strftime('%Y'),
- 'project': project,
+ 'project': catalog.project,
'copyright_holder': _copyright_holder,
})
-
+
if message.comments:
for comment in message.comments:
for line in textwrap.wrap(comment,