Django

Code

Changeset 1090

Show
Ignore:
Timestamp:
11/04/05 22:40:07 (3 years ago)
Author:
adrian
Message:

Made small edits to docs/i18n.txt

Files:

Legend:

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

    r1089 r1090  
    44 
    55Django has full support for internationalization of text in code and templates. 
    6 Here's an overview of how translation works in Django. 
    7  
    8 .. admonition:: Behind the scenes 
    9  
    10     Django's translation machinery uses the standard ``gettext`` module that 
    11     comes with Python. 
     6Here's how it works. 
    127 
    138Overview 
     
    4136    3. Activate the locale middleware in your Django settings. 
    4237 
     38 
     39.. admonition:: Behind the scenes 
     40 
     41    Django's translation machinery uses the standard ``gettext`` module that 
     42    comes with Python. 
     43 
    4344How to specify translation strings 
    4445================================== 
     
    8889        return HttpResponse(output) 
    8990 
     91(The caveat with using variables or computed values, as in the previous two 
     92examples, is that Django's translation-string-detecting utility, 
     93``make-messages.py``, won't be able to find these strings. More on 
     94``make-messages`` later.) 
     95 
    9096The strings you pass to ``_()`` or ``gettext()`` can take placeholders, 
    9197specified with Python's standard named-string interpolation syntax. Example:: 
     
    109115 
    110116Use the function ``django.utils.translation.gettext_noop()`` to mark a string 
    111 as a translate string without translating it. The string is later translated 
     117as a translation string without translating it. The string is later translated 
    112118from a variable. 
    113119 
     
    136142 
    137143If you don't like the verbose name ``gettext_lazy``, you can just alias it as 
    138 ``_``, like so:: 
     144``_`` (underscore), like so:: 
    139145 
    140146    from django.utils.translation import gettext_lazy as _ 
     
    143149        name = meta.CharField(help_text=_('This is the help text')) 
    144150 
    145 Always use lazy translations in Django models. And it's a good idea to add 
     151Always use lazy translations in `Django models`_. And it's a good idea to add 
    146152translations for the field names and table names, too. This means writing 
    147153explicit ``verbose_name`` and ``verbose_name_plural`` options in the ``META`` 
     
    155161            verbose_name = _('my thing') 
    156162            verbose_name_plural = _('mythings') 
     163 
     164.. _Django models: http://www.djangoproject.com/documentation/model_api/ 
    157165 
    158166Pluralization 
     
    176184---------------- 
    177185 
    178 Using translations in Django templates uses two template tags and a slightly 
     186Using translations in `Django templates`_ uses two template tags and a slightly 
    179187different syntax than in Python code. To give your template access to these 
    180188tags, put ``{% load i18n %}`` toward the top of your template. 
     
    241249string, so they don't need to be aware of translations. 
    242250 
     251.. _Django templates: http://www.djangoproject.com/documentation/templates_python/ 
     252 
    243253How to create language files 
    244254============================ 
     
    263273 
    264274...where ``de`` is the language code for the message file you want to create. 
    265 (The language code, in this case, is in locale format. So, for example, it's 
    266 ``pt_BR`` for Brazilian and ``de_AT`` for Austrian German.) 
    267  
    268 The script should be run from one of three places:: 
     275The language code, in this case, is in locale format. For example, it's 
     276``pt_BR`` for Brazilian and ``de_AT`` for Austrian German. 
     277 
     278The script should be run from one of three places: 
    269279 
    270280    * The root ``django`` directory (not a Subversion checkout, but the one 
     
    326336    the charset line (search for ``"CHARSET"``) and set it to the charset 
    327337    you'll be using to edit the content. Generally, utf-8 should work for most 
    328     languages, but ``gettext`` can handle any charset you throw at it. 
     338    languages, but ``gettext`` should handle any charset you throw at it. 
    329339 
    330340To reexamine all source code and templates for new translation strings and 
    331 update all message files for **all** languages, run ``make-messages.py -a``. 
     341update all message files for **all** languages, run this:: 
     342 
     343    make-messages.py -a 
    332344 
    333345Compiling message files