From 218f58dd547fd73b402732b826e548a444bcbaab Mon Sep 17 00:00:00 2001 From: vti Date: Sun, 3 Apr 2011 16:01:46 +0300 Subject: [PATCH] Pass available languages too --- lib/Lamework/Middleware/I18N.pm | 5 +++-- t/app_i18n.t | 4 ++-- t/lib/MyAppI18N/Action/Foo.pm | 5 ++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/Lamework/Middleware/I18N.pm b/lib/Lamework/Middleware/I18N.pm index 0bcef64..301f118 100644 --- a/lib/Lamework/Middleware/I18N.pm +++ b/lib/Lamework/Middleware/I18N.pm @@ -64,8 +64,9 @@ sub call { my $handle = $class->get_handle(@languages); $handle->fail_with(sub { $_[1] }); - $env->{'lamework.i18n.language'} = $handle->language_tag; - $env->{'lamework.i18n.maketext'} = sub { + $env->{'lamework.i18n.language'} = $handle->language_tag; + $env->{'lamework.i18n.languages'} = [$self->available_languages]; + $env->{'lamework.i18n.maketext'} = sub { return Encode::decode_utf8($handle->maketext(@_)); }; diff --git a/t/app_i18n.t b/t/app_i18n.t index 28395cf..6cbe13a 100644 --- a/t/app_i18n.t +++ b/t/app_i18n.t @@ -16,8 +16,8 @@ test_psgi $app, sub { my $cb = shift; my $res = $cb->(GET '/'); - is $res->content, 'http://localhost/en'; + is $res->content, 'http://localhost/en,en,ru|en'; $res = $cb->(GET '/ru'); - is $res->content, 'http://localhost/ru'; + is $res->content, 'http://localhost/ru,ru,ru|en'; }; diff --git a/t/lib/MyAppI18N/Action/Foo.pm b/t/lib/MyAppI18N/Action/Foo.pm index 0bcf2b7..b56802e 100644 --- a/t/lib/MyAppI18N/Action/Foo.pm +++ b/t/lib/MyAppI18N/Action/Foo.pm @@ -5,8 +5,11 @@ use base 'Lamework::Action'; sub run { my $self = shift; + my $language = $self->env->{'lamework.i18n.language'}; + my $languages = $self->env->{'lamework.i18n.languages'}; + $self->res->code(200); - $self->res->body($self->url_for('foo')); + $self->res->body(join ',' => $self->url_for('foo'), $language, join '|', @$languages); } 1;