1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

i18n: updated translation documentation for gettext_lazy

git-svn-id: http://code.djangoproject.com/svn/django/branches/i18n@885 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Georg Bauer 2005-10-16 16:15:58 +00:00
parent a6a0d1ddcc
commit 6807c4bd4d

View File

@ -68,6 +68,23 @@ they are exchanged over systems or users - like strings in a database - but
should be translated at the last possible point in time, when the string
is presented to the user.
One special case that isn't available in other gettext usages are lazily
translated strings. This is needed for stuff that you set up in your django
model files - those messages are stored internally and translated on access, but
not translated on storage (as that would only take the default language into account).
To translate a model helptext, do the following::
from django.utils.translation import gettext_lazy
class Mything(meta.Model):
name = meta.CharField('Name', help_text=gettext_lazy('This is the help text'))
...
This way only a lazy reference is stored for the string, not the actual translation.
The translation itself will be done when the string is used in a string context, like
template rendering in the admin.
There is a standard problem with translations, that is pluralization of
strings. This is done by the standard helper ngettext like so::