From 8f012352d4c728a09442394a9e878d5f17bb0e54 Mon Sep 17 00:00:00 2001 From: Brandon <103316367+okbrandon@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:35:03 +0100 Subject: [PATCH] translations: Fixed Chat & Tournament contexts translations --- frontend/public/locales/EN/translation.json | 15 ++++++++++++++- frontend/public/locales/ES/translation.json | 15 ++++++++++++++- frontend/public/locales/FR/translation.json | 15 ++++++++++++++- frontend/src/context/ChatContext.js | 18 ++++++++++-------- frontend/src/context/TournamentContext.js | 6 ++++-- 5 files changed, 56 insertions(+), 13 deletions(-) diff --git a/frontend/public/locales/EN/translation.json b/frontend/public/locales/EN/translation.json index 21bc9b03..8977fe77 100644 --- a/frontend/public/locales/EN/translation.json +++ b/frontend/public/locales/EN/translation.json @@ -415,6 +415,18 @@ "confirmModal": { "cancelButton": "Cancel", "confirmButton": "Confirm" + }, + "notifications": { + "messageReceived": "{{username}} sent you a message.", + "friendRequest": { + "received": "{{username}} sent you a friend request.", + "accepted": "{{username}} accepted your friend request.", + "declined": "{{username}} declined your friend request." + }, + "challenge": { + "accepted": "{{username}} denied your challenge.", + "declined": "{{username}} accepted your challenge." + } } }, "game": { @@ -532,7 +544,8 @@ "noPlayer": "N/A" } }, - "leaveMessage": "Due to you leaving, you've been removed from the tournament" + "leaveMessage": "Due to you leaving, you've been removed from the tournament", + "reconnectMessage": "Reconnecting to the server. Please wait..." }, "leave": { "title": "Press <0>Q to quit the game", diff --git a/frontend/public/locales/ES/translation.json b/frontend/public/locales/ES/translation.json index 74d06558..d240204c 100644 --- a/frontend/public/locales/ES/translation.json +++ b/frontend/public/locales/ES/translation.json @@ -415,6 +415,18 @@ "confirmModal": { "cancelButton": "Cancelar", "confirmButton": "Confirmar" + }, + "notifications": { + "messageReceived": "{{username}} te envió un mensaje.", + "friendRequest": { + "received": "{{username}} te envió una solicitud de amistad.", + "accepted": "{{username}} aceptó tu solicitud de amistad.", + "declined": "{{username}} rechazó tu solicitud de amistad." + }, + "challenge": { + "accepted": "{{username}} aceptó tu desafío.", + "declined": "{{username}} rechazó tu desafío." + } } }, "game": { @@ -532,7 +544,8 @@ "noPlayer": "N/A" } }, - "leaveMessage": "Debido a que te has ido, has sido eliminado del torneo" + "leaveMessage": "Debido a que te has ido, has sido eliminado del torneo", + "reconnectMessage": "Reconectando al servidor. Por favor espera..." }, "leave": { "title": "Presiona <0>Q para salir del juego", diff --git a/frontend/public/locales/FR/translation.json b/frontend/public/locales/FR/translation.json index 04357dac..052cf3d9 100644 --- a/frontend/public/locales/FR/translation.json +++ b/frontend/public/locales/FR/translation.json @@ -415,6 +415,18 @@ "confirmModal": { "cancelButton": "Annuler", "confirmButton": "Confirmer" + }, + "notifications": { + "messageReceived": "{{username}} vous a envoyé un message.", + "friendRequest": { + "received": "{{username}} vous a envoyé une demande d'ami.", + "accepted": "{{username}} a accepté votre demande d'ami.", + "declined": "{{username}} a refusé votre demande d'ami." + }, + "challenge": { + "accepted": "{{username}} a accepté votre défi.", + "declined": "{{username}} a refusé votre défi." + } } }, "game": { @@ -532,7 +544,8 @@ "noPlayer": "N/A" } }, - "leaveMessage": "En raison de votre départ, vous avez été retiré du tournoi" + "leaveMessage": "En raison de votre départ, vous avez été retiré du tournoi", + "reconnectMessage": "Reconnexion au serveur. Veuillez patienter..." }, "leave": { "title": "Appuyez sur <0>Q pour quitter le jeu", diff --git a/frontend/src/context/ChatContext.js b/frontend/src/context/ChatContext.js index d4078206..1fd0b23d 100644 --- a/frontend/src/context/ChatContext.js +++ b/frontend/src/context/ChatContext.js @@ -5,6 +5,7 @@ import { useNotification } from './NotificationContext'; import { useRelation } from './RelationContext'; import { useNavigate } from 'react-router-dom'; import refreshToken from '../api/token'; +import { useTranslation } from 'react-i18next'; const WS_CHAT_URL = process.env.REACT_APP_ENV === 'production' ? '/ws/chat/?token=' : 'ws://localhost:8000/ws/chat/?token='; @@ -18,6 +19,7 @@ export const ChatProvider = ({ children }) => { const [conversations, setConversations] = useState([]); const [unreadCounts, setUnreadCounts] = useState({}); const [sendNotification, setSendNotification] = useState(null); + const { t } = useTranslation(); // State for managing direct messages const [directMessage, setDirectMessage] = useState({ @@ -102,10 +104,10 @@ export const ChatProvider = ({ children }) => { useEffect(() => { if (sendNotification) { - addNotification('info', `${sendNotification} sent you a message.`); + addNotification('info', t('chat.notifications.messageReceived', { username: `${sendNotification}` })); setSendNotification(null); } - }, [sendNotification, addNotification]); + }, [sendNotification, addNotification, t]); useEffect(() => { const connectWSChat = async () => { @@ -175,11 +177,11 @@ export const ChatProvider = ({ children }) => { }); setIsRefetch(true); if (userFrom.status === 'pending') { - addNotification('info', `You have a friend request from ${userFrom.displayName}.`); + addNotification('info', t('chat.notifications.friendRequest.received', { username: `${userFrom.displayName}` })); } else if (userFrom.status === 'rejected') { - addNotification('info', `${userTo.displayName} rejected your friend request.`); + addNotification('info', t('chat.notifications.friendRequest.declined', { username: `${userTo.displayName}` })); } else if (userFrom.status === 'accepted') { - addNotification('info', `${userTo.displayName} accepted your friend request.`); + addNotification('info', t('chat.notifications.friendRequest.accepted', { username: `${userTo.displayName}` })); }; } else if (response.type === 'challenge_update') { const formattedData = { @@ -189,9 +191,9 @@ export const ChatProvider = ({ children }) => { } if (formattedData.invite.status === 'DECLINED') { - addNotification('info', `${formattedData.invite.invitee.displayName} denied your challenge.`); + addNotification('info', t('chat.notifications.challenge.accepted', { username: `${formattedData.invite.invitee.displayName}` })); } else if (formattedData.invite.status === 'ACCEPTED') { - addNotification('info', `${formattedData.invite.invitee.displayName} accepted your challenge.`); + addNotification('info', t('chat.notifications.challenge.declined', { username: `${formattedData.invite.invitee.displayName}` })); navigate('/game-challenge'); } } @@ -221,7 +223,7 @@ export const ChatProvider = ({ children }) => { console.log('WebSocket for Chat closed'); } }; - }, [addNotification, setIsRefetch, navigate]); + }, [addNotification, setIsRefetch, navigate, t]); const contextValue = useMemo(() => ({ conversations, diff --git a/frontend/src/context/TournamentContext.js b/frontend/src/context/TournamentContext.js index 59912c4e..022e01ff 100644 --- a/frontend/src/context/TournamentContext.js +++ b/frontend/src/context/TournamentContext.js @@ -4,6 +4,7 @@ import { useAuth } from "./AuthContext"; import { formatUserData } from "../api/user"; import refreshToken from "../api/token"; import { useNotification } from "./NotificationContext"; +import { useTranslation } from "react-i18next"; const WS_TOURNAMENT_URL = process.env.REACT_APP_ENV === 'production' ? '/ws/tournaments' : 'ws://localhost:8000/ws/tournaments'; @@ -20,6 +21,7 @@ const TournamentProvider = ({ children }) => { const [resetMatch, setResetMatch] = useState(null); const userIDRef = useRef(null); const heartbeatIntervalRef = useRef(null); + const { t } = useTranslation(); const sendMessage = useCallback((message) => { if (socketTournament.current && socketTournament.current.readyState === WebSocket.OPEN) { @@ -183,7 +185,7 @@ const TournamentProvider = ({ children }) => { const newToken = await refreshToken(); if (newToken) { connectWSTournament(); - addNotification('info', 'Reconnecting to the server...'); + addNotification('info', t('game.tournaments.reconnectMessage')); } else { console.log('WebSocket for Tournaments failed to refresh the token'); } @@ -200,7 +202,7 @@ const TournamentProvider = ({ children }) => { console.log('WebSocket for Tournaments closed'); } }; - }, [identify, heartbeat, navigate, updateTournament, addNotification]); + }, [identify, heartbeat, navigate, updateTournament, addNotification, t]); return (