2012-02-27 10:05:53 +01:00
|
|
|
from django.db import models
|
2012-02-27 11:39:00 +01:00
|
|
|
from django.conf import settings
|
2012-02-27 10:46:12 +01:00
|
|
|
from lang.models import Language
|
2012-02-27 11:39:00 +01:00
|
|
|
import os
|
|
|
|
import os.path
|
2012-02-27 10:13:42 +01:00
|
|
|
|
2012-02-27 11:08:16 +01:00
|
|
|
PLURAL_SEPARATOR = '\x00\x00'
|
|
|
|
|
2012-02-27 10:13:42 +01:00
|
|
|
class Project(models.Model):
|
|
|
|
name = models.CharField(max_length = 100)
|
|
|
|
slug = models.SlugField(db_index = True)
|
|
|
|
web = models.URLField()
|
|
|
|
mail = models.EmailField()
|
|
|
|
instructions = models.URLField()
|
2012-02-27 10:39:01 +01:00
|
|
|
|
2012-02-27 11:11:37 +01:00
|
|
|
@models.permalink
|
|
|
|
def get_absolute_url(self):
|
2012-02-27 11:39:00 +01:00
|
|
|
return ('trans.views.show_project', (), {'project': self.slug})
|
|
|
|
|
|
|
|
def get_path(self):
|
|
|
|
return os.path.join(settings.GIT_ROOT, self.slug)
|
|
|
|
|
2012-02-27 11:45:27 +01:00
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
2012-02-27 11:39:00 +01:00
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
# Create filesystem directory for storing data
|
|
|
|
p = self.get_path()
|
|
|
|
if not os.path.exists(p):
|
|
|
|
os.makedirs(p)
|
|
|
|
super(Project, self).save(*args, **kwargs)
|
2012-02-27 11:11:37 +01:00
|
|
|
|
2012-02-27 10:39:01 +01:00
|
|
|
class SubProject(models.Model):
|
|
|
|
name = models.CharField(max_length = 100)
|
|
|
|
slug = models.SlugField(db_index = True)
|
|
|
|
project = models.ForeignKey(Project)
|
|
|
|
repo = models.CharField(max_length = 200)
|
|
|
|
branch = models.CharField(max_length = 50)
|
2012-02-27 11:53:18 +01:00
|
|
|
filemask = models.CharField(max_length = 200)
|
2012-02-27 11:54:27 +01:00
|
|
|
style_choices = (('po', 'po'), ('ts', 'ts'))
|
|
|
|
style = models.CharField(max_length = 10, choices = style_choices)
|
2012-02-27 10:46:12 +01:00
|
|
|
|
2012-02-27 11:11:37 +01:00
|
|
|
@models.permalink
|
|
|
|
def get_absolute_url(self):
|
2012-02-27 11:18:49 +01:00
|
|
|
return ('trans.views.show_subproject', (), {'project': self.project.slug, 'subproject': self.slug})
|
2012-02-27 11:11:37 +01:00
|
|
|
|
2012-02-27 11:45:27 +01:00
|
|
|
def __unicode__(self):
|
|
|
|
return '%s/%s' (self.project.__unicode__(), self.name)
|
|
|
|
|
2012-02-27 10:46:12 +01:00
|
|
|
class Translation(models.Model):
|
|
|
|
subproject = models.ForeignKey(SubProject)
|
|
|
|
language = models.ForeignKey(Language)
|
|
|
|
translated = models.FloatField()
|
2012-02-27 10:56:15 +01:00
|
|
|
fuzzy = models.FloatField()
|
2012-02-27 10:46:12 +01:00
|
|
|
revision = models.CharField(max_length = 40)
|
|
|
|
filename = models.CharField(max_length = 200)
|
2012-02-27 10:58:59 +01:00
|
|
|
|
2012-02-27 11:11:37 +01:00
|
|
|
@models.permalink
|
|
|
|
def get_absolute_url(self):
|
2012-02-27 11:18:49 +01:00
|
|
|
return ('trans.views.show_translation', (), {'project': self.subproject.slug, 'subproject': self.subproject.slug, 'lang': self.language.code})
|
2012-02-27 11:11:37 +01:00
|
|
|
|
2012-02-27 11:45:27 +01:00
|
|
|
def __unicode__(self):
|
|
|
|
return '%s@%s' (self.language.name, self.subproject.__unicode__())
|
|
|
|
|
2012-02-27 10:58:59 +01:00
|
|
|
class Unit(models.Model):
|
|
|
|
translation = models.ForeignKey(Translation)
|
|
|
|
location = models.TextField()
|
|
|
|
flags = models.TextField()
|
|
|
|
source = models.TextField()
|
|
|
|
target = models.TextField()
|
2012-02-27 11:08:16 +01:00
|
|
|
|
|
|
|
def is_plural(self):
|
|
|
|
return self.source.find(PLURAL_SEPARATOR) != -1
|
|
|
|
|
|
|
|
def get_source_plurals(self):
|
|
|
|
return self.source.split(PLURAL_SEPARATOR)
|
|
|
|
|
|
|
|
def get_target_plurals(self):
|
|
|
|
ret = self.target.split(PLURAL_SEPARATOR)
|
|
|
|
plurals = self.translation.language.nplurals
|
|
|
|
if len(ret) == plurals:
|
|
|
|
return ret
|
|
|
|
|
|
|
|
while len(ret) < plurals:
|
|
|
|
ret.append('')
|
|
|
|
|
|
|
|
while len(ret) > plurals:
|
|
|
|
del(ret[-1])
|
|
|
|
|
|
|
|
return ret
|