Commit 27602525 authored by Michal Čihař's avatar Michal Čihař

Configurable merging of upload

User can choose merging method - add translation, suggestion or fuzzy
translation.

Currently only translations and fuzzy translations are implemented.

Part of issue #214
parent 82ae4058
......@@ -169,6 +169,15 @@ class SimpleUploadForm(forms.Form):
Base form for uploading a file.
'''
file = forms.FileField(label=_('File'))
method = forms.ChoiceField(
label=_('Merge method'),
choices=(
('', _('Add as translation')),
('suggest', _('Add as a suggestion')),
('fuzzy', _('Add as fuzzy translation')),
),
required=False
)
merge_header = forms.BooleanField(
label=_('Merge file header'),
help_text=_('Merges content of file header into the translation.'),
......
......@@ -2191,7 +2191,7 @@ class Translation(models.Model):
return result
def merge_store(self, author, store2, overwrite, merge_header=True):
def merge_store(self, author, store2, overwrite, merge_header, add_fuzzy):
'''
Merges ttkit store into current translation.
'''
......@@ -2234,6 +2234,10 @@ class Translation(models.Model):
# Actually update translation
unit1.merge(unit2, overwrite=True, comments=False)
# Handle
if add_fuzzy:
unit1.markfuzzy()
# Write to backend and commit
self.commit_pending(author)
store1.save()
......@@ -2243,7 +2247,7 @@ class Translation(models.Model):
return ret
def merge_upload(self, request, fileobj, overwrite, author=None,
merge_header=True):
merge_header=True, method=''):
'''
Top level handler for file uploads.
'''
......@@ -2269,14 +2273,18 @@ class Translation(models.Model):
ret = False
# Do actual merge
for translation in translations:
ret |= translation.merge_store(
author,
store,
overwrite,
merge_header
)
if method in ('', 'fuzzy'):
# Do actual merge
for translation in translations:
ret |= translation.merge_store(
author,
store,
overwrite,
merge_header,
(method == 'fuzzy')
)
else:
# Add as sugestions
return ret
......
......@@ -705,7 +705,8 @@ def upload_translation(request, project, subproject, lang):
request.FILES['file'],
overwrite,
author,
merge_header=form.cleaned_data['merge_header']
merge_header=form.cleaned_data['merge_header'],
method=form.cleaned_data['method']
)
if ret:
messages.info(request, _('File content successfully merged into translation.'))
......
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