diff options
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Travelynx.pm | 15 | ||||
-rw-r--r-- | lib/Travelynx/Command/translation.pm | 73 | ||||
-rw-r--r-- | lib/Travelynx/Controller/Account.pm | 12 |
3 files changed, 93 insertions, 7 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index 8dff817..cec4a92 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -3118,10 +3118,17 @@ sub startup { if ( $self->is_user_authenticated ) { return 1; } - $self->render( - 'login', - redirect_to => $self->req->url, - from => 'auth_required' + $self->respond_to( + json => { + json => { error => 'authentication required' }, + status => 401 + }, + any => { + template => 'login', + status => 401, + redirect_to => $self->req->url, + from => 'auth_required' + } ); return undef; } diff --git a/lib/Travelynx/Command/translation.pm b/lib/Travelynx/Command/translation.pm new file mode 100644 index 0000000..1f9ae78 --- /dev/null +++ b/lib/Travelynx/Command/translation.pm @@ -0,0 +1,73 @@ +package Travelynx::Command::translation; + +# Copyright (C) 2025 Birte Kristina Friesel +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +use Mojo::Base 'Mojolicious::Command'; +use Travelynx::Helper::Locales; + +has description => 'Export translation status'; + +has usage => sub { shift->extract_usage }; + +sub run { + my ( $self, $command ) = @_; + + my @locales = (qw(de-DE en-GB fr-FR hu-HU pl-PL)); + + my %handle; + for my $locale (@locales) { + $handle{$locale} = Travelynx::Helper::Locales->get_handle($locale); + $handle{$locale}->fail_with('failure_handler_auto'); + } + + binmode( STDOUT, ':encoding(utf-8)' ); + + if ( not $command ) { + $self->help; + } + elsif ( $command eq 'status' ) { + say '# Translation Status'; + say q{}; + + open( my $fh, '<:encoding(utf-8)', 'share/locales/de_DE.po' ); + for my $line (<$fh>) { + chomp $line; + if ( $line =~ m{ ^ [#] \s+ (.*) $ }x ) { + say "## $1"; + say q{}; + } + elsif ( $line =~ m{ ^ msgid \s+ " (.*) " $ }x ) { + my $id = $1; + say "### ${id}"; + say q{}; + for my $locale (@locales) { + my $translation = $handle{$locale}->maketext($id); + if ( $translation ne $id ) { + say "* ${locale}: ${translation}"; + } + else { + say "* ${locale} *missing*"; + } + } + say q{}; + } + } + close($fh); + } + else { + $self->help; + } +} + +1; + +__END__ + +=head1 SYNOPSIS + + Usage: index.pl dumpstops <format> <filename> + + Exports known stops to <filename>. + Right now, only the "csv" format is supported. diff --git a/lib/Travelynx/Controller/Account.pm b/lib/Travelynx/Controller/Account.pm index f4c6bcb..3a1e281 100644 --- a/lib/Travelynx/Controller/Account.pm +++ b/lib/Travelynx/Controller/Account.pm @@ -1119,6 +1119,7 @@ sub backend_form { if ( $s->{coverage}{area} and $s->{coverage}{area}{type} eq 'Polygon' + and defined $user_lon and $self->lonlat_in_polygon( $s->{coverage}{area}{coordinates}, [ $user_lon, $user_lat ] @@ -1128,7 +1129,8 @@ sub backend_form { push( @suggested_backends, $backend ); } elsif ( $s->{coverage}{area} - and $s->{coverage}{area}{type} eq 'MultiPolygon' ) + and $s->{coverage}{area}{type} eq 'MultiPolygon' + and defined $user_lon ) { for my $s_poly ( @{ $s->{coverage}{area}{coordinates} // [] } ) @@ -1189,6 +1191,7 @@ sub backend_form { if ( $s->{coverage}{area} and $s->{coverage}{area}{type} eq 'Polygon' + and defined $user_lon and $self->lonlat_in_polygon( $s->{coverage}{area}{coordinates}, [ $user_lon, $user_lat ] @@ -1198,7 +1201,8 @@ sub backend_form { push( @suggested_backends, $backend ); } elsif ( $s->{coverage}{area} - and $s->{coverage}{area}{type} eq 'MultiPolygon' ) + and $s->{coverage}{area}{type} eq 'MultiPolygon' + and defined $user_lon ) { for my $s_poly ( @{ $s->{coverage}{area}{coordinates} // [] } ) @@ -1240,6 +1244,7 @@ sub backend_form { if ( $s->{coverage}{area} and $s->{coverage}{area}{type} eq 'Polygon' + and defined $user_lon and $self->lonlat_in_polygon( $s->{coverage}{area}{coordinates}, [ $user_lon, $user_lat ] @@ -1249,7 +1254,8 @@ sub backend_form { push( @suggested_backends, $backend ); } elsif ( $s->{coverage}{area} - and $s->{coverage}{area}{type} eq 'MultiPolygon' ) + and $s->{coverage}{area}{type} eq 'MultiPolygon' + and defined $user_lon ) { for my $s_poly ( @{ $s->{coverage}{area}{coordinates} // [] } ) { |