[Catalyst-commits] r13341 - in Catalyst-Plugin-I18N/trunk: .
lib/Catalyst/Plugin t
tonvoon at dev.catalyst.perl.org
tonvoon at dev.catalyst.perl.org
Mon Jun 14 14:20:56 GMT 2010
Author: tonvoon
Date: 2010-06-14 15:20:56 +0100 (Mon, 14 Jun 2010)
New Revision: 13341
Modified:
Catalyst-Plugin-I18N/trunk/Changes
Catalyst-Plugin-I18N/trunk/lib/Catalyst/Plugin/I18N.pm
Catalyst-Plugin-I18N/trunk/t/04live.t
Log:
Re-implemented installed languages by parsing directory, rather
than using namespaces as this was unreliable (other languages added
to namespaces based on LANG envvar)
Modified: Catalyst-Plugin-I18N/trunk/Changes
===================================================================
--- Catalyst-Plugin-I18N/trunk/Changes 2010-06-14 13:42:27 UTC (rev 13340)
+++ Catalyst-Plugin-I18N/trunk/Changes 2010-06-14 14:20:56 UTC (rev 13341)
@@ -1,6 +1,6 @@
Revision history for Perl extension Catalyst::Plugin::I18N.
- - Add Language List feature by Ton Voon
+ - Add Language List feature by Ton Voon and Chris Dolan (RT #25050)
- Add dependency and tests for i-default fallback feature in Locale::Maketext::Simple 0.19
0.09 Sat Apr 18 2009
Modified: Catalyst-Plugin-I18N/trunk/lib/Catalyst/Plugin/I18N.pm
===================================================================
--- Catalyst-Plugin-I18N/trunk/lib/Catalyst/Plugin/I18N.pm 2010-06-14 13:42:27 UTC (rev 13340)
+++ Catalyst-Plugin-I18N/trunk/lib/Catalyst/Plugin/I18N.pm 2010-06-14 14:20:56 UTC (rev 13341)
@@ -102,6 +102,29 @@
else {
$self->log->debug(qq/Initialized i18n "$self\::I18N"/) if $self->debug;
}
+
+ if (! $self->config->{ 'Plugin::I18N' }->{installed_languages}) {
+ my $languages_list = {};
+ # We re-read the list of files in $path
+ # Originally tried to detect via namespaces, but this lists the currently set LANG envvar, which may not
+ # be a supported language. Also misses out .pm files
+ # Is acceptable to re-read this directory once on setup
+ if (opendir my $langdir, $path) {
+ foreach my $entry (readdir $langdir) {
+ next unless $entry =~ m/\A (\w+)\.(?:pm|po|mo) \z/xms;
+ my $langtag = $1;
+ next if $langtag eq "i_default";
+ my $language_tag = $langtag;
+ #my $language_tag = "$class\::I18N"->get_handle( $langtag )->language_tag;
+ # 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 );
+ }
+ closedir $langdir;
+ }
+ $self->config->{ 'Plugin::I18N' }->{installed_languages} = $languages_list;
+ }
}
=head2 METHODS
@@ -177,22 +200,7 @@
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;
+ return $c->config->{ 'Plugin::I18N' }->{installed_languages};
}
=head3 loc
Modified: Catalyst-Plugin-I18N/trunk/t/04live.t
===================================================================
--- Catalyst-Plugin-I18N/trunk/t/04live.t 2010-06-14 13:42:27 UTC (rev 13340)
+++ Catalyst-Plugin-I18N/trunk/t/04live.t 2010-06-14 14:20:56 UTC (rev 13341)
@@ -118,7 +118,7 @@
# Test languages_list
{
- my $expected = "de=German, en=English, en_gb=UK English, en_us=US English, fr=French, fr_ca=Canadian French";
+ my $expected = "de=German, en_us=US English, fr=French";
my $request =
HTTP::Request->new( GET => 'http://localhost:3000/current_languages_list' );
More information about the Catalyst-commits
mailing list