-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vti
committed
Apr 2, 2011
1 parent
92d7c48
commit 1dd3135
Showing
7 changed files
with
180 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package MyAppI18N; | ||
|
||
use base 'Lamework'; | ||
|
||
use Plack::Builder; | ||
|
||
sub startup { | ||
my $self = shift; | ||
|
||
$self->routes->add_route( | ||
'/', | ||
name => 'foo', | ||
defaults => {action => 'foo'} | ||
); | ||
} | ||
|
||
sub compile_psgi_app { | ||
my $self = shift; | ||
|
||
my $app = sub { | ||
my $env = shift; | ||
|
||
return [404, [], ['404 Not Found']]; | ||
}; | ||
|
||
builder { | ||
enable '+Lamework::Middleware::I18N', namespace => 'MyAppI18N'; | ||
|
||
enable '+Lamework::Middleware::RoutesDispatcher'; | ||
|
||
enable '+Lamework::Middleware::ActionBuilder'; | ||
|
||
$app; | ||
}; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package MyAppI18N::Action::Foo; | ||
|
||
use base 'Lamework::Action'; | ||
|
||
sub run { | ||
my $self = shift; | ||
|
||
$self->res->code(200); | ||
$self->res->body($self->url_for('foo')); | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package MyAppI18N::I18N::ru; | ||
|
||
use strict; | ||
use warnings; | ||
use utf8; | ||
|
||
use base 'MyAppI18N::I18N'; | ||
|
||
our %Lexicon = ( | ||
'Hello' => 'Привет' | ||
); | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,78 @@ | ||
package MyAppI18N::I18N::ru; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test::More tests => 19; | ||
use base 'MyAppI18N::I18N'; | ||
|
||
our %Lexicon = ( | ||
'Hello' => 'Привет' | ||
); | ||
|
||
package main; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use utf8; | ||
|
||
use Test::More tests => 22; | ||
use Test::MockObject; | ||
|
||
use_ok('Lamework::Middleware::I18N'); | ||
|
||
use Lamework::Registry; | ||
|
||
my $middleware = | ||
Lamework::Middleware::I18N->new(app => sub { }, languages => [qw/en ru/]); | ||
my $middleware = Lamework::Middleware::I18N->new( | ||
app => sub { }, | ||
namespace => 'MyAppI18N', | ||
languages => [qw/en ru/] | ||
); | ||
|
||
my $env = {PATH_INFO => ''}; | ||
$middleware->call($env); | ||
is $env->{'lamework.i18n.language'} => 'en'; | ||
is $env->{PATH_INFO} => ''; | ||
is $env->{'lamework.i18n.language'} => 'en'; | ||
is $env->{PATH_INFO} => ''; | ||
is $env->{'lamework.i18n.maketext'}->('Hello') => 'Hello'; | ||
|
||
$env = {PATH_INFO => '/'}; | ||
$middleware->call($env); | ||
is $env->{'lamework.i18n.language'} => 'en'; | ||
is $env->{PATH_INFO} => '/'; | ||
is $env->{PATH_INFO} => '/'; | ||
|
||
$env = {PATH_INFO => '/hello'}; | ||
$middleware->call($env); | ||
is $env->{'lamework.i18n.language'} => 'en'; | ||
is $env->{PATH_INFO} => '/hello'; | ||
is $env->{PATH_INFO} => '/hello'; | ||
|
||
$env = {PATH_INFO => '/enhello'}; | ||
$middleware->call($env); | ||
is $env->{'lamework.i18n.language'} => 'en'; | ||
is $env->{PATH_INFO} => '/enhello'; | ||
is $env->{PATH_INFO} => '/enhello'; | ||
|
||
$env = {PATH_INFO => '/en'}; | ||
$middleware->call($env); | ||
is $env->{'lamework.i18n.language'} => 'en'; | ||
is $env->{PATH_INFO} => '/'; | ||
is $env->{PATH_INFO} => '/'; | ||
|
||
$env = {PATH_INFO => '/ru/'}; | ||
$middleware->call($env); | ||
is $env->{'lamework.i18n.language'} => 'ru'; | ||
is $env->{PATH_INFO} => '/'; | ||
is $env->{PATH_INFO} => '/'; | ||
is $env->{'lamework.i18n.maketext'}->('Hello') => 'Привет'; | ||
is $env->{'lamework.i18n.maketext'}->('Unknown') => 'Unknown'; | ||
|
||
$env = {PATH_INFO => '/ru/hello'}; | ||
$middleware->call($env); | ||
is $env->{'lamework.i18n.language'} => 'ru'; | ||
is $env->{PATH_INFO} => '/hello'; | ||
is $env->{PATH_INFO} => '/hello'; | ||
|
||
$env = {PATH_INFO => '/', HTTP_ACCEPT_LANGUAGE => 'en-us,en; q=0.5'}; | ||
$middleware->call($env); | ||
is $env->{'lamework.i18n.language'} => 'en'; | ||
is $env->{PATH_INFO} => '/'; | ||
is $env->{PATH_INFO} => '/'; | ||
|
||
$env = {PATH_INFO => '/', HTTP_ACCEPT_LANGUAGE => 'ru-ru,ru; q=0.5'}; | ||
$middleware->call($env); | ||
is $env->{'lamework.i18n.language'} => 'ru'; | ||
is $env->{PATH_INFO} => '/'; | ||
is $env->{PATH_INFO} => '/'; |