diff options
author | Jannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de> | 2020-11-03 16:50:29 +0100 |
---|---|---|
committer | Jannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de> | 2020-11-03 16:50:29 +0100 |
commit | 8fdd948d0e805d937e0325db1a096c774ffd1233 (patch) | |
tree | bb2b2c4be82e88b9f8f375217c17161379ba194c /lib/JWebmail/Plugin/I18N2.pm | |
parent | 582f135054625f52aa08c4b52b30ee152c5aa282 (diff) |
added monkey patch replacement for future version of Mojolicious
Diffstat (limited to 'lib/JWebmail/Plugin/I18N2.pm')
-rw-r--r-- | lib/JWebmail/Plugin/I18N2.pm | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/JWebmail/Plugin/I18N2.pm b/lib/JWebmail/Plugin/I18N2.pm index 53813de..84d4af3 100644 --- a/lib/JWebmail/Plugin/I18N2.pm +++ b/lib/JWebmail/Plugin/I18N2.pm @@ -7,6 +7,32 @@ use Mojo::File; use Mojo::Util 'monkey_patch'; +package JWebmail::Plugin::I18N2::Match { + use Mojo::Base 'Mojolicious::Routes::Match'; + + has '_i18n2_stash'; + + sub path_for { + my $self = shift; + if (my $lang = $self->_i18n2_stash->{lang}) { + if (ref $_[0] eq 'HASH') { + $_[0]->{lang} ||= $lang; + } + elsif (ref $_[1] eq 'HASH') { + $_[1]->{lang} ||= $lang; + } + else { + my ($dom, %args) = @_%2 == 0 ? (undef, @_) : @_; + $args{lang} ||= $lang; + @_ = ($dom, %args); + shift @_ unless defined $_[0]; + } + } + $self->next::method(@_) + } +} + + has '_language_loaded' => sub { {} }; @@ -63,6 +89,8 @@ sub register { unless $self->_language_loaded->{$c->req->url->path->parts->[0] || ''}; }); + #$app->hook(before_dispatch => sub { my $c = shift; $c->match(JWebmail::Plugin::I18N2::Match->new(root => $c->app->routes, _i18n2_stash => $c->stash)); }); + # patch url_for my $mojo_url_for = Mojolicious::Controller->can('url_for'); my $i18n_url_for = sub { @@ -182,4 +210,4 @@ This is used for your translations. $c->l('hello') $app->helper('hello')->() -=cut
\ No newline at end of file +=cut |