diff --git a/backend/ypovoli/handlers.py b/backend/ypovoli/handlers.py new file mode 100644 index 00000000..1a027b7a --- /dev/null +++ b/backend/ypovoli/handlers.py @@ -0,0 +1,14 @@ +from rest_framework.views import exception_handler +from django.utils.translation import gettext_lazy as _ + + +def translate_exception_handler(exc, context): + response = exception_handler(exc, context) + + if response.status_code == 401: + response.data['detail'] = _('Given token not valid for any token type') + + if response.status_code == 404: + response.data['detail'] = _('Not found.') + + return response diff --git a/backend/ypovoli/locale/nl/LC_MESSAGES/django.po b/backend/ypovoli/locale/nl/LC_MESSAGES/django.po new file mode 100644 index 00000000..6e497baf --- /dev/null +++ b/backend/ypovoli/locale/nl/LC_MESSAGES/django.po @@ -0,0 +1,35 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-03-07 14:34+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: ypovoli/handlers.py:9 +msgid "Given token not valid for any token type" +msgstr "Gegeven token is niet geldig voor eender welk token type" + +#: ypovoli/handlers.py:12 +msgid "Not found." +msgstr "Niet gevonden." + +#: ypovoli/settings.py:113 +msgid "English" +msgstr "Engels" + +#: ypovoli/settings.py:113 +msgid "Dutch" +msgstr "Nederlands" diff --git a/backend/ypovoli/settings.py b/backend/ypovoli/settings.py index 32355200..c7d3e698 100644 --- a/backend/ypovoli/settings.py +++ b/backend/ypovoli/settings.py @@ -10,6 +10,7 @@ https://docs.djangoproject.com/en/5.0/ref/settings/ """ +from django.utils.translation import gettext_lazy as _ from datetime import timedelta from pathlib import Path @@ -69,7 +70,8 @@ ], 'DEFAULT_PERMISSION_CLASSES': [ 'rest_framework.permissions.IsAuthenticated' - ] + ], + 'EXCEPTION_HANDLERE': 'ypovoli' } SIMPLE_JWT = { @@ -108,6 +110,7 @@ LANGUAGE_CODE = "en-us" TIME_ZONE = "UTC" USE_I18N = True +LANGUAGES = [('en', _('English')), ('nl', _('Dutch'))] USE_L10N = False USE_TZ = True