Commit 13346e44 authored by Michal Čihař's avatar Michal Čihař

Wrap ttkit to prevent problems with interpreter (issue #37)

parent db2e6d13
...@@ -27,6 +27,20 @@ from util import is_plural, split_plural, join_plural ...@@ -27,6 +27,20 @@ from util import is_plural, split_plural, join_plural
logger = logging.getLogger('weblate') logger = logging.getLogger('weblate')
def ttkit(path):
'''
Returns translate-toolkit storage for a path.
'''
# Workaround for _ created by interactive interpreter and
# later used instead of gettext by ttkit
if not callable(__builtin__.__dict__['_']):
del __builtin__.__dict__['_']
return factory.getobject(path)
def validate_repoweb(val): def validate_repoweb(val):
try: try:
val % {'file': 'file.po', 'line': '9', 'branch': 'master'} val % {'file': 'file.po', 'line': '9', 'branch': 'master'}
...@@ -450,7 +464,7 @@ class SubProject(models.Model): ...@@ -450,7 +464,7 @@ class SubProject(models.Model):
errors = [] errors = []
for match in matches: for match in matches:
try: try:
factory.getobject(os.path.join(self.get_path(), match)) ttkit(os.path.join(self.get_path(), match))
except ValueError: except ValueError:
notrecognized.append(match) notrecognized.append(match)
except Exception, e: except Exception, e:
...@@ -464,7 +478,7 @@ class SubProject(models.Model): ...@@ -464,7 +478,7 @@ class SubProject(models.Model):
if self.template != '': if self.template != '':
template = os.path.join(self.get_path(), self.template) template = os.path.join(self.get_path(), self.template)
try: try:
factory.getobject(os.path.join(self.get_path(), match)) ttkit(os.path.join(self.get_path(), match))
except ValueError: except ValueError:
raise ValidationError(_('Format of translation template could not be recognized.')) raise ValidationError(_('Format of translation template could not be recognized.'))
except Exception, e: except Exception, e:
...@@ -615,7 +629,7 @@ class Translation(models.Model): ...@@ -615,7 +629,7 @@ class Translation(models.Model):
return os.path.join(self.subproject.get_path(), self.filename) return os.path.join(self.subproject.get_path(), self.filename)
def get_store(self): def get_store(self):
store = factory.getobject(self.get_filename()) store = ttkit(self.get_filename())
if hasattr(store, 'set_base_resource') and self.subproject.template != '': if hasattr(store, 'set_base_resource') and self.subproject.template != '':
template = os.path.join(self.subproject.get_path(), self.subproject.template) template = os.path.join(self.subproject.get_path(), self.subproject.template)
store.set_base_resource(template) store.set_base_resource(template)
...@@ -898,7 +912,7 @@ class Translation(models.Model): ...@@ -898,7 +912,7 @@ class Translation(models.Model):
''' '''
# Needed to behave like something what translate toolkit expects # Needed to behave like something what translate toolkit expects
fileobj.mode = "r" fileobj.mode = "r"
store2 = factory.getobject(fileobj) store2 = ttkit(fileobj)
if author is None: if author is None:
author = self.get_author_name(request.user) author = self.get_author_name(request.user)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment