From 53e2f3137c6198256be9ae74a231c17c9c85ee7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 27 Feb 2012 11:08:16 +0100 Subject: [PATCH] Plurals handling --- trans/models.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/trans/models.py b/trans/models.py index 79ad1012f..8a99dcd2b 100644 --- a/trans/models.py +++ b/trans/models.py @@ -1,6 +1,8 @@ from django.db import models from lang.models import Language +PLURAL_SEPARATOR = '\x00\x00' + class Project(models.Model): name = models.CharField(max_length = 100) slug = models.SlugField(db_index = True) @@ -29,3 +31,23 @@ class Unit(models.Model): flags = models.TextField() source = models.TextField() target = models.TextField() + + 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