Translate messages from websockets
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
parent
942c96dbfa
commit
e95d511017
|
@ -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':
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue