"'<output_dir>/<locale>/LC_MESSAGES/<domain>.po')"),
('locale=', 'l',
'locale of the catalog to compile'),
+ ('ignore-obsolete=', None,
+ 'whether to omit obsolete messages from the output')
]
+ boolean_options = ['ignore_obsolete']
def initialize_options(self):
self.domain = 'messages'
self.output_dir = None
self.output_file = None
self.locale = None
+ self.ignore_obsolete = False
def finalize_options(self):
if not self.input_file:
outfile = open(po_file, 'w')
try:
- write_po(outfile, catalog)
+ write_po(outfile, catalog, ignore_obsolete=self.ignore_obsolete)
finally:
outfile.close()
"<domain>.po')")
parser.add_option('--locale', '-l', dest='locale', metavar='LOCALE',
help='locale of the translations catalog')
+ parser.add_option('--ignore-obsolete', dest='ignore_obsolete',
+ action='store_true',
+ help='do not include obsolete messages in the output '
+ '(default %default)'),
- parser.set_defaults(domain='messages')
+ parser.set_defaults(domain='messages', ignore_obsolete=False)
options, args = parser.parse_args(argv)
if not options.input_file:
outfile = open(po_file, 'w')
try:
- write_po(outfile, catalog)
+ write_po(outfile, catalog,
+ ignore_obsolete=options.ignore_obsolete)
finally:
outfile.close()
return u'""\n' + u'\n'.join([(prefix + escape(l)) for l in lines])
def write_po(fileobj, catalog, width=76, no_location=False, omit_header=False,
- sort_output=False, sort_by_file=False):
+ sort_output=False, sort_by_file=False, ignore_obsolete=False):
r"""Write a ``gettext`` PO (portable object) template file for a given
message catalog to the provided file-like object.
: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
+ :sort_output: whether to sort the messages in the output by msgid
+ :sort_by_file: whether to sort the messages in the output by their locations
+ :ignore_obsolete: whether to ignore obsolete messages and not include them
+ in the output; by default they are included as comments
"""
def _normalize(key, prefix=''):
return normalize(key, prefix=prefix, width=width) \
_write_message(message)
_write('\n')
- for message in catalog.obsolete.values():
- for comment in message.user_comments:
- _write_comment(comment)
- _write_message(message, prefix='#~ ')
- _write('\n')
+ if not ignore_obsolete:
+ for message in catalog.obsolete.values():
+ for comment in message.user_comments:
+ _write_comment(comment)
+ _write_message(message, prefix='#~ ')
+ _write('\n')
#~ "multiple lines, and should still be handled\n"
#~ "correctly.\n"''', buf.getvalue().strip())
+ def test_po_with_obsolete_message_ignored(self):
+ catalog = Catalog()
+ catalog.add(u'foo', u'Voh', locations=[('main.py', 1)])
+ catalog.obsolete['bar'] = Message(u'bar', u'Bahr',
+ locations=[('utils.py', 3)],
+ user_comments=['User comment'])
+ buf = StringIO()
+ pofile.write_po(buf, catalog, omit_header=True, ignore_obsolete=True)
+ self.assertEqual('''#: main.py:1
+msgid "foo"
+msgstr "Voh"''', buf.getvalue().strip())
+
def suite():
suite = unittest.TestSuite()
'<output_dir>/<locale>/LC_MESSAGES/<domain>.po')
-l LOCALE, --locale=LOCALE
locale of the translations catalog
+ --ignore-obsolete do not include obsolete messages in the output
+ (default False)
If ``output_dir`` is specified, but ``output-file`` is not, the default
filename of the output file will be::
+-----------------------------+----------------------------------------------+
| ``--locale`` | locale for the new localized string |
+-----------------------------+----------------------------------------------+
+ | ``--ignore-obsolete`` | do not include obsolete messages in the |
+ | | output |
+ +-----------------------------+----------------------------------------------+
If ``output-dir`` is specified, but ``output-file`` is not, the default filename
of the output file will be::