diff --git a/public/js/vroom.js b/public/js/vroom.js index 24754e3..70c6df0 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -40,6 +40,27 @@ $.ajaxSetup({ dataType: 'json', }); +// Handle lang switch +$('#langSwitch').change(function(){ + $.ajax({ + data: { + action: 'langSwitch', + lang: $('#langSwitch').val() + }, + error: function() { + $.notify(locale.ERROR_OCCURRED, 'error'); + }, + success: function(data){ + if (data.status === 'success'){ + window.location.reload(); + } + else{ + $.notify(locale.ERROR_OCCURED, 'error'); + } + } + }); +}); + // // Define a few functions // diff --git a/public/vroom.pl b/public/vroom.pl index b7b00b2..9fe4cf8 100755 --- a/public/vroom.pl +++ b/public/vroom.pl @@ -1164,6 +1164,16 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub { my $action = $self->param('action'); my $prefix = ($self->stash('action') eq 'admin/action') ? 'admin':'room'; my $room = $self->param('room') || ""; + if ($action eq 'langSwitch'){ + my $new_lang = $self->param('lang') || 'en'; + $self->app->log->debug("switching to lang $new_lang"); + $self->session(language => $new_lang); + return $self->render( + json => { + status => 'success', + } + ); + } # Refuse any action from non members of the room if ($prefix ne 'admin' && (!$self->session('name') || !$self->has_joined($self->session('name'), $room) || !$self->session($room) || !$self->session($room)->{role})){ return $self->render( @@ -1588,6 +1598,13 @@ push @{app->renderer->paths}, '../templates/'.$config->{template}; app->secret($config->{secret}); app->sessions->secure(1); app->sessions->cookie_name('vroom'); +app->hook(before_dispatch => sub { + my $self = shift; + # Switch to the desired language + if ($self->session('language')){ + $self->languages($self->session('language')); + } +}); # And start, lets VROOM !! app->start; diff --git a/templates/default/join.html.ep b/templates/default/join.html.ep index 0bb3f89..c988228 100644 --- a/templates/default/join.html.ep +++ b/templates/default/join.html.ep @@ -253,6 +253,15 @@ +