xmpp.chapril.org-conversejs/trans/models.py

66 lines
2.0 KiB
Python
Raw Normal View History

2012-02-27 10:05:53 +01:00
from django.db import models
2012-02-27 10:46:12 +01:00
from lang.models import Language
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):
return ('trans.views.project', (), {'project': self.slug})
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 10:46:12 +01:00
2012-02-27 11:11:37 +01:00
@models.permalink
def get_absolute_url(self):
return ('trans.views.subproject', (), {'project': self.project.slug, 'subproject': self.slug})
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):
return ('trans.views.translation', (), {'project': self.subproject.slug, 'subproject': self.subproject.slug, 'lang': self.language.code})
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