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
This commit is contained in:
Jannis Leidel 2012-02-04 21:01:11 +00:00
parent a4f68c1b40
commit 170e5d5f74
4 changed files with 22 additions and 15 deletions

View File

@ -2,6 +2,7 @@ from django import http
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site, get_current_site from django.contrib.sites.models import Site, get_current_site
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.utils.translation import ugettext as _
def shortcut(request, content_type_id, object_id): def shortcut(request, content_type_id, object_id):
""" """
@ -11,17 +12,18 @@ def shortcut(request, content_type_id, object_id):
try: try:
content_type = ContentType.objects.get(pk=content_type_id) content_type = ContentType.objects.get(pk=content_type_id)
if not content_type.model_class(): if not content_type.model_class():
raise http.Http404("Content type %s object has no associated model" raise http.Http404(_(u"Content type %(ct_id)s object has no associated model") %
% content_type_id) {'ct_id': content_type_id})
obj = content_type.get_object_for_this_type(pk=object_id) obj = content_type.get_object_for_this_type(pk=object_id)
except (ObjectDoesNotExist, ValueError): except (ObjectDoesNotExist, ValueError):
raise http.Http404("Content type %s object %s doesn't exist" raise http.Http404(_(u"Content type %(ct_id)s object %(obj_id)s doesn't exist") %
% (content_type_id, object_id)) {'ct_id': content_type_id, 'obj_id': object_id})
try: try:
get_absolute_url = obj.get_absolute_url get_absolute_url = obj.get_absolute_url
except AttributeError: except AttributeError:
raise http.Http404("%s objects don't have a get_absolute_url() method" raise http.Http404(_("%(ct_name)s objects don't have a get_absolute_url() method") %
% content_type.name) {'ct_name': content_type.name})
absurl = get_absolute_url() absurl = get_absolute_url()
# Try to figure out the object's domain, so we can do a cross-site redirect # Try to figure out the object's domain, so we can do a cross-site redirect

View File

@ -7,6 +7,7 @@ from django.contrib.gis.db.models.fields import GeometryField
from django.db import connections, DEFAULT_DB_ALIAS from django.db import connections, DEFAULT_DB_ALIAS
from django.db.models import get_model from django.db.models import get_model
from django.utils.encoding import smart_str from django.utils.encoding import smart_str
from django.utils.translation import ugettext as _
from django.contrib.gis.shortcuts import render_to_kml, render_to_kmz from django.contrib.gis.shortcuts import render_to_kml, render_to_kmz
@ -40,7 +41,7 @@ def sitemap(request, sitemaps, section=None):
maps, urls = [], [] maps, urls = [], []
if section is not None: if section is not None:
if section not in sitemaps: if section not in sitemaps:
raise Http404("No sitemap available for section: %r" % section) raise Http404(_(u"No sitemap available for section: %r") % section)
maps.append(sitemaps[section]) maps.append(sitemaps[section])
else: else:
maps = sitemaps.values() maps = sitemaps.values()
@ -54,9 +55,9 @@ def sitemap(request, sitemaps, section=None):
else: else:
urls.extend(site.get_urls(page=page, site=current_site)) urls.extend(site.get_urls(page=page, site=current_site))
except EmptyPage: except EmptyPage:
raise Http404("Page %s empty" % page) raise Http404(_(u"Page %s empty") % page)
except PageNotAnInteger: except PageNotAnInteger:
raise Http404("No page '%s'" % page) raise Http404(_(u"No page '%s'") % page)
xml = smart_str(loader.render_to_string('gis/sitemaps/geo_sitemap.xml', {'urlset': urls})) xml = smart_str(loader.render_to_string('gis/sitemaps/geo_sitemap.xml', {'urlset': urls}))
return HttpResponse(xml, content_type='application/xml') return HttpResponse(xml, content_type='application/xml')

View File

@ -1,9 +1,10 @@
from django.http import Http404 from django.http import Http404
from django.utils.translation import ugettext as _
def feed(request, url, feed_dict=None): def feed(request, url, feed_dict=None):
"""Provided for backwards compatibility.""" """Provided for backwards compatibility."""
if not feed_dict: if not feed_dict:
raise Http404("No feeds are registered.") raise Http404(_(u"No feeds are registered."))
try: try:
slug, param = url.split('/', 1) slug, param = url.split('/', 1)
@ -13,7 +14,7 @@ def feed(request, url, feed_dict=None):
try: try:
f = feed_dict[slug] f = feed_dict[slug]
except KeyError: except KeyError:
raise Http404("Slug %r isn't registered." % slug) raise Http404(_(u"Slug %r isn't registered.") % slug)
instance = f() instance = f()
instance.feed_url = getattr(f, 'feed_url', None) or request.path instance.feed_url = getattr(f, 'feed_url', None) or request.path

View File

@ -14,6 +14,7 @@ import urllib
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseNotModified from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseNotModified
from django.template import loader, Template, Context, TemplateDoesNotExist from django.template import loader, Template, Context, TemplateDoesNotExist
from django.utils.http import http_date, parse_http_date from django.utils.http import http_date, parse_http_date
from django.utils.translation import ugettext as _, ugettext_noop
def serve(request, path, document_root=None, show_indexes=False): def serve(request, path, document_root=None, show_indexes=False):
""" """
@ -48,9 +49,9 @@ def serve(request, path, document_root=None, show_indexes=False):
if os.path.isdir(fullpath): if os.path.isdir(fullpath):
if show_indexes: if show_indexes:
return directory_index(newpath, fullpath) return directory_index(newpath, fullpath)
raise Http404("Directory indexes are not allowed here.") raise Http404(_(u"Directory indexes are not allowed here."))
if not os.path.exists(fullpath): if not os.path.exists(fullpath):
raise Http404('"%s" does not exist' % fullpath) raise Http404(_(u'"%s" does not exist') % fullpath)
# Respect the If-Modified-Since header. # Respect the If-Modified-Since header.
statobj = os.stat(fullpath) statobj = os.stat(fullpath)
mimetype, encoding = mimetypes.guess_type(fullpath) mimetype, encoding = mimetypes.guess_type(fullpath)
@ -69,16 +70,17 @@ def serve(request, path, document_root=None, show_indexes=False):
DEFAULT_DIRECTORY_INDEX_TEMPLATE = """ DEFAULT_DIRECTORY_INDEX_TEMPLATE = """
{% load i18n %}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en-us" /> <meta http-equiv="Content-Language" content="en-us" />
<meta name="robots" content="NONE,NOARCHIVE" /> <meta name="robots" content="NONE,NOARCHIVE" />
<title>Index of {{ directory }}</title> <title>{% blocktrans %}Index of {{ directory }}{% endblocktrans %}</title>
</head> </head>
<body> <body>
<h1>Index of {{ directory }}</h1> <h1>{% blocktrans %}Index of {{ directory }}{% endblocktrans %}</h1>
<ul> <ul>
{% ifnotequal directory "/" %} {% ifnotequal directory "/" %}
<li><a href="../">../</a></li> <li><a href="../">../</a></li>
@ -90,6 +92,7 @@ DEFAULT_DIRECTORY_INDEX_TEMPLATE = """
</body> </body>
</html> </html>
""" """
template_translatable = ugettext_noop(u"Index of %(directory)s")
def directory_index(path, fullpath): def directory_index(path, fullpath):
try: try: