diff --git a/.gitignore b/.gitignore index 17ded36..0b9eec4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ db.sqlite3 **/migrations/** /profiles/static/avatars/* !/profiles/static/avatars/default.env +*.mo diff --git a/accounts/locale/fr/LC_MESSAGES/django.po b/accounts/locale/fr/LC_MESSAGES/django.po new file mode 100644 index 0000000..eed9cf2 --- /dev/null +++ b/accounts/locale/fr/LC_MESSAGES/django.po @@ -0,0 +1,22 @@ +# 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-02-01 13:59+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" +#: views/login.py:22 +msgid "Invalid username or password." +msgstr "Nom d'utilisateur ou mot de passe incorect." diff --git a/accounts/views/login.py b/accounts/views/login.py index afcc03d..de5181f 100644 --- a/accounts/views/login.py +++ b/accounts/views/login.py @@ -4,6 +4,7 @@ from rest_framework import permissions, status from django.http import HttpRequest from django.contrib.auth import login from rest_framework.authentication import SessionAuthentication +from django.utils.translation import gettext as _ from ..serializers.login import LoginSerializer @@ -18,6 +19,6 @@ class LoginView(APIView): serializer.is_valid(raise_exception=True) user = serializer.get_user(data) if user is None: - return Response({'login': ['Invalid username or password.']}, status.HTTP_401_UNAUTHORIZED) + return Response({'login': [_('Invalid username or password.')]}, status.HTTP_401_UNAUTHORIZED) login(request, user) return Response({'id': user.pk}, status=status.HTTP_200_OK) diff --git a/frontend/static/js/index.js b/frontend/static/js/index.js index 0c505cc..a3111d2 100644 --- a/frontend/static/js/index.js +++ b/frontend/static/js/index.js @@ -20,6 +20,7 @@ import TournamentsView from "./views/tournament/TournamentsListView.js"; import TournamentCreateView from "./views/tournament/TournamentCreateView.js"; let client = new Client(location.origin); +let lang = client.lang; let lastView = undefined; let lastPageUrlBeforeLogin = undefined; @@ -144,13 +145,13 @@ document.addEventListener("DOMContentLoaded", async () => { //Languages Array.from(document.getElementById('languageSelector').children).forEach(el => { el.onclick = async _ => { - if (await client.lang.changeLanguage(el.value)) + if (await lang.changeLanguage(el.value)) return; document.querySelector('#languageSelector > .active')?.classList.remove('active'); el.classList.add('active'); }; }); - document.querySelector(`#languageSelector > [value=${client.lang.chosenLang}]`) + document.querySelector(`#languageSelector > [value=${lang.chosenLang}]`) ?.classList.add('active'); await client.isAuthentificate(); @@ -158,4 +159,4 @@ document.addEventListener("DOMContentLoaded", async () => { document.querySelector('a[href=\'' + location.pathname + '\']')?.classList.add('active'); }); -export { client, navigateTo, reloadView } +export { client, lang, navigateTo, reloadView } diff --git a/frontend/static/js/lang/en.json b/frontend/static/js/lang/en.json index 8fc8946..0ea3a84 100644 --- a/frontend/static/js/lang/en.json +++ b/frontend/static/js/lang/en.json @@ -11,5 +11,13 @@ "homeOnline": "Play online", "homeOffline": "Play offline", "homeMe": "Me", - "homeLogout": "Logout" + "homeLogout": "Logout", + "loginWindowTitle": "Login", + "loginFormTitle": "Login", + "loginFormUsername": "Username", + "loginFormPassword": "Password", + "loginFormButton": "Login", + "loginNoAccount": "No account yet?", + "loginRegister": "Register", + "errorEmptyField": "This field may not be blank." } diff --git a/frontend/static/js/lang/fr.json b/frontend/static/js/lang/fr.json index a879558..3fb8fa3 100644 --- a/frontend/static/js/lang/fr.json +++ b/frontend/static/js/lang/fr.json @@ -11,5 +11,13 @@ "homeOnline": "Jouer en ligne", "homeOffline": "Jouer hors ligne", "homeMe": "Moi", - "homeLogout": "Déconnexion" + "homeLogout": "Déconnexion", + "loginWindowTitle": "Connexion", + "loginFormTitle": "Connexion", + "loginFormUsername": "Nom d'utilisateur", + "loginFormPassword": "Mot de passe", + "loginFormButton": "Connexion", + "loginNoAccount": "Pas de compte?", + "loginRegister": "S'inscrire", + "errorEmptyField": "Ce champ ne peut être vide." } diff --git a/frontend/static/js/views/HomeView.js b/frontend/static/js/views/HomeView.js index a98fd9f..458af60 100644 --- a/frontend/static/js/views/HomeView.js +++ b/frontend/static/js/views/HomeView.js @@ -1,19 +1,19 @@ -import { client } from "../index.js"; +import { lang } from "../index.js"; import AbstractAuthentificateView from "./abstracts/AbstractAuthentifiedView.js"; export default class extends AbstractAuthentificateView { constructor(params) { - super(params, client.lang.get('homeWindowTitle', 'Home')); + super(params, lang.get('homeWindowTitle', 'Home')); this.redirect_url = "/login" } async getHtml() { return /* HTML */ ` -

${client.lang.get('homeTitle', 'Home')}

- ${client.lang.get('homeOnline', 'Play online')} - ${client.lang.get('homeOffline', 'Play offline')} - ${client.lang.get('homeMe', 'Me')} - ${client.lang.get('homeLogout', 'Logout')} +

${lang.get('homeTitle', 'Home')}

+ ${lang.get('homeOnline', 'Play online')} + ${lang.get('homeOffline', 'Play offline')} + ${lang.get('homeMe', 'Me')} + ${lang.get('homeLogout', 'Logout')} `; } } diff --git a/frontend/static/js/views/accounts/LoginView.js b/frontend/static/js/views/accounts/LoginView.js index 6ecc3e1..19595fe 100644 --- a/frontend/static/js/views/accounts/LoginView.js +++ b/frontend/static/js/views/accounts/LoginView.js @@ -1,4 +1,4 @@ -import { client, navigateTo } from "../../index.js"; +import { client, lang, navigateTo } from "../../index.js"; import { clear, fill_errors } from "../../utils/formUtils.js"; import AbstractNonAuthentifiedView from "../abstracts/AbstractNonAuthentified.js"; @@ -10,10 +10,10 @@ async function login(redirectTo = '/home') let password = document.getElementById('passwordInput').value; if (username === '') { - document.getElementById('username').innerHTML = 'This field may not be blank.'; + document.getElementById('username').innerHTML = lang.get('errorEmptyField', 'This field may not be blank.'); } if (password === '') { - document.getElementById('password').innerHTML = 'This field may not be blank.'; + document.getElementById('password').innerHTML = lang.get('errorEmptyField', 'This field may not be blank.'); } if (username === '' || password === '') return; @@ -32,7 +32,7 @@ async function login(redirectTo = '/home') export default class extends AbstractNonAuthentifiedView { constructor(params, lastUrlBeforeLogin = '/home') { - super(params, "Login", lastUrlBeforeLogin); + super(params, lang.get('loginWindowTitle', 'Login'), lastUrlBeforeLogin); this.redirectTo = lastUrlBeforeLogin; } @@ -56,21 +56,21 @@ export default class extends AbstractNonAuthentifiedView { return `
-

Login

+

${lang.get('loginFormTitle', 'Login')}

- +
- +
- + -

No account yet? Register

+

${lang.get('loginNoAccount', 'No account yet?')} ${lang.get('loginRegister', 'Register')}