Exemple #1
0
def _save_translation(entity, locale, translation, author=""):
    """Admin interface: save new or update existing translation in DB."""

    translations = Translation.objects.filter(entity=entity, locale=locale).order_by("date")

    if len(translations) == 0:  # New translation
        t = Translation(entity=entity, locale=locale, string=translation, author=author, date=datetime.datetime.now())
    else:  # Update translation
        t = translations.reverse()[0]
        t.string = translation
        t.author = author
        t.date = datetime.datetime.now()
    t.save()