Form for non-plural strings
This commit is contained in:
parent
8839491535
commit
04666ac331
|
@ -17,7 +17,12 @@
|
||||||
<tr><th>{% trans "Source" %}</th><th>{% trans "Translation" %}<th></tr>
|
<tr><th>{% trans "Source" %}</th><th>{% trans "Translation" %}<th></tr>
|
||||||
{% if unit.is_plural %}
|
{% if unit.is_plural %}
|
||||||
{% else %}
|
{% 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 %}
|
{% endif %}
|
||||||
<tr><th>{% trans "Location" %}</th></tr>
|
<tr><th>{% trans "Location" %}</th></tr>
|
||||||
<tr><td>{{ unit.get_location_links }}</td></tr>
|
<tr><td>{{ unit.get_location_links }}</td></tr>
|
||||||
|
|
8
trans/forms.py
Normal file
8
trans/forms.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
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)
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
from django.shortcuts import render_to_response, get_object_or_404
|
from django.shortcuts import render_to_response, get_object_or_404
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.http import HttpResponseRedirect
|
||||||
|
|
||||||
from trans.models import Project, SubProject, Translation, Unit
|
from trans.models import Project, SubProject, Translation, Unit
|
||||||
|
from trans.forms import TranslationForm
|
||||||
|
|
||||||
def home(request):
|
def home(request):
|
||||||
projects = Project.objects.all()
|
projects = Project.objects.all()
|
||||||
|
@ -39,13 +41,32 @@ def show_translation(request, project, subproject, lang):
|
||||||
def translate(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)
|
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')
|
rqtype = request.REQUEST.get('type', 'all')
|
||||||
pos = request.REQUEST.get('oldpos', '-1')
|
pos = request.REQUEST.get('oldpos', '-1')
|
||||||
try:
|
try:
|
||||||
pos = int(pos)
|
pos = int(pos)
|
||||||
except:
|
except:
|
||||||
pos = -1
|
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&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()
|
total = obj.unit_set.all().count()
|
||||||
|
|
||||||
return render_to_response('translate.html', RequestContext(request, {
|
return render_to_response('translate.html', RequestContext(request, {
|
||||||
|
@ -54,4 +75,5 @@ def translate(request, project, subproject, lang):
|
||||||
'unit': unit,
|
'unit': unit,
|
||||||
'total': total,
|
'total': total,
|
||||||
'type': rqtype,
|
'type': rqtype,
|
||||||
|
'form': form,
|
||||||
}))
|
}))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user