diff -ur Catalyst-Plugin-I18N-0.09/lib/Catalyst/Plugin/I18N.pm Catalyst-Plugin-I18N-0.09-2HxZfC/lib/Catalyst/Plugin/I18N.pm --- Catalyst-Plugin-I18N-0.09/lib/Catalyst/Plugin/I18N.pm 2009-04-18 10:28:12.000000000 +0100 +++ Catalyst-Plugin-I18N-0.09-2HxZfC/lib/Catalyst/Plugin/I18N.pm 2009-06-24 14:59:49.000000000 +0100 @@ -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 diff -ur Catalyst-Plugin-I18N-0.09/t/04live.t Catalyst-Plugin-I18N-0.09-2HxZfC/t/04live.t --- Catalyst-Plugin-I18N-0.09/t/04live.t 2009-04-18 10:28:12.000000000 +0100 +++ Catalyst-Plugin-I18N-0.09-2HxZfC/t/04live.t 2009-06-24 15:00:52.000000000 +0100 @@ -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' ); + } + } diff -ur Catalyst-Plugin-I18N-0.09/t/lib/TestApp.pm Catalyst-Plugin-I18N-0.09-2HxZfC/t/lib/TestApp.pm --- Catalyst-Plugin-I18N-0.09/t/lib/TestApp.pm 2009-04-18 10:28:12.000000000 +0100 +++ Catalyst-Plugin-I18N-0.09-2HxZfC/t/lib/TestApp.pm 2009-06-24 14:51:02.000000000 +0100 @@ -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;