[Jifty-commit] r2545 - jifty/trunk/lib/Jifty

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Jan 24 02:38:39 EST 2007


Author: agentz
Date: Wed Jan 24 02:38:33 2007
New Revision: 2545

Modified:
   jifty/trunk/lib/Jifty/Handler.pm
   jifty/trunk/lib/Jifty/I18N.pm

Log:
[Jifty::I18N]
* added the update method which reconstructs the locale
  handle (used by Jifty::Handler::handle_request)
* &_(loc) now uses the global locale handle instead of
  the one set up during Jifty::I18N->new().
* Audrey's refresh method now always calls C<update>
  either directly or indirectly (via C<new>)
[Jifty::Handler]
* C<handle_request> now always calls
  Jifty::I18N->update directly or indirectly
  (via C<Jifty::I18N->refresh>)
With this patch, Jifty's I18N works perfectly per
user's HTTP request when using the standalone server
(or possibly with Apache too)


Modified: jifty/trunk/lib/Jifty/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Handler.pm	(original)
+++ jifty/trunk/lib/Jifty/Handler.pm	Wed Jan 24 02:38:33 2007
@@ -180,6 +180,9 @@
     if ( Jifty->config->framework('DevelMode') ) {
         Module::Refresh->refresh;
         Jifty::I18N->refresh;
+    } else {
+        # We need to update I18N's locale handle per request:
+        Jifty::I18N->update;
     }
 
     $self->cgi( $args{cgi} );

Modified: jifty/trunk/lib/Jifty/I18N.pm
==============================================================================
--- jifty/trunk/lib/Jifty/I18N.pm	(original)
+++ jifty/trunk/lib/Jifty/I18N.pm	Wed Jan 24 02:38:33 2007
@@ -7,6 +7,7 @@
 use Email::MIME::ContentType;
 use Encode::Guess qw(iso-8859-1);
 use File::ShareDir ':ALL';
+#use Smart::Comments;
 
 =head1 NAME
 
@@ -17,7 +18,7 @@
 =head2 C<_>
 
 This module exports the C<loc> method, which it inherits from
-L<Locale::Maketext::Simple>. Jifty aliases this method to C<_()> for 
+L<Locale::Maketext>. Jifty aliases this method to C<_()> for 
 your convenience.
 
 =cut
@@ -30,6 +31,7 @@
 
 =cut
 
+our ($LocaleHandle, $Lang);
 
 sub new {
     my $class = shift;
@@ -60,25 +62,27 @@
 
     # Allow hard-coded languages in the config file
     my $lang = Jifty->config->framework('L10N')->{'Lang'};
-    $lang = [defined $lang ? $lang : ()] unless ref($lang) eq 'ARRAY';
+    $Lang = [defined $lang ? $lang : ()] unless ref($lang) eq 'ARRAY';
 
-    my $lh         = $class->get_handle(@$lang);
+    $class->update;
     my $loc_method = sub {
+        ### ref class: ref($LocaleHandle)
         # Retain compatibility with people using "-e _" etc.
         return \*_ unless @_;
 
         # When $_[0] is undef, return undef.  When it is '', return ''.
-        no warnings 'uninitialized';
-        return $_[0] unless (length $_[0]);
+        return $_[0] if !defined $_[0] or $_[0] eq '';
 
-        local $@;
         # Force stringification to stop Locale::Maketext from choking on
         # things like DateTime objects.
         my @stringified_args = map {"$_"} @_;
-        my $result = eval { $lh->maketext(@stringified_args) };
+        
+        local $@;
+        my $result = eval { $LocaleHandle->maketext(@stringified_args) };
         if ($@) {
             # Sometimes Locale::Maketext fails to localize a string and throws
             # an exception instead.  In that case, we just return the input.
+            ### got error: $@
             return join(' ', @stringified_args);
         }
         return $result;
@@ -101,6 +105,7 @@
 
 my $last_modified = '';
 sub refresh {
+    my $class = shift;
     my $modified = join(
         ',',
         sort map { $_ => -M $_ } map { glob("$_/*.po") } (
@@ -109,12 +114,23 @@
         )
     );
     if ($modified ne $last_modified) {
-        Jifty::I18N->new;
+        $class->new;
         $last_modified = $modified;
+    } else {
+        $class->update;
     }
 }
 
+=head2 update
 
+Used by L<Jifty::Handler> to update the I18N handle per HTTP request.
+
+=cut
+
+sub update {
+    ### updating the Locale Handle...
+    $LocaleHandle = $_[0]->get_handle(@$Lang);
+}
 
 =head2 promote_encoding STRING [CONTENT-TYPE]
 


More information about the Jifty-commit mailing list