Django

Code

Changeset 3318

Show
Ignore:
Timestamp:
07/10/06 21:49:56 (2 years ago)
Author:
adrian
Message:

Added note to docs/settings.txt and docs/i18n.txt about not importing from django.utils.translation in the settings file

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/i18n.txt

    r3247 r3318  
    453453    * Only languages listed in the `LANGUAGES setting`_ can be selected. If 
    454454      you want to restrict the language selection to a subset of provided 
    455       languages (because your appliaction doesn't provide all those languages), 
     455      languages (because your application doesn't provide all those languages), 
    456456      set ``LANGUAGES`` to a list of languages. For example:: 
    457457 
     
    466466 
    467467      .. _LANGUAGES setting: http://www.djangoproject.com/documentation/settings/#languages 
     468 
     469    * If you define a custom ``LANGUAGES`` setting, as explained in the 
     470      previous bullet, it's OK to mark the languages as translation strings 
     471      -- but use a "dummy" ``gettext()`` function, not the one in 
     472      ``django.utils.translation``. You should *never* import 
     473      ``django.utils.translation`` from within your settings file, because that 
     474      module in itself depends on the settings, and that would cause a circular 
     475      import. 
     476 
     477      The solution is to use a "dummy" ``gettext()`` function. Here's a sample 
     478      settings file:: 
     479 
     480          gettext = lambda s: s 
     481 
     482          LANGUAGES = ( 
     483              ('de', gettext('German')), 
     484              ('en', gettext('English')), 
     485          ) 
     486 
     487      With this arrangement, ``make-messages.py`` will still find and mark 
     488      these strings for translation, but the translation won't happen at 
     489      runtime -- so you'll have to remember to wrap the languages in the *real* 
     490      ``gettext()`` in any code that uses ``LANGUAGES`` at runtime. 
     491 
    468492    * The ``LocaleMiddleware`` can only select languages for which there is a 
    469493      Django-provided base translation. If you want to provide translations 
  • django/trunk/docs/settings.txt

    r3297 r3318  
    502502to restrict language selection to a subset of the Django-provided languages. 
    503503 
     504If you define a custom ``LANGUAGES`` setting, it's OK to mark the languages as 
     505translation strings (as in the default value displayed above) -- but use a 
     506"dummy" ``gettext()`` function, not the one in ``django.utils.translation``. 
     507You should *never* import ``django.utils.translation`` from within your 
     508settings file, because that module in itself depends on the settings, and that 
     509would cause a circular import. 
     510 
     511The solution is to use a "dummy" ``gettext()`` function. Here's a sample 
     512settings file:: 
     513 
     514    gettext = lambda s: s 
     515 
     516    LANGUAGES = ( 
     517        ('de', gettext('German')), 
     518        ('en', gettext('English')), 
     519    ) 
     520 
     521With this arrangement, ``make-messages.py`` will still find and mark these 
     522strings for translation, but the translation won't happen at runtime -- so 
     523you'll have to remember to wrap the languages in the *real* ``gettext()`` in 
     524any code that uses ``LANGUAGES`` at runtime. 
     525 
    504526MANAGERS 
    505527--------