Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Vinaigrette translates Django model data -- stored in the database -- using GNU gettext and Django's standard internationalization features.


Add vinaigrette to INSTALLED_APPS in your settings.

Then, tell vinaigrette which fields you want to translate. Because vinaigrette needs to register signals, you should register your model translations when models have finished loading, in the appropriate files (or wherever you keep your AppConfig subclasses):

import vinaigrette

class SaladAppConfig(AppConfig):
    def ready(self):
        # Import the model requiring translation
        from .models import Ingredient  # or...
        Ingredient = self.get_model("Ingredient")

        # Register fields to translate
        vinaigrette.register(Ingredient, ['name', 'description'])

This tells vinaigrette to translate the name and description fields on Ingredient objects.


After installing vinaigrette, the PO files generated by makemessages will include strings from the registered fields. If a particular string is translated, the model value will be the string translated into the appropriate language:

>>> from django.utils.translation import activate
>>> i = Ingredient(name=u'Lettuce')
>>> activate('fr')

Et cetera

There are a couple of options to restrict which objects translation strings will be collected from. See the docstring for vinaigrette.register.

Vinaigrette adds a --keep-obsolete option to makemessages, which prevents gettext from deactivating translated messages no longer present in code or in registered database fields.

Vinaigrette is designed for database content that is:

  • always edited in the default language
  • edited by site administrators, not users

Only model instances are translated. Data accessed via the Django QuerySet values method will not be translated.

In general, when a field is accessed, it will always return the translated version, if one exists. However, if a value is set, the exact value entered (and not the translated version) should be saved to the database. For example:

>>> from django.utils.translation import activate
>>> i = Ingredient(name=u'Lettuce')
>>> activate('fr')
>>> = 'Cabbage'
>>> Ingredient.objects.get(name='Cabbage').name

Help! The Admin is messing up all the vinaigrette fields whenever I save changes!

Add vinaigrette.middleware.VinaigretteAdminLanguageMiddleware to your settings.MIDDLEWARE to force the admin to always use the main language, and not have vinaigrette mess with your change views.



  • Create a virtualenv for the project
  • Install tox. When tox is run, it will create the test environments for supported Django and Python versions and then run tests against them