translation framework
This commit is contained in:
parent
533ffc79df
commit
4c56e363b7
|
@ -116,6 +116,7 @@ INSTALLED_APPS = (
|
|||
'django.contrib.admin',
|
||||
# Uncomment the next line to enable admin documentation:
|
||||
'django.contrib.admindocs',
|
||||
'django_extensions'
|
||||
)
|
||||
|
||||
try:
|
||||
|
|
|
@ -21,17 +21,20 @@ class Ship(models.Model):
|
|||
number = models.IntegerField(max_length=20)
|
||||
date = models.DateField()
|
||||
ship_name = models.CharField(max_length=255)
|
||||
ship_name_trans = models.CharField(max_length=255, blank=True)
|
||||
captain = models.CharField(max_length=255)
|
||||
captain_trans = models.CharField(max_length=255, blank=True)
|
||||
flag = models.CharField(max_length=255)
|
||||
owner = models.CharField(max_length=255)
|
||||
owner_trans = models.CharField(max_length=255, blank=True)
|
||||
port = models.CharField(max_length=255)
|
||||
country = models.CharField(max_length=255)
|
||||
|
||||
def __unicode__(self):
|
||||
return "%d: %s" % (self.number, self.ship_name,)
|
||||
|
||||
class Meta:
|
||||
ordering = ['number']
|
||||
# class Meta:
|
||||
# ordering = ['number']
|
||||
|
||||
def no_of_goods(self):
|
||||
return Good.objects.filter(ship=self).count()
|
||||
|
|
|
@ -1 +1,35 @@
|
|||
# Create your views here.
|
||||
from models import *
|
||||
from django.http import HttpResponse
|
||||
from ships import models
|
||||
import json
|
||||
from django.shortcuts import render_to_response
|
||||
|
||||
def translate(request, model, field):
|
||||
start = request.GET.get("start", False)
|
||||
end = request.GET.get("end", False)
|
||||
if not start and not end:
|
||||
limit = False
|
||||
else:
|
||||
limit = True
|
||||
try:
|
||||
m = models.__getattribute__(model)
|
||||
except AttributeError:
|
||||
return HttpResponse("no such model")
|
||||
response = ''
|
||||
if field not in m._meta.get_all_field_names():
|
||||
return HttpResponse("no such field")
|
||||
qset = m.objects.values(field).distinct()
|
||||
if limit:
|
||||
if not start:
|
||||
start = 0
|
||||
if not end:
|
||||
end = qset.count()
|
||||
qset = qset[start:end]
|
||||
for obj in qset:
|
||||
val = obj[field]
|
||||
ordArr = []
|
||||
for char in val:
|
||||
ordArr.append(str(ord(char)))
|
||||
response += "%s|%s<br />" % (",".join(ordArr), val,)
|
||||
return render_to_response("translate.html", {'txt': response})
|
||||
|
|
18
manifests/templates/translate.html
Normal file
18
manifests/templates/translate.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="google_translate_element"></div><script>
|
||||
function googleTranslateElementInit() {
|
||||
new google.translate.TranslateElement({
|
||||
pageLanguage: 'ar',
|
||||
includedLanguages: 'en'
|
||||
}, 'google_translate_element');
|
||||
}
|
||||
</script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
|
||||
{{ txt|safe }}
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -12,5 +12,6 @@ urlpatterns = patterns('',
|
|||
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
|
||||
|
||||
# Uncomment the next line to enable the admin:
|
||||
(r'translate/(?P<model>[A-Za-z].*?)/(?P<field>[A-Za-z].*?)/', 'ships.views.translate'),
|
||||
(r'^admin/', include(admin.site.urls)),
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user