[Catalyst-commits] r6573 - in trunk/Catalyst-Plugin-I18N: .
lib/Catalyst/Plugin t t/lib t/lib/TestApp/I18N
bricas at dev.catalyst.perl.org
bricas at dev.catalyst.perl.org
Tue Jul 17 21:55:33 GMT 2007
Author: bricas
Date: 2007-07-17 21:55:33 +0100 (Tue, 17 Jul 2007)
New Revision: 6573
Added:
trunk/Catalyst-Plugin-I18N/t/lib/TestApp/I18N/en_us.pm
Modified:
trunk/Catalyst-Plugin-I18N/Changes
trunk/Catalyst-Plugin-I18N/Makefile.PL
trunk/Catalyst-Plugin-I18N/lib/Catalyst/Plugin/I18N.pm
trunk/Catalyst-Plugin-I18N/t/04live.t
trunk/Catalyst-Plugin-I18N/t/lib/TestApp.pm
Log:
switch to module::install, added language_tag() method + tests
Modified: trunk/Catalyst-Plugin-I18N/Changes
===================================================================
--- trunk/Catalyst-Plugin-I18N/Changes 2007-07-17 20:40:23 UTC (rev 6572)
+++ trunk/Catalyst-Plugin-I18N/Changes 2007-07-17 20:55:33 UTC (rev 6573)
@@ -1,6 +1,12 @@
Revision history for Perl extension Catalyst::Plugin::I18N.
-0.05 Sun Jan 09 200g
+0.06 Tue Jul 17 2007
+ - re-org distro
+ - switch to Module::Install
+ - added language_tag() method
+ - pod fixes
+
+0.05 Sun Jan 09 2006
- added language() method (Daisuke Murase)
0.04 Wed Nov 30 2005
Modified: trunk/Catalyst-Plugin-I18N/Makefile.PL
===================================================================
--- trunk/Catalyst-Plugin-I18N/Makefile.PL 2007-07-17 20:40:23 UTC (rev 6572)
+++ trunk/Catalyst-Plugin-I18N/Makefile.PL 2007-07-17 20:55:33 UTC (rev 6573)
@@ -1,13 +1,14 @@
-use ExtUtils::MakeMaker;
+use inc::Module::Install 0.65;
-WriteMakefile(
- NAME => 'Catalyst::Plugin::I18N',
- AUTHOR => 'Sebastian Riedel (sri at oook.de)',
- PREREQ_PM => {
- 'Catalyst' => '2.99',
- 'Locale::Maketext::Simple' => 0,
- 'I18N::LangTags::Detect' => 0,
- 'Locale::Maketext::Lexicon' => 0,
- },
- VERSION_FROM => 'I18N.pm'
-);
+name 'Catalyst-Plugin-I18N';
+all_from 'lib/Catalyst/Plugin/I18N.pm';
+
+requires 'Catalyst::Runtime';
+requires 'Locale::Maketext::Simple';
+requires 'I18N::LangTags::Detect';
+requires 'Locale::Maketext::Lexicon';
+
+requires 'Test::More';
+
+auto_install;
+WriteAll;
Modified: trunk/Catalyst-Plugin-I18N/lib/Catalyst/Plugin/I18N.pm
===================================================================
--- trunk/Catalyst-Plugin-I18N/lib/Catalyst/Plugin/I18N.pm 2007-07-17 20:40:23 UTC (rev 6572)
+++ trunk/Catalyst-Plugin-I18N/lib/Catalyst/Plugin/I18N.pm 2007-07-17 20:55:33 UTC (rev 6573)
@@ -7,7 +7,7 @@
require Locale::Maketext::Simple;
-our $VERSION = '0.05';
+our $VERSION = '0.06';
=head1 NAME
@@ -80,7 +80,7 @@
Contains languages.
$c->languages(['de_DE']);
- print join '', @{ $c->language };
+ print join '', @{ $c->languages };
=cut
@@ -118,6 +118,24 @@
return $lang;
}
+=head3 language_tag
+
+return language tag for current locale. The most notable difference from this
+method in comparison to C<language()> is typically that languages and regions
+are joined with a dash and not an underscore.
+
+ $c->language(); # en_us
+ $c->language_tag(); # en-us
+
+=cut
+
+sub language_tag {
+ my $c = shift;
+ my $class = ref $c || $c;
+
+ return "$class\::I18N"->get_handle( @{ $c->languages } )->language_tag;
+}
+
=head3 loc
=head3 localize
Modified: trunk/Catalyst-Plugin-I18N/t/04live.t
===================================================================
--- trunk/Catalyst-Plugin-I18N/t/04live.t 2007-07-17 20:40:23 UTC (rev 6572)
+++ trunk/Catalyst-Plugin-I18N/t/04live.t 2007-07-17 20:55:33 UTC (rev 6573)
@@ -6,7 +6,7 @@
use FindBin;
use lib "$FindBin::Bin/lib";
-use Test::More tests => 12;
+use Test::More tests => 20;
use Catalyst::Test 'TestApp';
BEGIN {
@@ -73,4 +73,32 @@
is( $response->content, $expected, 'Content OK' );
}
+ # test language()/language_tag()
+ {
+ my $expected = 'en_us';
+ my $request =
+ HTTP::Request->new( GET => 'http://localhost:3000/current_language' );
+
+ $request->header( 'Accept-Language' => 'en-us' );
+
+ ok( my $response = request($request), 'Request' );
+ ok( $response->is_success, 'Response Successful 2xx' );
+ is( $response->code, 200, 'Response Code' );
+
+ is( $response->content, $expected, 'Content OK' );
+ }
+ {
+ my $expected = 'en-us';
+ my $request =
+ HTTP::Request->new( GET => 'http://localhost:3000/current_language_tag' );
+
+ $request->header( 'Accept-Language' => 'en-us' );
+
+ ok( my $response = request($request), 'Request' );
+ ok( $response->is_success, 'Response Successful 2xx' );
+ is( $response->code, 200, 'Response Code' );
+
+ is( $response->content, $expected, 'Content OK' );
+ }
+
}
Added: trunk/Catalyst-Plugin-I18N/t/lib/TestApp/I18N/en_us.pm
===================================================================
--- trunk/Catalyst-Plugin-I18N/t/lib/TestApp/I18N/en_us.pm (rev 0)
+++ trunk/Catalyst-Plugin-I18N/t/lib/TestApp/I18N/en_us.pm 2007-07-17 20:55:33 UTC (rev 6573)
@@ -0,0 +1,12 @@
+package TestApp::I18N::en_us;
+
+use strict;
+use warnings;
+
+use base qw( TestApp::I18N );
+
+our %Lexicon = (
+ 'Hello' => 'Yo!'
+);
+
+1;
Modified: trunk/Catalyst-Plugin-I18N/t/lib/TestApp.pm
===================================================================
--- trunk/Catalyst-Plugin-I18N/t/lib/TestApp.pm 2007-07-17 20:40:23 UTC (rev 6572)
+++ trunk/Catalyst-Plugin-I18N/t/lib/TestApp.pm 2007-07-17 20:55:33 UTC (rev 6573)
@@ -18,5 +18,10 @@
my( $self, $c ) = @_;
$c->res->body( $c->language );
}
+
+sub current_language_tag : Global {
+ my( $self, $c ) = @_;
+ $c->res->body( $c->language_tag );
+}
-1;
\ No newline at end of file
+1;
More information about the Catalyst-commits
mailing list