From 7c8bd21ccbca8a3166289ab0e5511cc82d2822aa Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Sun, 1 May 2022 22:02:37 +0200 Subject: collection of smaller changes --- lib/JWebmail/Plugin/I18N2.pm | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'lib/JWebmail/Plugin/I18N2.pm') diff --git a/lib/JWebmail/Plugin/I18N2.pm b/lib/JWebmail/Plugin/I18N2.pm index c951eec..61f87d6 100644 --- a/lib/JWebmail/Plugin/I18N2.pm +++ b/lib/JWebmail/Plugin/I18N2.pm @@ -125,8 +125,10 @@ sub register { } } - $app->defaults(default_language => $defaultLang); - $app->defaults(languages => [$t->languages]); + $app->defaults( + default_language => $defaultLang, + languages => [$t->languages], + ); # add translator as helper $app->helper(l => sub { @@ -142,16 +144,13 @@ sub register { return $res; }); - # modify incoming url - $app->hook(before_dispatch => sub { + # modify incoming and generated urls + $app->hook(before_routes => sub { my $c = shift; + unshift @{ $c->req->url->path->parts }, '' unless $t->languages($c->req->url->path->parts->[0] || ''); - }); - # modify generated url - $app->hook(before_dispatch => sub { - my $c = shift; $c->match(JWebmail::Plugin::I18N2::Match->new( root => $c->app->routes, _i18n2_stash => $c->stash, -- cgit v1.2.3