Changeset 1090
- Timestamp:
- 11/04/05 22:40:07 (3 years ago)
- Files:
-
- django/trunk/docs/i18n.txt (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/i18n.txt
r1089 r1090 4 4 5 5 Django 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. 6 Here's how it works. 12 7 13 8 Overview … … 41 36 3. Activate the locale middleware in your Django settings. 42 37 38 39 .. admonition:: Behind the scenes 40 41 Django's translation machinery uses the standard ``gettext`` module that 42 comes with Python. 43 43 44 How to specify translation strings 44 45 ================================== … … 88 89 return HttpResponse(output) 89 90 91 (The caveat with using variables or computed values, as in the previous two 92 examples, 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 90 96 The strings you pass to ``_()`` or ``gettext()`` can take placeholders, 91 97 specified with Python's standard named-string interpolation syntax. Example:: … … 109 115 110 116 Use the function ``django.utils.translation.gettext_noop()`` to mark a string 111 as a translat estring without translating it. The string is later translated117 as a translation string without translating it. The string is later translated 112 118 from a variable. 113 119 … … 136 142 137 143 If you don't like the verbose name ``gettext_lazy``, you can just alias it as 138 ``_`` , like so::144 ``_`` (underscore), like so:: 139 145 140 146 from django.utils.translation import gettext_lazy as _ … … 143 149 name = meta.CharField(help_text=_('This is the help text')) 144 150 145 Always use lazy translations in Django models. And it's a good idea to add151 Always use lazy translations in `Django models`_. And it's a good idea to add 146 152 translations for the field names and table names, too. This means writing 147 153 explicit ``verbose_name`` and ``verbose_name_plural`` options in the ``META`` … … 155 161 verbose_name = _('my thing') 156 162 verbose_name_plural = _('mythings') 163 164 .. _Django models: http://www.djangoproject.com/documentation/model_api/ 157 165 158 166 Pluralization … … 176 184 ---------------- 177 185 178 Using translations in Django templatesuses two template tags and a slightly186 Using translations in `Django templates`_ uses two template tags and a slightly 179 187 different syntax than in Python code. To give your template access to these 180 188 tags, put ``{% load i18n %}`` toward the top of your template. … … 241 249 string, so they don't need to be aware of translations. 242 250 251 .. _Django templates: http://www.djangoproject.com/documentation/templates_python/ 252 243 253 How to create language files 244 254 ============================ … … 263 273 264 274 ...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's266 ``pt_BR`` for Brazilian and ``de_AT`` for Austrian German. )267 268 The script should be run from one of three places: :275 The 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 278 The script should be run from one of three places: 269 279 270 280 * The root ``django`` directory (not a Subversion checkout, but the one … … 326 336 the charset line (search for ``"CHARSET"``) and set it to the charset 327 337 you'll be using to edit the content. Generally, utf-8 should work for most 328 languages, but ``gettext`` canhandle any charset you throw at it.338 languages, but ``gettext`` should handle any charset you throw at it. 329 339 330 340 To reexamine all source code and templates for new translation strings and 331 update all message files for **all** languages, run ``make-messages.py -a``. 341 update all message files for **all** languages, run this:: 342 343 make-messages.py -a 332 344 333 345 Compiling message files
