diff options
-rw-r--r-- | cpanfile | 2 | ||||
-rwxr-xr-x | lib/Travelynx.pm | 33 | ||||
-rw-r--r-- | lib/Travelynx/Helper/Locales.pm | 22 | ||||
-rw-r--r-- | share/locales/de_DE.po | 58 | ||||
-rw-r--r-- | share/locales/en_GB.po | 58 | ||||
-rw-r--r-- | templates/account.html.ep | 30 |
6 files changed, 188 insertions, 15 deletions
@@ -9,6 +9,8 @@ requires 'GIS::Distance::Fast'; requires 'IO::Socket::Socks', '>= 0.64'; requires 'IO::Socket::SSL', '>= 2.009'; requires 'List::UtilsBy'; +requires 'Locale::Maketext'; +requires 'Locale::Maketext::Lexicon'; requires 'Math::Polygon'; requires 'MIME::Entity'; requires 'Mojolicious'; diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index 7dba658..3ddce00 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -26,6 +26,7 @@ use Travelynx::Helper::DBRIS; use Travelynx::Helper::EFA; use Travelynx::Helper::HAFAS; use Travelynx::Helper::IRIS; +use Travelynx::Helper::Locales; use Travelynx::Helper::MOTIS; use Travelynx::Helper::Sendmail; use Travelynx::Helper::Traewelling; @@ -157,6 +158,31 @@ sub startup { } ); + $self->hook( + 'before_render' => sub { + my ($self) = @_; + + # TODO load languages from user profile, if set + + my @languages = ('en-GB'); + if ( my $languages = $self->req->headers->accept_language ) { + @languages = (); + + #say "-- Accept-Language: $languages"; + 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' ); + } + } + } + $self->stash( loc_handle => + Travelynx::Helper::Locales->get_handle(@languages) ); + } + ); + $self->attr( cache_iris_main => sub { my ($self) = @_; @@ -412,6 +438,13 @@ sub startup { ); $self->helper( + 'L' => sub { + my ( $self, @args ) = @_; + $self->stash('loc_handle')->maketext(@args); + } + ); + + $self->helper( 'now' => sub { return DateTime->now( time_zone => 'Europe/Berlin' ); } diff --git a/lib/Travelynx/Helper/Locales.pm b/lib/Travelynx/Helper/Locales.pm new file mode 100644 index 0000000..12e95d1 --- /dev/null +++ b/lib/Travelynx/Helper/Locales.pm @@ -0,0 +1,22 @@ +package Travelynx::Helper::Locales; + +use strict; +use warnings; + +use base qw(Locale::Maketext); + +our %lexicon = ( + _AUTO => 1, +); + +use Locale::Maketext::Lexicon { + _decode => 1, + '*' => [ Gettext => 'share/locales/*.po' ], +}; + +sub init { + my ($self) = @_; + return $self->SUPER::init( @_[ 1 .. $#_ ] ); +} + +1; diff --git a/share/locales/de_DE.po b/share/locales/de_DE.po new file mode 100644 index 0000000..190b577 --- /dev/null +++ b/share/locales/de_DE.po @@ -0,0 +1,58 @@ +msgid "" +msgstr "" +"Language: de-DE\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" + +# Global + +msgid "button.logout" +msgstr "Abmelden" + +# account.html.ep + +msgid "account.account" +msgstr "Account" + +msgid "account.name" +msgstr "Name" + +msgid "account.mail" +msgstr "E-Mail" + +msgid "account.password" +msgstr "Passwort" + +msgid "account.connections" +msgstr "Verbindungen" + +msgid "account.connections.enabled" +msgstr "Vorschläge aktiv" + +msgid "account.connections.disabled" +msgstr "Vorschläge deaktiviert" + +msgid "account.visibility" +msgstr "Sichtbarkeit" + +msgid "account.interaction" +msgstr "Interaktion" + +msgid "account.interaction.accept-follows" +msgstr "Accounts können dir direkt folgen" + +msgid "account.interaction.accept-follow-requests" +msgstr "Accounts können dir auf Anfrage folgen" + +msgid "account.interaction.one" +msgstr "eine" + +msgid "account.interaction.open-request" +msgstr "offene Anfrage" + +msgid "account.interaction.open-requests" +msgstr "offene Anfragen" + +msgid "account.interaction.disabled" +msgstr "Accounts können dir nicht folgen" diff --git a/share/locales/en_GB.po b/share/locales/en_GB.po new file mode 100644 index 0000000..1bfcbc3 --- /dev/null +++ b/share/locales/en_GB.po @@ -0,0 +1,58 @@ +msgid "" +msgstr "" +"Language: de-DE\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" + +# Global + +msgid "button.logout" +msgstr "Logout" + +# account.html.ep + +msgid "account.account" +msgstr "Account" + +msgid "account.name" +msgstr "Name" + +msgid "account.mail" +msgstr "E-Mail" + +msgid "account.password" +msgstr "Password" + +msgid "account.connections" +msgstr "Connections" + +msgid "account.connections.enabled" +msgstr "Suggestions enabled" + +msgid "account.connections.disabled" +msgstr "Suggestions disabled" + +msgid "account.visibility" +msgstr "Visibility" + +msgid "account.interaction" +msgstr "Interaction" + +msgid "account.interaction.accept-follows" +msgstr "Accounts may follow you" + +msgid "account.interaction.accept-follow-requests" +msgstr "Accounts may send follow requests" + +msgid "account.interaction.one" +msgstr "one" + +msgid "account.interaction.open-request" +msgstr "open request" + +msgid "account.interaction.open-requests" +msgstr "open requests" + +msgid "account.interaction.disabled" +msgstr "Accounts cannot follow you" diff --git a/templates/account.html.ep b/templates/account.html.ep index e4bf38d..4c5add8 100644 --- a/templates/account.html.ep +++ b/templates/account.html.ep @@ -46,34 +46,34 @@ % my $use_history = users->use_history(uid => $acc->{id}); <div class="row"> <div class="col s12"> - <h2>Account</h2> + <h2><%= L('account.account') %></h2> <table class="striped"> <tr> - <th scope="row">Name</th> + <th scope="row"><%= L('account.name') %></th> <td><a href="/account/name"><i class="material-icons">edit</i></a><%= $acc->{name} %></td> </tr> <tr> - <th scope="row">Mail</th> + <th scope="row"><%= L('account.mail') %></th> <td><a href="/account/mail"><i class="material-icons">edit</i></a><%= $acc->{email} %></td> </tr> <tr> - <th scope="row">Passwort</th> + <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">Verbindungen</th> + <th scope="row"><%= L('account.connections') %></th> <td> <a href="/account/insight"><i class="material-icons">edit</i></a> % if ($use_history & 0x03) { - Vorschläge aktiv + %= L('account.connections.enabled') % } % else { - <span style="color: #999999;">Vorschläge deaktiviert</span> + <span style="color: #999999;"><%= L('account.connections.disabled') %></span> % } </td> </tr> <tr> - <th scope="row">Sichtbarkeit</th> + <th scope="row"><%= L('account.visibility') %></th> <td> <a href="/account/privacy"><i class="material-icons">edit</i></a> <i class="material-icons">check</i><i class="material-icons"><%= visibility_icon($acc->{default_visibility_str}) %></i> @@ -81,23 +81,23 @@ </td> </tr> <tr> - <th scope="row">Interaktion</th> + <th scope="row"><%= L('account.interaction') %></th> <td> <a href="/account/social"><i class="material-icons">edit</i></a> % if ($acc->{accept_follows}) { - <span>Accounts können dir direkt folgen</span> + <span><%= L('account.interaction.accept-follows') %></span> % } % elsif ($acc->{accept_follow_requests}) { - <span>Accounts können dir auf Anfrage folgen + <span><%= L('account.interaction.accept-follow-requests') %> % if ($num_rx_follow_requests == 1) { - – <a href="/account/social/follow-requests-received"><strong>eine</strong> offene Anfrage</a> + – <a href="/account/social/follow-requests-received"><strong><%= L('account.interaction.one') %></strong> <%= L('account.interaction.open-request') %></a> % } elsif ($num_rx_follow_requests) { - – <a href="/account/social/follow-requests-received"><strong><%= $num_rx_follow_requests %></strong> offene Anfragen</a> + – <a href="/account/social/follow-requests-received"><strong><%= $num_rx_follow_requests %></strong> <%= L('account.interaction.open-requests') %></a> % } </span> % } % else { - <span style="color: #999999;">Accounts können dir nicht folgen</span> + <span style="color: #999999;"><%= L('account.interaction.disabled') %></span> % } </td> </tr> @@ -163,7 +163,7 @@ %= form_for 'logout' => begin %= csrf_field <button class="btn waves-effect waves-light" type="submit" name="action" value="logout"> - Abmelden + %= L('button.logout') </button> %= end </div> |