Skip to content

Commit

Permalink
translations: Fixed Chat & Tournament contexts translations
Browse files Browse the repository at this point in the history
  • Loading branch information
okbrandon committed Nov 14, 2024
1 parent 87a1b89 commit 8f01235
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
15 changes: 14 additions & 1 deletion frontend/public/locales/EN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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</0> to quit the game",
Expand Down
15 changes: 14 additions & 1 deletion frontend/public/locales/ES/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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</0> para salir del juego",
Expand Down
15 changes: 14 additions & 1 deletion frontend/public/locales/FR/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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</0> pour quitter le jeu",
Expand Down
18 changes: 10 additions & 8 deletions frontend/src/context/ChatContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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=';

Expand All @@ -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({
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 = {
Expand All @@ -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');
}
}
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/context/TournamentContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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) {
Expand Down Expand Up @@ -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');
}
Expand All @@ -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 (
<TournamentContext.Provider value={{
Expand Down

0 comments on commit 8f01235

Please sign in to comment.