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

Support for adding words to dictionary while translating

Fixes #675
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 808ad745
...@@ -26,6 +26,7 @@ Released on ? 2015. ...@@ -26,6 +26,7 @@ Released on ? 2015.
* Extended keyboard shortcuts. * Extended keyboard shortcuts.
* Improved dictionary matching for several languages. * Improved dictionary matching for several languages.
* Improved layout of most of pages. * Improved layout of most of pages.
* Support for adding words to dictionary while translating.
weblate 2.3 weblate 2.3
----------- -----------
......
...@@ -333,7 +333,9 @@ ...@@ -333,7 +333,9 @@
</h4> </h4>
</div> </div>
<div class="panel-body"> <div class="panel-body">
{% if glossary %} <form action="{% url 'show_dictionary' project=unit.translation.subproject.project.slug lang=unit.translation.language.code %}" method="POST">
{% csrf_token %}
<input type="hidden" name="next" value="{{ this_unit_url }}" />
<table class="table table-condensed table-striped"> <table class="table table-condensed table-striped">
<thead> <thead>
<tr> <tr>
...@@ -353,12 +355,24 @@ ...@@ -353,12 +355,24 @@
{% endif %} {% endif %}
</td> </td>
</tr> </tr>
{% empty %}
<tr>
<td colspan="3">
{% trans "No related strings were found in the glossary." %}
</td>
</tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
<tfoot>
<tr class="form-inline">
<td>{{ addword_form.source }}</td>
<td>{{ addword_form.target }}</td>
<td>
<input type="submit" class="btn btn-default btn-xs" title="{% trans "Add word to glossary" %}" value="{% trans "Add" %}" />
<td>
</tfoot>
</table> </table>
{% else %} </form>
<p>{% trans "No related strings were found in the glossary." %}</p>
{% endif %}
</div> </div>
</div> </div>
......
...@@ -605,6 +605,15 @@ class WordForm(forms.Form): ...@@ -605,6 +605,15 @@ class WordForm(forms.Form):
target = forms.CharField(label=_('Translation')) target = forms.CharField(label=_('Translation'))
class InlineWordForm(WordForm):
"""Inline rendered form for adding words."""
def __init__(self, *args, **kwargs):
super(InlineWordForm, self).__init__(*args, **kwargs)
for field in ('source', 'target'):
self.fields[field].widget.attrs['placeholder'] = self.fields[field].label
self.fields[field].widget.attrs['size'] = 10
class DictUploadForm(forms.Form): class DictUploadForm(forms.Form):
''' '''
Uploading file to a dictionary. Uploading file to a dictionary.
......
...@@ -295,7 +295,9 @@ def show_dictionary(request, project, lang): ...@@ -295,7 +295,9 @@ def show_dictionary(request, project, lang):
source=form.cleaned_data['source'], source=form.cleaned_data['source'],
target=form.cleaned_data['target'] target=form.cleaned_data['target']
) )
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(
request.POST.get('next', request.get_full_path())
)
else: else:
form = WordForm() form = WordForm()
......
...@@ -35,7 +35,7 @@ from weblate.trans.models import ( ...@@ -35,7 +35,7 @@ from weblate.trans.models import (
) )
from weblate.trans.autofixes import fix_target from weblate.trans.autofixes import fix_target
from weblate.trans.forms import ( from weblate.trans.forms import (
TranslationForm, SearchForm, TranslationForm, SearchForm, InlineWordForm,
MergeForm, AutoForm, ReviewForm, MergeForm, AutoForm, ReviewForm,
AntispamForm, CommentForm, RevertForm AntispamForm, CommentForm, RevertForm
) )
...@@ -594,6 +594,7 @@ def translate(request, project, subproject, lang): ...@@ -594,6 +594,7 @@ def translate(request, project, subproject, lang):
'user_locked': user_locked, 'user_locked': user_locked,
'project_locked': project_locked, 'project_locked': project_locked,
'glossary': Dictionary.objects.get_words(unit), 'glossary': Dictionary.objects.get_words(unit),
'addword_form': InlineWordForm(),
} }
) )
......
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