Mercurial > babel > mirror
diff babel/messages/frontend.py @ 569:1b801a0cb2cb trunk
Support for context-aware methods during message extraction (fixes #229, patch by David Rios)
author | fschwarz |
---|---|
date | Mon, 26 Sep 2011 20:01:01 +0000 |
parents | c6bc419cc32a |
children | 99c48a6ca1d6 |
line wrap: on
line diff
--- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -309,10 +309,10 @@ callback=callback, strip_comment_tags= self.strip_comments) - for filename, lineno, message, comments in extracted: + for filename, lineno, message, comments, context in extracted: filepath = os.path.normpath(os.path.join(dirname, filename)) catalog.add(message, None, [(filepath, lineno)], - auto_comments=comments) + auto_comments=comments, context=context) log.info('writing PO template file to %s' % self.output_file) write_po(outfile, catalog, width=self.width, @@ -907,10 +907,10 @@ callback=callback, strip_comment_tags= options.strip_comment_tags) - for filename, lineno, message, comments in extracted: + for filename, lineno, message, comments, context in extracted: filepath = os.path.normpath(os.path.join(dirname, filename)) catalog.add(message, None, [(filepath, lineno)], - auto_comments=comments) + auto_comments=comments, context=context) if options.output not in (None, '-'): self.log.info('writing PO template file to %s' % options.output) @@ -1181,13 +1181,14 @@ def parse_keywords(strings=[]): """Parse keywords specifications from the given list of strings. - >>> kw = parse_keywords(['_', 'dgettext:2', 'dngettext:2,3']).items() + >>> kw = parse_keywords(['_', 'dgettext:2', 'dngettext:2,3', 'pgettext:1c,2']).items() >>> kw.sort() >>> for keyword, indices in kw: ... print (keyword, indices) ('_', None) ('dgettext', (2,)) ('dngettext', (2, 3)) + ('pgettext', ((1, 'c'), 2)) """ keywords = {} for string in strings: @@ -1197,7 +1198,13 @@ funcname, indices = string, None if funcname not in keywords: if indices: - indices = tuple([(int(x)) for x in indices.split(',')]) + inds = [] + for x in indices.split(','): + if x[-1] == 'c': + inds.append((int(x[:-1]), 'c')) + else: + inds.append(int(x)) + indices = tuple(inds) keywords[funcname] = indices return keywords