Count number of strings found.

This commit is contained in:
Michael Gorven 2009-11-27 13:06:39 +02:00
parent 30a3897d3d
commit bbd6c2ed78
1 changed files with 4 additions and 1 deletions

View File

@ -43,11 +43,11 @@ ts_message = u""" <message>
</message>
"""
strings = {}
count = 0
class StringExtractor(NodeVisitor):
def __init__(self, strings, filename):
self.strings = strings
self.filename = filename
self.classname = 'unknown'
@ -56,8 +56,10 @@ class StringExtractor(NodeVisitor):
self.generic_visit(node)
def visit_Call(self, node):
global count
if hasattr(node.func, 'attr') and node.func.attr == 'trUtf8' and isinstance(node.args[0], Str):
string = node.args[0].s
count += 1
key = '%s-%s' % (self.classname, string)
strings[key] = [self.classname, self.filename, node.lineno, string]
self.generic_visit(node)
@ -100,6 +102,7 @@ def main():
if file.endswith(u'.py'):
print u'Parsing "%s"' % file
parse_file(os.path.join(root, file))
print u'Found %s strings' % count
print u'Generating TS file...',
write_file(os.path.join(start_dir, u'i18n', u'openlp_en.ts'))
print u'done.'