django-hvad 1.3.0

A content translation framework for django integrated automatically in the normal ORM. Removes the pain of having to think about translations in a django project.

Model translations made easy.

This project adds support for model translations in Django. It is designed to be unobtrusive, efficient and reliable. On the technical side, it uses an automatically created Translations Model to store translatable fields in arbitrary languages with a foreign key to the main model, enabling fast queries.

Started in 2011, hvad has grown mature and is now used on large scale applications.

Quick links:

Features

  • Simple - only 3 new queryset methods.
  • Natural - use Django ORM as usual, it just became language aware.
  • Fast - no additional queries for reads, just an inner join to an indexed key.
  • Complete - relationships, custom managers and querysets, proxy models, and abstract models.
  • Batteries included - translation-enabled forms and admin are provided.
  • Reliable - more than 300 test cases and counting.
  • Compatible with Django 1.4 to 1.8, running Python 2.7, 3.3 or 3.4.

Example Uses

Declaring a translatable Book model:

class Book(TranslatableModel):
    author = models.ForeignKey(Author)
    release = models.Date()

    translations = TranslatedFields(
        title = models.CharField(max_length=250)
    )

Thus, only the title will vary based on the language. Release date and author are shared among all languages. Let's now create a Book instance:

# The recommended way:
book = Book.objects.language('en').create(
    author = Author.objects.get(name='Antoine de Saint Exupéry'),
    release = datetime.date(1943, 4, 6),
    title = "The Little Prince",
)

# Also works
book = Book(language_code='en')
book.author = Author.objects.get(name='Antoine de Saint Exupéry')
book.release = datetime.date(1943, 4, 6)
book.title = "The Little Prince"
book.save()

Providing some translations:

book.translate('fr')
book.title = "Le Petit Prince"
book.save()
book.translate('de')
book.title = "Der kleine Prinz"
book.save()

Every call to translate() creates a new translation from scratch and switches to that translation; save() only saves the latest translation. Let's now perform some language-aware queries:

Book.objects.all()

Compatible by default: returns all objects, without any translated fields attached. Starting from v1.0, default behavior can be overriden to work like next query:

Book.objects.language().all()

Returns all objects as translated instances, but only the ones that are translated into the currect language. You can also specify which language to get, using e.g.:

Book.objects.language("en").all()

Usual queryset methods work like they always did: let's get all books as translated instances, filtering on the title attribute, returning those that have Petit Prince in their French title, ordered by publication date (in their French edition):

Book.objects.language("fr").filter(title__contains='Petit Prince').order_by('release')

Other random examples:

# last German book published in year 1948
Book.objects.language("de").filter(release__year=1948).latest()

# other books from the same author as mybook. Cache author as well.
Book.objects.language().select_related('author').filter(author__books=mybook)

# books that have "Django" in their title, regardless of the language
Book.objects.language('all').filter(title__icontains='Django')

More examples in the quickstart guide.

Author

Kristian Ollegaard

Pip

django-hvad==1.3.0

Classifiers

  • Development Status :: 5 - Production/Stable
  • Framework :: Django
  • Intended Audience :: Developers
  • Operating System :: OS Independent
  • Programming Language :: Python :: 2.7
  • Programming Language :: Python :: 3.3
  • Programming Language :: Python :: 3.4
  • License :: OSI Approved :: BSD License
  • Topic :: Database
  • Topic :: Internet :: WWW/HTTP :: Dynamic Content
  • Topic :: Text Processing :: Linguistic
File Type Python Version Uploaded On Downloads
django-hvad-1.3.0.zip Source July 29, 2015 298
django-hvad-1.3.0.tar.gz Source July 29, 2015 1,987
Version Release Date
1.3.0 July 29, 2015
1.2.2 June 3, 2015
1.2.1 May 5, 2015
1.2.0 March 19, 2015
1.1.1 March 5, 2015
1.1.0 Feb. 17, 2015
1.0.0 Dec. 19, 2014
0.5.2 Nov. 8, 2014
0.5.1 Oct. 23, 2014
0.5.0 Sept. 11, 2014
0.4.1 June 1, 2014
0.4.0 May 20, 2014
0.3 May 18, 2013
0.2 Aug. 13, 2012
0.1.5 Feb. 2, 2012
0.1.4 Nov. 29, 2011
0.1.2 Oct. 17, 2011
0.1.1 Sept. 28, 2011
0.1.0 Sept. 22, 2011
0.0.6 Sept. 20, 2011
0.0.5 Sept. 7, 2011
0.0.4 Sept. 6, 2011
0.0.3 Sept. 5, 2011
Date Package Version Action
Aug. 26, 2015, 12:13 a.m. django-hvad 1.2.1 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 1.2.0 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 1.2.2 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 1.3.0 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.5.2 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.5.1 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.5.0 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.4.0 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.4.1 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.0.3 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.0.6 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.0.4 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.0.5 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.1.5 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.1.4 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.1.2 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.1.1 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.1.0 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.2 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 0.3 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 1.0.0 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 1.1.0 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad 1.1.1 Release Created
Aug. 26, 2015, 12:13 a.m. django-hvad Package Created