Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add missing imports and models to the examples in internationalizatio…

…n and localization documentation
  • Loading branch information...
commit 1d543949d7acc93a172e8a2c9272d8b983a421ef 1 parent 6a47995
Silvan Spross authored May 19, 2013

Showing 1 changed file with 15 additions and 2 deletions. Show diff stats Hide diff stats

  1. 17  docs/topics/i18n/translation.txt
17  docs/topics/i18n/translation.txt
@@ -80,6 +80,7 @@ In this example, the text ``"Welcome to my site."`` is marked as a translation
80 80
 string::
81 81
 
82 82
     from django.utils.translation import ugettext as _
  83
+    from django.http import HttpResponse
83 84
 
84 85
     def my_view(request):
85 86
         output = _("Welcome to my site.")
@@ -89,6 +90,7 @@ Obviously, you could code this without using the alias. This example is
89 90
 identical to the previous one::
90 91
 
91 92
     from django.utils.translation import ugettext
  93
+    from django.http import HttpResponse
92 94
 
93 95
     def my_view(request):
94 96
         output = ugettext("Welcome to my site.")
@@ -192,6 +194,7 @@ of its value.)
192 194
 For example::
193 195
 
194 196
     from django.utils.translation import ungettext
  197
+    from django.http import HttpResponse
195 198
 
196 199
     def hello_world(request, count):
197 200
         page = ungettext(
@@ -208,6 +211,7 @@ languages as the ``count`` variable.
208 211
 Lets see a slightly more complex usage example::
209 212
 
210 213
     from django.utils.translation import ungettext
  214
+    from myapp.models import Report
211 215
 
212 216
     count = Report.objects.count()
213 217
     if count == 1:
@@ -283,6 +287,7 @@ For example::
283 287
 
284 288
 or::
285 289
 
  290
+    from django.db import models
286 291
     from django.utils.translation import pgettext_lazy
287 292
 
288 293
     class MyThing(models.Model):
@@ -328,6 +333,7 @@ Model fields and relationships ``verbose_name`` and ``help_text`` option values
328 333
 For example, to translate the help text of the *name* field in the following
329 334
 model, do the following::
330 335
 
  336
+    from django.db import models
331 337
     from django.utils.translation import ugettext_lazy as _
332 338
 
333 339
     class MyThing(models.Model):
@@ -336,8 +342,6 @@ model, do the following::
336 342
 You can mark names of ``ForeignKey``, ``ManyTomanyField`` or ``OneToOneField``
337 343
 relationship as translatable by using their ``verbose_name`` options::
338 344
 
339  
-    from django.utils.translation import ugettext_lazy as _
340  
-
341 345
     class MyThing(models.Model):
342 346
         kind = models.ForeignKey(ThingKind, related_name='kinds',
343 347
                                  verbose_name=_('kind'))
@@ -355,6 +359,7 @@ It is recommended to always provide explicit
355 359
 relying on the fallback English-centric and somewhat naïve determination of
356 360
 verbose names Django performs by looking at the model's class name::
357 361
 
  362
+    from django.db import models
358 363
     from django.utils.translation import ugettext_lazy as _
359 364
 
360 365
     class MyThing(models.Model):
@@ -370,6 +375,7 @@ Model methods ``short_description`` attribute values
370 375
 For model methods, you can provide translations to Django and the admin site
371 376
 with the ``short_description`` attribute::
372 377
 
  378
+    from django.db import models
373 379
     from django.utils.translation import ugettext_lazy as _
374 380
 
375 381
     class MyThing(models.Model):
@@ -404,6 +410,7 @@ If you ever see output that looks like ``"hello
404 410
 If you don't like the long ``ugettext_lazy`` name, you can just alias it as
405 411
 ``_`` (underscore), like so::
406 412
 
  413
+    from django.db import models
407 414
     from django.utils.translation import ugettext_lazy as _
408 415
 
409 416
     class MyThing(models.Model):
@@ -429,6 +436,9 @@ definition. Therefore, you are authorized to pass a key name instead of an
429 436
 integer as the ``number`` argument. Then ``number`` will be looked up in the
430 437
 dictionary under that key during string interpolation. Here's example::
431 438
 
  439
+    from django import forms
  440
+    from django.utils.translation import ugettext_lazy
  441
+
432 442
     class MyForm(forms.Form):
433 443
         error_message = ungettext_lazy("You only provided %(num)d argument",
434 444
             "You only provided %(num)d arguments", 'num')
@@ -461,6 +471,7 @@ that concatenates its contents *and* converts them to strings only when the
461 471
 result is included in a string. For example::
462 472
 
463 473
     from django.utils.translation import string_concat
  474
+    from django.utils.translation import ugettext_lazy
464 475
     ...
465 476
     name = ugettext_lazy('John Lennon')
466 477
     instrument = ugettext_lazy('guitar')
@@ -1663,6 +1674,8 @@ preference available as ``request.LANGUAGE_CODE`` for each
1663 1674
 :class:`~django.http.HttpRequest`. Feel free to read this value in your view
1664 1675
 code. Here's a simple example::
1665 1676
 
  1677
+    from django.http import HttpResponse
  1678
+
1666 1679
     def hello_world(request, count):
1667 1680
         if request.LANGUAGE_CODE == 'de-at':
1668 1681
             return HttpResponse("You prefer to read Austrian German.")

0 notes on commit 1d54394

Please sign in to comment.
Something went wrong with that request. Please try again.