[Catalyst-commits] r10704 - in Catalyst-Plugin-I18N/trunk: .
lib/Catalyst/Plugin t t/lib
marcus at dev.catalyst.perl.org
marcus at dev.catalyst.perl.org
Sun Jun 28 17:26:39 GMT 2009
Author: marcus
Date: 2009-06-28 17:26:38 +0000 (Sun, 28 Jun 2009)
New Revision: 10704
Modified:
Catalyst-Plugin-I18N/trunk/Changes
Catalyst-Plugin-I18N/trunk/lib/Catalyst/Plugin/I18N.pm
Catalyst-Plugin-I18N/trunk/t/04live.t
Catalyst-Plugin-I18N/trunk/t/lib/TestApp.pm
Log:
Language List feature by Ton Voon
Modified: Catalyst-Plugin-I18N/trunk/Changes
===================================================================
--- Catalyst-Plugin-I18N/trunk/Changes 2009-06-28 16:58:01 UTC (rev 10703)
+++ Catalyst-Plugin-I18N/trunk/Changes 2009-06-28 17:26:38 UTC (rev 10704)
@@ -1,5 +1,7 @@
Revision history for Perl extension Catalyst::Plugin::I18N.
+ - Add Language List feature by Ton Voon
+
0.09 Sat Apr 18 2009
- switch NEXT out for MRO::Compat
Modified: Catalyst-Plugin-I18N/trunk/lib/Catalyst/Plugin/I18N.pm
===================================================================
--- Catalyst-Plugin-I18N/trunk/lib/Catalyst/Plugin/I18N.pm 2009-06-28 16:58:01 UTC (rev 10703)
+++ Catalyst-Plugin-I18N/trunk/lib/Catalyst/Plugin/I18N.pm 2009-06-28 17:26:38 UTC (rev 10704)
@@ -6,6 +6,7 @@
use MRO::Compat;
use I18N::LangTags ();
use I18N::LangTags::Detect;
+use I18N::LangTags::List;
require Locale::Maketext::Simple;
@@ -157,6 +158,34 @@
return "$class\::I18N"->get_handle( @{ $c->languages } )->language_tag;
}
+=head3 languages_list
+
+Returns a hash of { langtag => "descriptive name for language" } based on languages
+available in the namespace. The descriptive name is based on I18N::LangTags::List information.
+If the descriptive name is not available, will be undef.
+
+=cut
+
+sub languages_list {
+ my $c = shift;
+ my $class = ref $c || $c;
+ my $languages_list = {};
+ my $namespace = "${class}::I18N::";
+ no strict 'refs';
+ foreach my $loaded_class (%$namespace) {
+ next unless $loaded_class =~ /::([\w-]+)::$/;
+ my $langtag = $1;
+ next if $langtag eq "i_default";
+ #my $language_tag = "$class\::I18N"->get_handle( $langtag )->language_tag;
+ my $language_tag = $langtag;
+ # Did use the get_handle, but that caused problems because en became "Default (Fallthru) Language"
+ # Just do a simple convert instead
+ $language_tag =~ s/_/-/g;
+ $languages_list->{ $langtag } = I18N::LangTags::List::name( $language_tag );
+ }
+ return $languages_list;
+}
+
=head3 loc
=head3 localize
Modified: Catalyst-Plugin-I18N/trunk/t/04live.t
===================================================================
--- Catalyst-Plugin-I18N/trunk/t/04live.t 2009-06-28 16:58:01 UTC (rev 10703)
+++ Catalyst-Plugin-I18N/trunk/t/04live.t 2009-06-28 17:26:38 UTC (rev 10704)
@@ -6,7 +6,7 @@
use FindBin;
use lib "$FindBin::Bin/lib";
-use Test::More tests => 24;
+use Test::More tests => 28;
use Catalyst::Test 'TestApp';
BEGIN {
@@ -116,4 +116,17 @@
is( $response->content, $expected, 'Content OK' );
}
+ # Test languages_list
+ {
+ my $expected = "de=German, en=English, en_gb=UK English, en_us=US English, fr=French, fr_ca=Canadian French";
+ my $request =
+ HTTP::Request->new( GET => 'http://localhost:3000/current_languages_list' );
+
+ 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' );
+ }
+
}
Modified: Catalyst-Plugin-I18N/trunk/t/lib/TestApp.pm
===================================================================
--- Catalyst-Plugin-I18N/trunk/t/lib/TestApp.pm 2009-06-28 16:58:01 UTC (rev 10703)
+++ Catalyst-Plugin-I18N/trunk/t/lib/TestApp.pm 2009-06-28 17:26:38 UTC (rev 10704)
@@ -24,4 +24,11 @@
$c->res->body( $c->language_tag );
}
+sub current_languages_list : Global {
+ my( $self, $c ) = @_;
+ my $h = $c->languages_list;
+ my $output = join(", ", map { "$_=".$h->{$_} } (sort keys %$h) );
+ $c->res->body( $output );
+}
+
1;
More information about the Catalyst-commits
mailing list