Loading lib/Travelynx.pm +30 −23 Original line number Diff line number Diff line Loading @@ -162,29 +162,7 @@ sub startup { 'before_render' => sub { my ($self) = @_; # TODO load languages from user profile, if set my @languages; if ( $self->is_user_authenticated and @{ $self->current_user->{languages} } ) { @languages = @{ $self->current_user->{languages} }; } elsif ( my $languages = $self->req->headers->accept_language ) { for my $lang ( split( qr{ \s* , \s* }x, $languages ) ) { if ( $lang =~ m{ ^ de }x ) { push( @languages, 'de-DE' ); } elsif ( $lang =~ m{ ^ en }x ) { push( @languages, 'en-GB' ); } } } # de-DE is our fall-back language and thus always appended $self->stash( loc_handle => Travelynx::Helper::Locales->get_handle( @languages, 'de-DE' ) ); $self->stash( loc_handle => $self->loc_handle ); } ); Loading Loading @@ -442,6 +420,33 @@ sub startup { } ); $self->helper( loc_handle => sub { my ($self) = @_; my @languages; if ( $self->is_user_authenticated and @{ $self->current_user->{languages} } ) { @languages = @{ $self->current_user->{languages} }; } elsif ( my $languages = $self->req->headers->accept_language ) { for my $lang ( split( qr{ \s* , \s* }x, $languages ) ) { if ( $lang =~ m{ ^ de }x ) { push( @languages, 'en-GB' ); } elsif ( $lang =~ m{ ^ en }x ) { push( @languages, 'en-GB' ); } } } # de-DE is our fall-back language and thus always appended return Travelynx::Helper::Locales->get_handle( @languages, 'de-DE' ); } ); $self->helper( 'L' => sub { my ( $self, @args ) = @_; Loading Loading @@ -3105,6 +3110,7 @@ sub startup { $authed_r->get('/account/hooks')->to('account#webhook'); $authed_r->get('/account/traewelling')->to('traewelling#settings'); $authed_r->get('/account/insight')->to('account#insight'); $authed_r->get('/account/language')->to('account#change_language'); $authed_r->get('/ajax/status_card.html')->to('traveling#status_card'); $authed_r->get( '/cancelled' => [ format => [ 'html', 'json' ] ] ) ->to( 'traveling#cancelled', format => undef ); Loading Loading @@ -3135,6 +3141,7 @@ sub startup { $authed_r->post('/account/hooks')->to('account#webhook'); $authed_r->post('/account/traewelling')->to('traewelling#settings'); $authed_r->post('/account/insight')->to('account#insight'); $authed_r->post('/account/language')->to('account#change_language'); $authed_r->post('/account/select_backend')->to('account#change_backend'); $authed_r->post('/checkin/add')->to('traveling#add_intransit_form'); $authed_r->post('/journey/add')->to('traveling#add_journey_form'); Loading lib/Travelynx/Controller/Account.pm +29 −0 Original line number Diff line number Diff line Loading @@ -874,6 +874,35 @@ sub webhook { $self->render( 'webhooks', hook => $hook ); } sub change_language { my ($self) = @_; my $action = $self->req->param('action'); my $language = $self->req->param('language'); if ( $action and $action eq 'save' ) { if ( $self->validation->csrf_protect->has_error('csrf_token') ) { $self->render( 'bad_request', csrf => 1, status => 400 ); return; } $self->users->set_language( uid => $self->current_user->{id}, language => $language, ); $self->flash( success => 'language' ); $self->redirect_to('account'); } else { my @languages = @{ $self->current_user->{languages} }; $self->param( language => $languages[0] // q{} ); $self->render('language'); } } sub change_mail { my ($self) = @_; Loading lib/Travelynx/Model/Journeys.pm +2 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,8 @@ sub epoch_to_dt { ); } # TODO turn into a travelynx helper called from templates so that # loc_handle is available for localization sub min_to_human { my ( $self, $minutes ) = @_; Loading lib/Travelynx/Model/Users.pm +8 −0 Original line number Diff line number Diff line Loading @@ -216,6 +216,14 @@ sub set_backend { ); } sub set_language { my ( $self, %opt ) = @_; $opt{db} //= $self->{pg}->db; $opt{db} ->update( 'users', { language => $opt{language} }, { id => $opt{uid} } ); } sub set_privacy { my ( $self, %opt ) = @_; my $db = $opt{db} // $self->{pg}->db; Loading templates/account.html.ep +7 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ % elsif ($success eq 'password') { <span class="card-title">Passwort geändert</span> % } % elsif ($success eq 'language') { <span class="card-title">Sprache geändert</span> % } % elsif ($success eq 'privacy') { <span class="card-title">Einstellungen zu öffentlichen Account-Daten geändert</span> % } Loading Loading @@ -60,6 +63,10 @@ <th scope="row"><%= L('account.password') %></th> <td><a href="/account/password"><i class="material-icons">edit</i></a></td> </tr> <tr> <th scope="row"><%= L('account.language') %></th> <td><a href="/account/language"><i class="material-icons">edit</i></a><%= $acc->{languages}[0] // q{} %></td> </tr> <tr> <th scope="row"><%= L('account.connections') %></th> <td> Loading Loading
lib/Travelynx.pm +30 −23 Original line number Diff line number Diff line Loading @@ -162,29 +162,7 @@ sub startup { 'before_render' => sub { my ($self) = @_; # TODO load languages from user profile, if set my @languages; if ( $self->is_user_authenticated and @{ $self->current_user->{languages} } ) { @languages = @{ $self->current_user->{languages} }; } elsif ( my $languages = $self->req->headers->accept_language ) { for my $lang ( split( qr{ \s* , \s* }x, $languages ) ) { if ( $lang =~ m{ ^ de }x ) { push( @languages, 'de-DE' ); } elsif ( $lang =~ m{ ^ en }x ) { push( @languages, 'en-GB' ); } } } # de-DE is our fall-back language and thus always appended $self->stash( loc_handle => Travelynx::Helper::Locales->get_handle( @languages, 'de-DE' ) ); $self->stash( loc_handle => $self->loc_handle ); } ); Loading Loading @@ -442,6 +420,33 @@ sub startup { } ); $self->helper( loc_handle => sub { my ($self) = @_; my @languages; if ( $self->is_user_authenticated and @{ $self->current_user->{languages} } ) { @languages = @{ $self->current_user->{languages} }; } elsif ( my $languages = $self->req->headers->accept_language ) { for my $lang ( split( qr{ \s* , \s* }x, $languages ) ) { if ( $lang =~ m{ ^ de }x ) { push( @languages, 'en-GB' ); } elsif ( $lang =~ m{ ^ en }x ) { push( @languages, 'en-GB' ); } } } # de-DE is our fall-back language and thus always appended return Travelynx::Helper::Locales->get_handle( @languages, 'de-DE' ); } ); $self->helper( 'L' => sub { my ( $self, @args ) = @_; Loading Loading @@ -3105,6 +3110,7 @@ sub startup { $authed_r->get('/account/hooks')->to('account#webhook'); $authed_r->get('/account/traewelling')->to('traewelling#settings'); $authed_r->get('/account/insight')->to('account#insight'); $authed_r->get('/account/language')->to('account#change_language'); $authed_r->get('/ajax/status_card.html')->to('traveling#status_card'); $authed_r->get( '/cancelled' => [ format => [ 'html', 'json' ] ] ) ->to( 'traveling#cancelled', format => undef ); Loading Loading @@ -3135,6 +3141,7 @@ sub startup { $authed_r->post('/account/hooks')->to('account#webhook'); $authed_r->post('/account/traewelling')->to('traewelling#settings'); $authed_r->post('/account/insight')->to('account#insight'); $authed_r->post('/account/language')->to('account#change_language'); $authed_r->post('/account/select_backend')->to('account#change_backend'); $authed_r->post('/checkin/add')->to('traveling#add_intransit_form'); $authed_r->post('/journey/add')->to('traveling#add_journey_form'); Loading
lib/Travelynx/Controller/Account.pm +29 −0 Original line number Diff line number Diff line Loading @@ -874,6 +874,35 @@ sub webhook { $self->render( 'webhooks', hook => $hook ); } sub change_language { my ($self) = @_; my $action = $self->req->param('action'); my $language = $self->req->param('language'); if ( $action and $action eq 'save' ) { if ( $self->validation->csrf_protect->has_error('csrf_token') ) { $self->render( 'bad_request', csrf => 1, status => 400 ); return; } $self->users->set_language( uid => $self->current_user->{id}, language => $language, ); $self->flash( success => 'language' ); $self->redirect_to('account'); } else { my @languages = @{ $self->current_user->{languages} }; $self->param( language => $languages[0] // q{} ); $self->render('language'); } } sub change_mail { my ($self) = @_; Loading
lib/Travelynx/Model/Journeys.pm +2 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,8 @@ sub epoch_to_dt { ); } # TODO turn into a travelynx helper called from templates so that # loc_handle is available for localization sub min_to_human { my ( $self, $minutes ) = @_; Loading
lib/Travelynx/Model/Users.pm +8 −0 Original line number Diff line number Diff line Loading @@ -216,6 +216,14 @@ sub set_backend { ); } sub set_language { my ( $self, %opt ) = @_; $opt{db} //= $self->{pg}->db; $opt{db} ->update( 'users', { language => $opt{language} }, { id => $opt{uid} } ); } sub set_privacy { my ( $self, %opt ) = @_; my $db = $opt{db} // $self->{pg}->db; Loading
templates/account.html.ep +7 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ % elsif ($success eq 'password') { <span class="card-title">Passwort geändert</span> % } % elsif ($success eq 'language') { <span class="card-title">Sprache geändert</span> % } % elsif ($success eq 'privacy') { <span class="card-title">Einstellungen zu öffentlichen Account-Daten geändert</span> % } Loading Loading @@ -60,6 +63,10 @@ <th scope="row"><%= L('account.password') %></th> <td><a href="/account/password"><i class="material-icons">edit</i></a></td> </tr> <tr> <th scope="row"><%= L('account.language') %></th> <td><a href="/account/language"><i class="material-icons">edit</i></a><%= $acc->{languages}[0] // q{} %></td> </tr> <tr> <th scope="row"><%= L('account.connections') %></th> <td> Loading