Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17458 -- Marked Http404 error messages for translation. Thanks…

…, Claude Paroz.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17447 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 170e5d5f7421cc5d6142e1e6b0762392fb68dbb3 1 parent a4f68c1
Jannis Leidel authored February 04, 2012
14  django/contrib/contenttypes/views.py
@@ -2,6 +2,7 @@
2 2
 from django.contrib.contenttypes.models import ContentType
3 3
 from django.contrib.sites.models import Site, get_current_site
4 4
 from django.core.exceptions import ObjectDoesNotExist
  5
+from django.utils.translation import ugettext as _
5 6
 
6 7
 def shortcut(request, content_type_id, object_id):
7 8
     """
@@ -11,17 +12,18 @@ def shortcut(request, content_type_id, object_id):
11 12
     try:
12 13
         content_type = ContentType.objects.get(pk=content_type_id)
13 14
         if not content_type.model_class():
14  
-            raise http.Http404("Content type %s object has no associated model"
15  
-                               % content_type_id)
  15
+            raise http.Http404(_(u"Content type %(ct_id)s object has no associated model") %
  16
+                               {'ct_id': content_type_id})
16 17
         obj = content_type.get_object_for_this_type(pk=object_id)
17 18
     except (ObjectDoesNotExist, ValueError):
18  
-        raise http.Http404("Content type %s object %s doesn't exist"
19  
-                           % (content_type_id, object_id))
  19
+        raise http.Http404(_(u"Content type %(ct_id)s object %(obj_id)s doesn't exist") %
  20
+                           {'ct_id': content_type_id, 'obj_id': object_id})
  21
+
20 22
     try:
21 23
         get_absolute_url = obj.get_absolute_url
22 24
     except AttributeError:
23  
-        raise http.Http404("%s objects don't have a get_absolute_url() method"
24  
-                           % content_type.name)
  25
+        raise http.Http404(_("%(ct_name)s objects don't have a get_absolute_url() method") %
  26
+                           {'ct_name': content_type.name})
25 27
     absurl = get_absolute_url()
26 28
 
27 29
     # Try to figure out the object's domain, so we can do a cross-site redirect
7  django/contrib/gis/sitemaps/views.py
@@ -7,6 +7,7 @@
7 7
 from django.db import connections, DEFAULT_DB_ALIAS
8 8
 from django.db.models import get_model
9 9
 from django.utils.encoding import smart_str
  10
+from django.utils.translation import ugettext as _
10 11
 
11 12
 from django.contrib.gis.shortcuts import render_to_kml, render_to_kmz
12 13
 
@@ -40,7 +41,7 @@ def sitemap(request, sitemaps, section=None):
40 41
     maps, urls = [], []
41 42
     if section is not None:
42 43
         if section not in sitemaps:
43  
-            raise Http404("No sitemap available for section: %r" % section)
  44
+            raise Http404(_(u"No sitemap available for section: %r") % section)
44 45
         maps.append(sitemaps[section])
45 46
     else:
46 47
         maps = sitemaps.values()
@@ -54,9 +55,9 @@ def sitemap(request, sitemaps, section=None):
54 55
             else:
55 56
                 urls.extend(site.get_urls(page=page, site=current_site))
56 57
         except EmptyPage:
57  
-            raise Http404("Page %s empty" % page)
  58
+            raise Http404(_(u"Page %s empty") % page)
58 59
         except PageNotAnInteger:
59  
-            raise Http404("No page '%s'" % page)
  60
+            raise Http404(_(u"No page '%s'") % page)
60 61
     xml = smart_str(loader.render_to_string('gis/sitemaps/geo_sitemap.xml', {'urlset': urls}))
61 62
     return HttpResponse(xml, content_type='application/xml')
62 63
 
5  django/contrib/gis/views.py
... ...
@@ -1,9 +1,10 @@
1 1
 from django.http import Http404
  2
+from django.utils.translation import ugettext as _
2 3
 
3 4
 def feed(request, url, feed_dict=None):
4 5
     """Provided for backwards compatibility."""
5 6
     if not feed_dict:
6  
-        raise Http404("No feeds are registered.")
  7
+        raise Http404(_(u"No feeds are registered."))
7 8
 
8 9
     try:
9 10
         slug, param = url.split('/', 1)
@@ -13,7 +14,7 @@ def feed(request, url, feed_dict=None):
13 14
     try:
14 15
         f = feed_dict[slug]
15 16
     except KeyError:
16  
-        raise Http404("Slug %r isn't registered." % slug)
  17
+        raise Http404(_(u"Slug %r isn't registered.") % slug)
17 18
 
18 19
     instance = f()
19 20
     instance.feed_url = getattr(f, 'feed_url', None) or request.path
11  django/views/static.py
@@ -14,6 +14,7 @@
14 14
 from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseNotModified
15 15
 from django.template import loader, Template, Context, TemplateDoesNotExist
16 16
 from django.utils.http import http_date, parse_http_date
  17
+from django.utils.translation import ugettext as _, ugettext_noop
17 18
 
18 19
 def serve(request, path, document_root=None, show_indexes=False):
19 20
     """
@@ -48,9 +49,9 @@ def serve(request, path, document_root=None, show_indexes=False):
48 49
     if os.path.isdir(fullpath):
49 50
         if show_indexes:
50 51
             return directory_index(newpath, fullpath)
51  
-        raise Http404("Directory indexes are not allowed here.")
  52
+        raise Http404(_(u"Directory indexes are not allowed here."))
52 53
     if not os.path.exists(fullpath):
53  
-        raise Http404('"%s" does not exist' % fullpath)
  54
+        raise Http404(_(u'"%s" does not exist') % fullpath)
54 55
     # Respect the If-Modified-Since header.
55 56
     statobj = os.stat(fullpath)
56 57
     mimetype, encoding = mimetypes.guess_type(fullpath)
@@ -69,16 +70,17 @@ def serve(request, path, document_root=None, show_indexes=False):
69 70
 
70 71
 
71 72
 DEFAULT_DIRECTORY_INDEX_TEMPLATE = """
  73
+{% load i18n %}
72 74
 <!DOCTYPE html>
73 75
 <html lang="en">
74 76
   <head>
75 77
     <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
76 78
     <meta http-equiv="Content-Language" content="en-us" />
77 79
     <meta name="robots" content="NONE,NOARCHIVE" />
78  
-    <title>Index of {{ directory }}</title>
  80
+    <title>{% blocktrans %}Index of {{ directory }}{% endblocktrans %}</title>
79 81
   </head>
80 82
   <body>
81  
-    <h1>Index of {{ directory }}</h1>
  83
+    <h1>{% blocktrans %}Index of {{ directory }}{% endblocktrans %}</h1>
82 84
     <ul>
83 85
       {% ifnotequal directory "/" %}
84 86
       <li><a href="../">../</a></li>
@@ -90,6 +92,7 @@ def serve(request, path, document_root=None, show_indexes=False):
90 92
   </body>
91 93
 </html>
92 94
 """
  95
+template_translatable = ugettext_noop(u"Index of %(directory)s")
93 96
 
94 97
 def directory_index(path, fullpath):
95 98
     try:

0 notes on commit 170e5d5

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