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

View File

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