This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
glasnost/talGettext.py

44 lines
976 B
Python
Executable File

#! /usr/bin/env python
# TODO: support attr-translate
import os
import sgmllib
import sys
directory = sys.argv[1]
translations = {}
class ParserForTranslations(sgmllib.SGMLParser):
def __init__(self, body):
sgmllib.SGMLParser.__init__(self)
self.translation = 0
self.feed(body)
def handle_data(self, data):
if not self.translation:
return
self.translation = 0
translations[data.strip()] = None
def unknown_starttag(self, tag, attrs):
attrs = [x for x in attrs if x[0] == 'tal:translate' and not x[1]]
if not attrs:
return
self.translation = 1
for root, dir, files in os.walk(directory):
for file in files:
if not file.endswith('.tal') and not file.endswith('.html'):
continue
file = os.path.join(root, file)
ParserForTranslations(open(file).read())
for t in translations.keys():
print '_("""%s""")' % t