Unverified Commit 731b7898 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Localization with Locale::Maketext

WiP, no suitable foundation for merge requests yet.

Still todo:
* override Accept-Language header via account settings
* Adjust all the templates and frontend javascript

Related to #223
parent e081fd25
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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';
+33 −0
Original line number Diff line number Diff line
@@ -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) = @_;
@@ -411,6 +437,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' );
+22 −0
Original line number Diff line number Diff line
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;

share/locales/de_DE.po

0 → 100644
+58 −0
Original line number Diff line number Diff line
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"

share/locales/en_GB.po

0 → 100644
+58 −0
Original line number Diff line number Diff line
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"
Loading