diff options
Diffstat (limited to 'lib/JWebmail')
-rw-r--r-- | lib/JWebmail/Plugin/I18N.pm | 2 | ||||
-rw-r--r-- | lib/JWebmail/Plugin/I18N2.pm | 30 |
2 files changed, 30 insertions, 2 deletions
diff --git a/lib/JWebmail/Plugin/I18N.pm b/lib/JWebmail/Plugin/I18N.pm index dc10fdd..a554ff7 100644 --- a/lib/JWebmail/Plugin/I18N.pm +++ b/lib/JWebmail/Plugin/I18N.pm @@ -209,4 +209,4 @@ This is used for your translations. $c->l('hello') $app->helper('hello')->() -=cut
\ No newline at end of file +=cut 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 |