Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
i18n of HTTP status strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed Mar 27, 2015
1 parent f094eb5 commit 9e3de09
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
15 changes: 11 additions & 4 deletions error.spt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@ from __future__ import absolute_import, division, print_function, unicode_litera

from aspen.http import status_strings

from gratipay.utils.i18n import HTTP_ERRORS

[----------------------------------------]

style = ''
msg = status_strings.get(response.code, 'Unknown Error').title()
code = response.code
msg = _(HTTP_ERRORS.get(code, status_strings.get(code, '')))
try:
assert msg
except Exception as e:
website.tell_sentry(e, state)

err = response.body

title = str(response.code)
[----------------------------------------] text/html
{% extends "templates/base.html" %}
{% set title = code %}
{% block content %}
<p>{{ msg }}</p>
<pre>{{ err }}</pre>
{% endblock %}
[----------------------------------------] application/json via json_dump
{ "error_code": response.code
{ "error_code": code
, "error_message_short": msg
, "error_message_long": err
}
Expand Down
11 changes: 11 additions & 0 deletions gratipay/utils/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ def make_sorted_dict(keys, d):
))


_ = lambda a: a
HTTP_ERRORS = {
403: _("Forbidden"),
404: _("Not Found"),
429: _("Too Many Requests"),
500: _("Internal Server Error"),
502: _("Upstream Error"),
}
del _


ternary_re = re.compile(r'^\(? *(.+?) *\? *(.+?) *: *(.+?) *\)?$')
and_re = re.compile(r' *&& *')
or_re = re.compile(r' *\|\| *')
Expand Down

0 comments on commit 9e3de09

Please sign in to comment.