Skip to content

Commit

Permalink
feat(backend): Translate API error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
barnslig committed Dec 30, 2021
1 parent 2a89eb9 commit d17239e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
18 changes: 17 additions & 1 deletion backend/dpt_app/trails/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-12-25 19:24+0000\n"
"POT-Creation-Date: 2021-12-30 14:38+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -229,3 +229,19 @@ msgstr "Spiel-Aktion"
#, python-brace-format
msgid "Action: {0}"
msgstr "Spiel-Aktion: {0}"

#: trails/views.py:56
msgid "Unknown Game ID"
msgstr "Unbekannter Spiel-Code!"

#: trails/views.py:74 trails/views.py:177
msgid "Missing or malformed bearer"
msgstr "Fehler bei der Authentifizierung!"

#: trails/views.py:161
msgid "Unknown QR code ID"
msgstr "Unbekannter QR-Code!"

#: trails/views.py:220
msgid "This QR code is already used"
msgstr "Der QR-Code wurde bereits verwendet!"
32 changes: 17 additions & 15 deletions backend/dpt_app/trails/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import time
from django.http import HttpResponse, JsonResponse
from django.utils.translation import gettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
import time

from .enums import ClockType, ActionType
from .models import Game, Log, Parameter, Player, Character
from .qr_models import Code
from .enums import ClockType, ParameterType, ActionType, CharacterType

# TODO: For production, protect this variable with a mutex
# or move it into the DB
Expand Down Expand Up @@ -51,7 +53,7 @@ def inner(request, gameId, *args, **kwargs):
{
"id": "game-not-found",
"status": 404,
"title": "Unknown Game ID"
"title": _("Unknown Game ID")
}
]}, status=404)
return func(request, game, *args, **kwargs)
Expand All @@ -69,7 +71,7 @@ def inner(request, game, *args, **kwargs):
{
"id": "not-authorised",
"status": 403,
"title": "Missing or malformed bearer"
"title": _("Missing or malformed bearer")
}
]}, status=403)
return inner
Expand Down Expand Up @@ -151,7 +153,7 @@ def has_valid_bearer(bearer, game):
{
"id": "code-not-found",
"status": 404,
"title": "Unknown QR code ID"
"title": _("Unknown QR code ID")
}
]}, status=404)

Expand All @@ -164,12 +166,12 @@ def has_valid_bearer(bearer, game):
if has_valid_bearer(bearer, game) or is_onboarding(code):
return func_code_post(game, code, bearer)
return JsonResponse({"errors": [
{
"id": "not-authorised",
"status": 403,
"title": "Missing or malformed bearer"
}
]}, status=403)
{
"id": "not-authorised",
"status": 403,
"title": _("Missing or malformed bearer")
}
]}, status=403)


def func_code_get(game, code):
Expand Down Expand Up @@ -208,11 +210,11 @@ def func_code_post(game, code, bearer):
if code.one_shot is True and game.logs.filter(id=code.id).exists():
return JsonResponse({"errors": [
{
"id": "already-used",
"status": 403,
"title": "This QR code is already used"
"id": "already-used",
"status": 403,
"title": _("This QR code is already used")
}
]}, status=403)
]}, status=403)

for action in code.actions.all():
if action.action_type == ActionType.PARAMETER:
Expand Down

0 comments on commit d17239e

Please sign in to comment.