summaryrefslogtreecommitdiff
path: root/docs/topics
diff options
context:
space:
mode:
authorBernardo Pires <carneiro.be@gmail.com>2013-11-09 11:32:19 +0100
committerBaptiste Mispelon <bmispelon@gmail.com>2013-11-10 00:02:13 +0100
commit4aed1ee339c4a36035e1fd1a02b1ec9142feac07 (patch)
tree0229169fa61e2ce8ef363d5ba92a01dbb3b25493 /docs/topics
parent4b9e932fd46eaac4774d229c40c2ee75f8fb759b (diff)
[1.6.x] Fixed #21372 -- Corrected docs regarding translating LANGUAGES.
Corrected LANGUAGES documentation on how to translate language names. Now using django.utils.translation.ugettext_lazy instead of a dummy gettext() function. Thanks to Salvatore for the report. Backport of 8bc350b38516d8c3a14aed113dd3402b9375b75c from master.
Diffstat (limited to 'docs/topics')
-rw-r--r--docs/topics/i18n/translation.txt24
1 files changed, 7 insertions, 17 deletions
diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt
index aadb0a6f03..77c8915a06 100644
--- a/docs/topics/i18n/translation.txt
+++ b/docs/topics/i18n/translation.txt
@@ -1624,29 +1624,19 @@ Notes:
en-us).
* If you define a custom :setting:`LANGUAGES` setting, as explained in the
- previous bullet, it's OK to mark the languages as translation strings
- -- but use a "dummy" ``ugettext()`` function, not the one in
- ``django.utils.translation``. You should *never* import
- ``django.utils.translation`` from within your settings file, because that
- module in itself depends on the settings, and that would cause a circular
- import.
+ previous bullet, you can mark the language names as translation strings
+ -- but use :func:`~django.utils.translation.ugettext_lazy` instead of
+ :func:`~django.utils.translation.ugettext` to avoid a circular import.
- The solution is to use a "dummy" ``ugettext()`` function. Here's a sample
- settings file::
+ Here's a sample settings file::
- ugettext = lambda s: s
+ from django.utils.translation import ugettext_lazy as _
LANGUAGES = (
- ('de', ugettext('German')),
- ('en', ugettext('English')),
+ ('de', _('German')),
+ ('en', _('English')),
)
- With this arrangement, :djadmin:`django-admin.py makemessages <makemessages>`
- will still find and mark these strings for translation, but the translation
- won't happen at runtime -- so you'll have to remember to wrap the languages in
- the *real* ``ugettext()`` in any code that uses :setting:`LANGUAGES` at
- runtime.
-
Once ``LocaleMiddleware`` determines the user's preference, it makes this
preference available as ``request.LANGUAGE_CODE`` for each
:class:`~django.http.HttpRequest`. Feel free to read this value in your view