Factor out plurals handling

This commit is contained in:
Michal Čihař 2012-02-27 17:54:14 +01:00
parent 941aa9747b
commit e8956cfbeb
2 changed files with 19 additions and 5 deletions

View File

@ -8,8 +8,7 @@ import git
from translate.storage import factory
from trans.managers import TranslationManager, UnitManager
PLURAL_SEPARATOR = '\x00\x00'
from util import is_plural, split_plural, join_plural
class Project(models.Model):
name = models.CharField(max_length = 100)
@ -214,13 +213,13 @@ class Unit(models.Model):
self.save()
def is_plural(self):
return self.source.find(PLURAL_SEPARATOR) != -1
return is_plural(self.source)
def get_source_plurals(self):
return self.source.split(PLURAL_SEPARATOR)
return split_plural(self.source)
def get_target_plurals(self):
ret = self.target.split(PLURAL_SEPARATOR)
ret = split_plural(self.target)
plurals = self.translation.language.nplurals
if len(ret) == plurals:
return ret

15
trans/util.py Normal file
View File

@ -0,0 +1,15 @@
PLURAL_SEPARATOR = '\x00\x00'
def is_plural(s):
'''
Checks whether string is plural form.
'''
return s.find(PLURAL_SEPARATOR) != -1
def split_plural(s):
return s.split(PLURAL_SEPARATOR)
def join_plural(s):
return PLURAL_SEPARATOR.join(s)