
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
.. image:: https://travis-ci.com/ecometrica/django-vinaigrette.svg?branch=master :target: https://travis-ci.com/ecometrica/django-vinaigrette?branch=master .. image:: https://coveralls.io/repos/github/ecometrica/django-vinaigrette/badge.svg?branch=master :target: https://coveralls.io/github/ecometrica/django-vinaigrette?branch=master
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 apps.py
files
(or wherever you keep your AppConfig
subclasses):
.. code:: python
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 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:
.. code:: python
>>> from django.utils.translation import activate
>>> i = Ingredient(name=u'Lettuce')
>>> i.name
u'Lettuce'
>>> activate('fr')
>>> i.name
u'Laitue'
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:
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:
.. code:: python
>>> 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'
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.
tox
. When tox is run, it will create the test environments for
supported Django and Python versions and then run tests against themFix Python 2 support for makemessages
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
MIDDLEWARE_CLASSES
or MIDDLEWARE
Deprecates VinaigrettteAdminLanguageMiddleware
for VinaigretteAdminLanguageMiddleware
vinaigrette.middleware.VinaigretteAdminLanguageMiddleware
vinaigrette.VinaigrettteAdminLanguageMiddleware
will continue to work until next major versionAdds tox and pytest for development and testing
--keep-vinaigrette-temp
option which keeps the temporary file containing the generated list of translationsFAQs
Translate Django model data using gettext
We found that django-vinaigrette demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.