Giter Club home page Giter Club logo

django-vinaigrette's Introduction

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. In the appropriate models.py files:

import vinaigrette
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'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.