From 6807c4bd4d209e055bd05e0518a5c86493b16bb3 Mon Sep 17 00:00:00 2001 From: Georg Bauer Date: Sun, 16 Oct 2005 16:15:58 +0000 Subject: [PATCH] i18n: updated translation documentation for gettext_lazy git-svn-id: http://code.djangoproject.com/svn/django/branches/i18n@885 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/translation.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/translation.txt b/docs/translation.txt index 37d2bc2385..0397374568 100644 --- a/docs/translation.txt +++ b/docs/translation.txt @@ -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::