Commit 04666ac3 authored by Michal Čihař's avatar Michal Čihař

Form for non-plural strings

parent 88394915
......@@ -17,7 +17,12 @@
<tr><th>{% trans "Source" %}</th><th>{% trans "Translation" %}<th></tr>
{% if unit.is_plural %}
{% else %}
<tr><td>{{ unit.source }}</td><td colspan="2">{{ form.target }}</td></tr>
<tr><td>{{ unit.source }}</td><td colspan="2">
{{ form.checksum }}
{{ form.target }}
<br />
{{ form.fuzzy }}<label for="id_fuzzy">{% trans "Fuzzy" %}</label>
</td></tr>
{% endif %}
<tr><th>{% trans "Location" %}</th></tr>
<tr><td>{{ unit.get_location_links }}</td></tr>
......
from django import forms
from django.utils.translation import ugettext_lazy, ugettext as _
class TranslationForm(forms.Form):
checksum = forms.CharField(widget = forms.HiddenInput)
target = forms.CharField(widget = forms.Textarea, required = False)
fuzzy = forms.BooleanField(label = ugettext_lazy('Fuzzy'), required = False)
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.conf import settings
from django.http import HttpResponseRedirect
from trans.models import Project, SubProject, Translation, Unit
from trans.forms import TranslationForm
def home(request):
projects = Project.objects.all()
......@@ -39,13 +41,32 @@ def show_translation(request, project, subproject, lang):
def translate(request, project, subproject, lang):
obj = get_object_or_404(Translation, language__code = lang, subproject__slug = subproject, subproject__project__slug = project)
# Check where we are
rqtype = request.REQUEST.get('type', 'all')
pos = request.REQUEST.get('oldpos', '-1')
try:
pos = int(pos)
except:
pos = -1
unit = obj.unit_set.filter_type(rqtype).filter(position__gt = pos)[0]
# Any form submitted?
if request.method == 'POST':
form = TranslationForm(request.POST)
if form.is_valid():
# Check and save
return HttpResponseRedirect('%s?type=%s&amp;oldpos=%d' % (obj.get_translate_url(), rqtype, pos))
else:
# What unit to show
unit = obj.unit_set.filter_type(rqtype).filter(position__gt = pos)[0]
# Prepare form
form = TranslationForm(initial = {
'checksum': unit.checksum,
'target': unit.target,
'fuzzy': unit.fuzzy,
})
total = obj.unit_set.all().count()
return render_to_response('translate.html', RequestContext(request, {
......@@ -54,4 +75,5 @@ def translate(request, project, subproject, lang):
'unit': unit,
'total': total,
'type': rqtype,
'form': form,
}))
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