Skip to content

Commit

Permalink
Merge pull request #59 from SELab-2/i18n-api
Browse files Browse the repository at this point in the history
I18n api
  • Loading branch information
EwoutV authored Mar 13, 2024
2 parents 4d7f6da + 2b0b035 commit 1866e37
Show file tree
Hide file tree
Showing 15 changed files with 425 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/backend-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ jobs:
python -m pip install --upgrade pip
pip install flake8
pip install -r ./backend/requirements.txt
- name: Compile translations
run: django-admin compilemessages
- name: Execute tests
run: cd backend; python manage.py test
148 changes: 148 additions & 0 deletions backend/api/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# 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 <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-13 23:12+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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"

#: helpers/check_folder_structure.py:141
msgid "zip.errors.invalid_structure.blocked_extension_found"
msgstr "The submitted zip file contains a file with a non-allowed extension."

#: helpers/check_folder_structure.py:145 helpers/check_folder_structure.py:196
msgid "zip.success"
msgstr "The submitted zip file succeeds in all checks."

#: helpers/check_folder_structure.py:148
msgid "zip.errors.invalid_structure.obligated_extension_not_found"
msgstr ""
"The submitted zip file doesn't have any file with a certain file extension "
"that's obligated."

#: helpers/check_folder_structure.py:175
msgid "zip.errors.invalid_structure.directory_not_defined"
msgstr "An obligated directory was not found in the submitted zip file."

#: helpers/check_folder_structure.py:195
msgid "zip.errors.invalid_structure.directory_not_found_in_template"
msgstr ""
"There was a directory found in the submitted zip file, which was not asked "
"for."

#: serializers/course_serializer.py:58 serializers/course_serializer.py:77
msgid "courses.error.context"
msgstr "The course is not supplied in the context."

#: serializers/course_serializer.py:64 tests/test_locale.py:28
#: tests/test_locale.py:38
msgid "courses.error.students.already_present"
msgstr "The student is already present in the course."

#: serializers/course_serializer.py:68 serializers/course_serializer.py:87
msgid "courses.error.students.past_course"
msgstr "The course is from a past year, thus cannot be manipulated."

#: serializers/course_serializer.py:83
msgid "courses.error.students.not_present"
msgstr "The student is not present in the course."

#: serializers/group_serializer.py:47
msgid "group.errors.score_exceeds_max"
msgstr "The score exceeds the group's max score."

#: serializers/group_serializer.py:57 serializers/group_serializer.py:87
msgid "group.error.context"
msgstr "The group is not supplied in the context."

#: serializers/group_serializer.py:65 serializers/group_serializer.py:99
msgid "group.errors.locked"
msgstr "The group is currently locked."

#: serializers/group_serializer.py:69
msgid "group.errors.full"
msgstr "The group is already full."

#: serializers/group_serializer.py:73
msgid "group.errors.not_in_course"
msgstr "The student is not present in the related course."

#: serializers/group_serializer.py:77
msgid "group.errors.already_in_group"
msgstr "The student is already in the group."

#: serializers/group_serializer.py:95
msgid "group.errors.not_present"
msgstr "The student is currently not in the group."

#: serializers/project_serializer.py:56
msgid "project.errors.context"
msgstr "The project is not supplied in the context."

#: serializers/project_serializer.py:60
msgid "project.errors.start_date_in_past"
msgstr "The start date of the project lies in the past."

#: serializers/project_serializer.py:64
msgid "project.errors.deadline_before_start_date"
msgstr "The deadline of the project lies before the start date of the project."

#: serializers/project_serializer.py:89
msgid "project.error.submissions.past_project"
msgstr "The deadline of the project has already passed."

#: serializers/project_serializer.py:92
msgid "project.error.submissions.non_visible_project"
msgstr "The project is currently in a non-visible state."

#: serializers/project_serializer.py:95
msgid "project.error.submissions.archived_project"
msgstr "The project is archived."

#: views/course_view.py:58
msgid "courses.success.assistants.add"
msgstr "The assistant was successfully added to the course."

#: views/course_view.py:77
msgid "courses.success.assistants.remove"
msgstr "The assistant was successfully removed from the course."

#: views/course_view.py:111
msgid "courses.success.students.add"
msgstr "The student was successfully added to the course."

#: views/course_view.py:131
msgid "courses.success.students.remove"
msgstr "The student was successfully removed from the course."

#: views/course_view.py:186
msgid "course.success.project.add"
msgstr "The project was successfully added to the course."

#: views/group_view.py:73
msgid "group.success.students.add"
msgstr "The student was successfully added to the group."

#: views/group_view.py:92
msgid "group.success.students.remove"
msgstr "The student was successfully removed from the group."

#: views/group_view.py:111
msgid "group.success.submissions.add"
msgstr "The submission was successfully added to the group."

#: views/project_view.py:80
msgid "project.success.groups.created"
msgstr "A group was successfully created for the project."
149 changes: 149 additions & 0 deletions backend/api/locale/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# 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 <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-13 23:07+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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"

#: helpers/check_folder_structure.py:141
msgid "zip.errors.invalid_structure.blocked_extension_found"
msgstr ""
"Bestanden met een verboden extensie zijn gevonden in het ingediende zip-"
"bestand."

#: helpers/check_folder_structure.py:145 helpers/check_folder_structure.py:196
msgid "zip.success"
msgstr "Het zip-bestand van de indiening bevat alle benodigde bestanden."

#: helpers/check_folder_structure.py:148
msgid "zip.errors.invalid_structure.obligated_extension_not_found"
msgstr ""
"Er is geen enkel bestand met een bepaalde extensie die verplicht is in het "
"ingediende zip-bestand."

#: helpers/check_folder_structure.py:175
msgid "zip.errors.invalid_structure.directory_not_defined"
msgstr "Een verplichte map is niet aanwezig in het ingediende zip-bestand."

#: helpers/check_folder_structure.py:195
msgid "zip.errors.invalid_structure.directory_not_found_in_template"
msgstr "Het ingediende zip-bestand bevat een map die niet gevraagd is."

#: serializers/course_serializer.py:58 serializers/course_serializer.py:77
msgid "courses.error.context"
msgstr "De opleiding is niet meegeleverd als context."

#: serializers/course_serializer.py:64 tests/test_locale.py:28
#: tests/test_locale.py:38
msgid "courses.error.students.already_present"
msgstr "De student bevindt zich al in de opleiding."

#: serializers/course_serializer.py:68 serializers/course_serializer.py:87
msgid "courses.error.students.past_course"
msgstr "De opleiding die men probeert te manipuleren is van een vorig jaar."

#: serializers/course_serializer.py:83
msgid "courses.error.students.not_present"
msgstr "De student bevindt zich niet in de opleiding."

#: serializers/group_serializer.py:47
msgid "group.errors.score_exceeds_max"
msgstr "De score van de groep is groter dan de maximum score."

#: serializers/group_serializer.py:57 serializers/group_serializer.py:87
msgid "group.error.context"
msgstr "De groep is niet meegegeven als context waar dat nodig is."

#: serializers/group_serializer.py:65 serializers/group_serializer.py:99
msgid "group.errors.locked"
msgstr "De groep is momenteel vergrendeld."

#: serializers/group_serializer.py:69
msgid "group.errors.full"
msgstr "De groep is al vol."

#: serializers/group_serializer.py:73
msgid "group.errors.not_in_course"
msgstr ""
"De student bevindt zich niet in de opleiding waartoe het project hoort."

#: serializers/group_serializer.py:77
msgid "group.errors.already_in_group"
msgstr "De student bevindt zich al in de groep."

#: serializers/group_serializer.py:95
msgid "group.errors.not_present"
msgstr "De student bevindt zich niet in de groep."

#: serializers/project_serializer.py:56
msgid "project.errors.context"
msgstr "Het project is niet meegegeven als context waar dat nodig is."

#: serializers/project_serializer.py:60
msgid "project.errors.start_date_in_past"
msgstr "De startdatum van het project ligt in het verleden."

#: serializers/project_serializer.py:64
msgid "project.errors.deadline_before_start_date"
msgstr "De uiterste inleverdatum voor het project ligt voor de startdatum."

#: serializers/project_serializer.py:89
msgid "project.error.submissions.past_project"
msgstr "De uiterste inleverdatum voor het project is gepasseerd."

#: serializers/project_serializer.py:92
msgid "project.error.submissions.non_visible_project"
msgstr "Het project is niet zichtbaar."

#: serializers/project_serializer.py:95
msgid "project.error.submissions.archived_project"
msgstr "Het project is gearchiveerd."

#: views/course_view.py:58
msgid "courses.success.assistants.add"
msgstr "De assistent is succesvol toegevoegd aan de opleiding."

#: views/course_view.py:77
msgid "courses.success.assistants.remove"
msgstr "De assistent is succesvol verwijderd uit de opleiding."

#: views/course_view.py:111
msgid "courses.success.students.add"
msgstr "De student is succesvol toegevoegd aan de opleiding."

#: views/course_view.py:131
msgid "courses.success.students.remove"
msgstr "De student is succesvol verwijderd uit de opleiding."

#: views/course_view.py:186
msgid "course.success.project.add"
msgstr "Het project is succesvol toegevoegd aan de opleiding."

#: views/group_view.py:73
msgid "group.success.students.add"
msgstr "De student is succesvol toegevoegd aan de groep."

#: views/group_view.py:92
msgid "group.success.students.remove"
msgstr "De student is succesvol verwijderd uit de groep."

#: views/group_view.py:111
msgid "group.success.submissions.add"
msgstr "De indiening is succesvol toegevoegd aan de groep."

#: views/project_view.py:80
msgid "project.success.groups.created"
msgstr "De groep is succesvol toegevoegd aan het project."
3 changes: 3 additions & 0 deletions backend/api/models/checks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from api.models.project import Project
from api.models.extension import FileExtension

Expand Down Expand Up @@ -38,6 +39,8 @@ class StructureCheck(models.Model):
blank=True
)

# ID check should be generated automatically


class ExtraCheck(models.Model):
"""Model that represents an extra check for a project.
Expand Down
6 changes: 3 additions & 3 deletions backend/api/serializers/project_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ def validate(self, data):

# Check if the project's deadline is not passed.
if project.deadline_passed():
raise ValidationError(gettext("project.error.submission.past_project"))
raise ValidationError(gettext("project.error.submissions.past_project"))

if not project.is_visible():
raise ValidationError(gettext("project.error.submission.non_visible_project"))
raise ValidationError(gettext("project.error.submissions.non_visible_project"))

if project.is_archived():
raise ValidationError(gettext("project.error.submission.archived_project"))
raise ValidationError(gettext("project.error.submissions.archived_project"))

return data
3 changes: 1 addition & 2 deletions backend/api/tests/test_file_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,4 @@ def test_your_checking(self):
obligated=[fileExtensionTS, fileExtensionTSX],
blocked=[])

succes = (True, 'zip.success')
self.assertEqual(check_zip_file(project=project, dir_path="structures/zip_struct1.zip"), succes)
self.assertTrue(check_zip_file(project=project, dir_path="structures/zip_struct1.zip")[0])
38 changes: 38 additions & 0 deletions backend/api/tests/test_locale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import json
from django.urls import reverse
from django.utils.translation import activate
from django.utils.translation import gettext as _
from rest_framework.test import APITestCase

from api.models.course import Course
from api.models.student import Student
from authentication.models import User


class TestLocaleAddAlreadyPresentStudentToCourse(APITestCase):
def setUp(self) -> None:
self.client.force_authenticate(User.get_dummy_admin())

course = Course.objects.create(id=1, name="Test Course", academic_startyear=2024)
student = Student.objects.create(id=1, first_name="John", last_name="Doe", email="john.doe@example.com")

student.courses.add(course)

def test_default_locale(self):
response = self.client.post(reverse("course-students", args=["1"]),
{"student_id": 1})

self.assertEqual(response.status_code, 400)
body = json.loads(response.content.decode('utf-8'))
activate("en")
self.assertEqual(body["non_field_errors"][0], _("courses.error.students.already_present"))

def test_nl_locale(self):
response = self.client.post(reverse("course-students", args=["1"]),
{"student_id": 1},
headers={"accept-language": "nl"})

self.assertEqual(response.status_code, 400)
body = json.loads(response.content.decode('utf-8'))
activate("nl")
self.assertEqual(body["non_field_errors"][0], _("courses.error.students.already_present"))
Loading

0 comments on commit 1866e37

Please sign in to comment.