Made a couple of tweaks to lazy translation docs.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17490 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
8d381acb24
commit
fc14996c8d
|
@ -306,13 +306,13 @@ string context, such as in template rendering.
|
||||||
This is essential when calls to these functions are located in code paths that
|
This is essential when calls to these functions are located in code paths that
|
||||||
are executed at module load time.
|
are executed at module load time.
|
||||||
|
|
||||||
As this is something that can easily happen when defining models (the
|
As this is something that can easily happen when defining models, forms and
|
||||||
declarative notation of Django models is implemented in a way such that model
|
model forms (the declarative notation Django offers for them is implemented in a
|
||||||
fields are actually class level attributes) this means you need to make sure to
|
way such that their fields are actually class level attributes) this means you
|
||||||
use lazy translations in the following cases:
|
need to make sure to use lazy translations in the following cases:
|
||||||
|
|
||||||
Model fields and relationship ``verbose_name`` and ``help_text`` option values
|
Model fields and relationships ``verbose_name`` and ``help_text`` option values
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
For example, to translate the help text of the *name* field in the following
|
For example, to translate the help text of the *name* field in the following
|
||||||
model, do the following::
|
model, do the following::
|
||||||
|
@ -369,8 +369,8 @@ with the ``short_description`` attribute::
|
||||||
return self.kind.type == MOUSE_TYPE
|
return self.kind.type == MOUSE_TYPE
|
||||||
is_mouse.short_description = _('Is it a mouse?')
|
is_mouse.short_description = _('Is it a mouse?')
|
||||||
|
|
||||||
Notes on translation in models
|
Working with lazy translation objects
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
-------------------------------------
|
||||||
|
|
||||||
The result of a ``ugettext_lazy()`` call can be used wherever you would use a
|
The result of a ``ugettext_lazy()`` call can be used wherever you would use a
|
||||||
unicode string (an object with type ``unicode``) in Python. If you try to use
|
unicode string (an object with type ``unicode``) in Python. If you try to use
|
||||||
|
@ -398,15 +398,12 @@ If you don't like the long ``ugettext_lazy`` name, you can just alias it as
|
||||||
class MyThing(models.Model):
|
class MyThing(models.Model):
|
||||||
name = models.CharField(help_text=_('This is the help text'))
|
name = models.CharField(help_text=_('This is the help text'))
|
||||||
|
|
||||||
Working with lazy translation objects
|
|
||||||
-------------------------------------
|
|
||||||
|
|
||||||
Using ``ugettext_lazy()`` and ``ungettext_lazy()`` to mark strings in models
|
Using ``ugettext_lazy()`` and ``ungettext_lazy()`` to mark strings in models
|
||||||
and utility functions is a common operation. When you're working with these
|
and utility functions is a common operation. When you're working with these
|
||||||
objects elsewhere in your code, you should ensure that you don't accidentally
|
objects elsewhere in your code, you should ensure that you don't accidentally
|
||||||
convert them to strings, because they should be converted as late as possible
|
convert them to strings, because they should be converted as late as possible
|
||||||
(so that the correct locale is in effect). This necessitates the use of a
|
(so that the correct locale is in effect). This necessitates the use of the
|
||||||
couple of helper functions.
|
helper function described next.
|
||||||
|
|
||||||
Joining strings: string_concat()
|
Joining strings: string_concat()
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
Loading…
Reference in New Issue