forked from ecometrica/django-vinaigrette
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.rst
91 lines (66 loc) · 2.62 KB
/
README.rst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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'
Help! The Admin is messing up all the vinaigrette fields whenever I save changes!
---------------------------------------------------------------------------------
Use `vinaigrette.VinaigrettteAdminLanguageMiddleware` to force the admin to
always use the main language, and not have vinaigrette mess with your
change views.
=============
Release Notes
=============
0.1.3
-----
* Support for Django 1.6.
0.2.0
-----
* New VinaigrettteAdminLanguageMiddleware middleware.
* Bug fix for the --all option, it now works again.
0.3.0
-----
* Support for python 3.3.