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.
* Extended keyboard shortcuts.
* Improved dictionary matching for several languages.
* Improved layout of most of pages.
* Support for adding words to dictionary while translating.
weblate 2.3
-----------
......
......@@ -333,7 +333,9 @@
</h4>
</div>
<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">
<thead>
<tr>
......@@ -353,12 +355,24 @@
{% endif %}
</td>
</tr>
{% empty %}
<tr>
<td colspan="3">
{% trans "No related strings were found in the glossary." %}
</td>
</tr>
{% endfor %}
</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>
{% else %}
<p>{% trans "No related strings were found in the glossary." %}</p>
{% endif %}
</form>
</div>
</div>
......
......@@ -605,6 +605,15 @@ class WordForm(forms.Form):
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):
'''
Uploading file to a dictionary.
......
......@@ -295,7 +295,9 @@ def show_dictionary(request, project, lang):
source=form.cleaned_data['source'],
target=form.cleaned_data['target']
)
return HttpResponseRedirect(request.get_full_path())
return HttpResponseRedirect(
request.POST.get('next', request.get_full_path())
)
else:
form = WordForm()
......
......@@ -35,7 +35,7 @@ from weblate.trans.models import (
)
from weblate.trans.autofixes import fix_target
from weblate.trans.forms import (
TranslationForm, SearchForm,
TranslationForm, SearchForm, InlineWordForm,
MergeForm, AutoForm, ReviewForm,
AntispamForm, CommentForm, RevertForm
)
......@@ -594,6 +594,7 @@ def translate(request, project, subproject, lang):
'user_locked': user_locked,
'project_locked': project_locked,
'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