1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-25 06:22:22 +00:00

Translate messages from websockets

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2023-03-25 08:09:42 +01:00
parent 942c96dbfa
commit e95d511017
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 9 additions and 1 deletions

View File

@ -6,6 +6,7 @@ from random import randint
from asgiref.sync import sync_to_async
from channels.generic.websocket import AsyncJsonWebsocketConsumer
from django.conf import settings
from django.utils import translation
from django.utils.translation import gettext_lazy as _
from draw.models import Draw, Round, Pool, TeamDraw
@ -70,6 +71,8 @@ class DrawConsumer(AsyncJsonWebsocketConsumer):
.prefetch_related('draw__current_round__current_pool__current_team').aget()
match content['type']:
case 'set_language':
translation.activate(content['language'])
case 'start_draw':
await self.start_draw(**content)
case 'abort':

View File

@ -515,7 +515,12 @@ document.addEventListener('DOMContentLoaded', () => {
console.error('Chat socket closed unexpectedly')
})
socket.addEventListener('open', e => {})
socket.addEventListener('open', e => {
socket.send(JSON.stringify({
'type': 'set_language',
'language': document.getElementsByName('language')[0].value,
}))
})
let format_form = document.getElementById('format-form-' + tournament.id)
if (format_form !== null) {