Skip to main content
https://travis-ci.com/ecometrica/django-vinaigrette.svg?branch=master https://coveralls.io/repos/github/ecometrica/django-vinaigrette/badge.svg?branch=master

django-vinaigrette

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

Installing

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 apps.py 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.

Using

After installing vinaigrette, the PO files generated by manage.py 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')
>>> i.name
u'Lettuce'
>>> activate('fr')
>>> i.name
u'Laitue'

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 manage.py 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')
>>> i.name
u'Laitue'
>>> i.name = 'Cabbage'
>>> i.name
u'Chou'
>>> i.save()
>>> Ingredient.objects.get(name='Cabbage').name
u'Chou'

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.

Contributing

Testing

  • 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

Release Notes

2.0.1

  • Rebuild for PyPI

2.0.0

  • Remove Python 2 support

  • Allow running makemessages without specifying a locale (runs on all locales)

  • Address Django upgrade warnings

  • Ensure that makemessages works when a non-English locale is active during its execution

1.2.1

  • Fix Python 2 support for makemessages

    • Add a test for makemessages

1.2.0

  • Added an optional contexts parameter for the register function, for providing translation context for model fields.

  • Update middleware to the 1.10+ style

    • Maintains backwards-compat with 1.9 and below

      • Will now work in either MIDDLEWARE_CLASSES or MIDDLEWARE

    • Deprecates VinaigrettteAdminLanguageMiddleware for VinaigretteAdminLanguageMiddleware

      • Users should change to vinaigrette.middleware.VinaigretteAdminLanguageMiddleware

      • vinaigrette.VinaigrettteAdminLanguageMiddleware will continue to work until next major version

  • Adds tox and pytest for development and testing

1.1.1

  • Update contact info

1.1.0

  • Django 2.0 support

1.0.1

  • Remembered to update version properly

1.0.0

  • Add the --keep-vinaigrette-temp option which keeps the temporary file containing the generated list of translations

  • Added support for Django 1.9

  • Remove support for Django versions < 1.8

0.5.0

  • Can specify properties to use instead of database field names in .register() function.

0.4.0

  • Support for Django 1.7

0.3.0

  • Support for python 3.3.

0.2.0

  • Bug fix for the –all option, it now works again.

  • New VinaigrettteAdminLanguageMiddleware middleware.

0.1.3

  • Support for Django 1.6.

Metadata

Release files for django-vinaigrette 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-vinaigrette 2.0.1
File Size Uploaded
django-vinaigrette-2.0.1.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-vinaigrette 2.0.1
File Interpreter ABI Platform
django_vinaigrette-2.0.1-py2-none-any.whl Python 2 none any Details

Total release size: 22.6 kB

Release files / django-vinaigrette-2.0.1.tar.gz

Download URL django-vinaigrette-2.0.1.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
cf5b3e789da3f4f755a896c39c7b226932e171d782b006ed9771b04597df8f2e
BLAKE2b-256 checksum
How to use checksums
18072c3b669d0db3491a1184509914684891c3bea14f4d971d4afa3d7d950032
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

Release files / django_vinaigrette-2.0.1-py2-none-any.whl

Download URL django_vinaigrette-2.0.1-py2-none-any.whl
Size 12.3 kB
Tags Python 2
SHA-256 checksum
How to use checksums
84f2fc3b77001cd378c613020d011c0a5ae854dd33cba92ff73c63ce57650139
BLAKE2b-256 checksum
How to use checksums
63723cf032be97c04cfd3e056953264f9d0a31895e64983be36ee36c79266892
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.2.1

2 release files

1.2.0

1 release file

1.1.1

2 release files

1.1.0

2 release files

1.0.1

1 release file

1.0.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page