Factor out plurals handling
This commit is contained in:
parent
941aa9747b
commit
e8956cfbeb
|
@ -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
15
trans/util.py
Normal 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)
|
||||
|
Loading…
Reference in New Issue
Block a user