2012-02-27 16:09:31 +01:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
from lang.models import Language
|
|
|
|
|
2012-02-27 17:54:42 +01:00
|
|
|
from util import is_plural, split_plural, join_plural
|
|
|
|
|
2012-02-27 16:09:31 +01:00
|
|
|
class TranslationManager(models.Manager):
|
|
|
|
def update_from_blob(self, subproject, code, path, blob):
|
|
|
|
'''
|
|
|
|
Parses translation meta info and creates/updates translation object.
|
|
|
|
'''
|
|
|
|
lang = Language.objects.get(code = code)
|
|
|
|
trans, created = self.get_or_create(
|
|
|
|
language = lang,
|
|
|
|
subproject = subproject,
|
|
|
|
filename = path)
|
2012-02-27 16:29:32 +01:00
|
|
|
trans.update_from_blob(blob)
|
2012-02-27 16:09:31 +01:00
|
|
|
|
2012-02-27 17:50:47 +01:00
|
|
|
class UnitManager(models.Manager):
|
|
|
|
def update_from_unit(self, translation, unit):
|
|
|
|
'''
|
|
|
|
Process translation toolkit unit and stores/updates database entry.
|
|
|
|
'''
|
2012-02-27 17:54:42 +01:00
|
|
|
src = join_plural(unit.source.strings)
|
2012-02-27 17:50:47 +01:00
|
|
|
ctx = unit.getcontext()
|
2012-02-27 18:05:42 +01:00
|
|
|
import trans.models
|
|
|
|
try:
|
|
|
|
dbunit = self.get(
|
|
|
|
translation = translation,
|
|
|
|
source = src,
|
|
|
|
context = ctx)
|
|
|
|
force = False
|
|
|
|
except:
|
|
|
|
dbunit = trans.models.Unit(
|
|
|
|
translation = translation,
|
|
|
|
source = src,
|
|
|
|
context = ctx)
|
|
|
|
force = True
|
|
|
|
|
|
|
|
dbunit.update_from_unit(unit, force)
|
2012-02-27 17:50:47 +01:00
|
|
|
return dbunit
|