show translation strings in table

This commit is contained in:
Sanj B 2011-12-24 20:49:16 +05:30
parent f46fd27aa0
commit d7303ec37b
2 changed files with 15 additions and 6 deletions

View File

@ -18,7 +18,7 @@ def translate(request, model, field):
m = models.__getattribute__(model)
except AttributeError:
return HttpResponse("no such model")
response = ''
response = []
if field not in m._meta.get_all_field_names():
return HttpResponse("no such field")
qset = m.objects.values(field).distinct()
@ -39,9 +39,12 @@ def translate(request, model, field):
isEnglish = False
ordArr.append(str(ord(char)))
if not isEnglish:
response += "%s\n\n" % (val,)
response.append({
'ord': ordArr.join(","),
'val': val
})
context = RequestContext(request, {
'txt': response,
'values': response,
'model': model,
'field': field
})

View File

@ -12,9 +12,15 @@ function googleTranslateElementInit() {
}, 'google_translate_element');
}
</script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
{{ txt|linebreaksbr|safe }}
<br /><br /><br />
<table>
{% for v in values %}
<tr>
<td>{{ v.ord }}</td>
<td>{{ v.val }}</td>
</tr>
{% endfor %}
</table>
<br /><br />
<form action="/dotranslate/{{ model }}/{{ field }}/" method="POST">
{% csrf_token %}
<textarea name="txt" id="txt"></textarea> <br />