Initial untested merging of translations

This commit is contained in:
Michal Čihař 2012-03-04 10:18:13 +01:00
parent 5696ace382
commit cd5d63f74f
2 changed files with 32 additions and 2 deletions

View File

@ -354,6 +354,33 @@ class Translation(models.Model):
result.append(('suggestions', _('Strings with suggestions (%d)') % suggestions)) result.append(('suggestions', _('Strings with suggestions (%d)') % suggestions))
return result return result
def merge_upload(self, request, fileobj, overwrite, mergefuzzy = False):
store2 = factory.getobjects(fileobj)
store1 = self.get_store()
store.require_index()
for unit2 in store2.units:
if unit2.isheader():
if isinstance(store1, poheader):
store1.mergeheaders(store2)
continue
unit1 = store1.findid(unit2.getid())
if unit1 is None:
unit1 = store1.findunit(unit2.source)
if unit1 is None:
logger.error("The template does not contain the following unit:\n%s", str(unit2))
else:
if len(unit2.target.strip()) == 0:
continue
if not mergefuzzy:
if unit2.isfuzzy():
continue
unit1.merge(unit2, overwrite=overwrite)
store1.save()
author = '%s <%s>' % (request.user.get_full_name(), request.user.email)
self.git_commit(author)
class Unit(models.Model): class Unit(models.Model):
translation = models.ForeignKey(Translation) translation = models.ForeignKey(Translation)

View File

@ -180,7 +180,10 @@ def upload_translation(request, project, subproject, lang):
if request.method == 'POST': if request.method == 'POST':
form = UploadForm(request.POST, request.FILES) form = UploadForm(request.POST, request.FILES)
if form.is_valid(): if form.is_valid():
# FIXME: process upload try:
obj.merge_upload(request, request.FILES['file'], form.cleaned_data['overwrite'])
messages.add_message(request, messages.INFO, _('File content successfully merged into translation.')) messages.add_message(request, messages.INFO, _('File content successfully merged into translation.'))
except Exception, e:
messages.add_message(request, messages.ERROR, _('File content merge failed: %s' % str(e)))
return HttpResponseRedirect(obj.get_absolute_url()) return HttpResponseRedirect(obj.get_absolute_url())