From: Chris W. <la...@us...> - 2005-01-25 04:26:53
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1120/OpenInteract2 Modified Files: Context.pm Log Message: OIN-26: ensure we always have a localization handle available Index: Context.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Context.pm,v retrieving revision 1.79 retrieving revision 1.80 diff -C2 -d -r1.79 -r1.80 *** Context.pm 24 Jan 2005 17:17:15 -0000 1.79 --- Context.pm 25 Jan 2005 04:26:43 -0000 1.80 *************** *** 26,29 **** --- 26,31 ---- sub DEPLOY_STATIC_URL { return $DEPLOY_STATIC_URL } + my ( $DEFAULT_LANGUAGE_HANDLE ); + # This is the only copy of the context that should be around. We might # modify this later so we can have multiple copies of the context *************** *** 49,52 **** --- 51,55 ---- require OpenInteract2::Exception; require OpenInteract2::Setup; + require OpenInteract2::I18N; my @CORE_FIELDS = qw( base_config repository packages cache *************** *** 171,174 **** --- 174,178 ---- } + ######################################## # CONFIGURATION ASSIGNMENTS *************** *** 192,195 **** --- 196,203 ---- $self->assign_deploy_static_url; $log_init->info( "Assigned constants from server config ok" ); + + $DEFAULT_LANGUAGE_HANDLE = OpenInteract2::I18N->get_handle( + $config->{language}{default_language} + ); } return $self->{server_config}; *************** *** 275,278 **** --- 283,287 ---- } + ######################################## # DATE FACTORY *************** *** 300,303 **** --- 309,313 ---- } + ######################################## # ACTION LOOKUP *************** *** 319,322 **** --- 329,333 ---- } + sub lookup_action_info { my ( $self, $action_name ) = @_; *************** *** 463,466 **** --- 474,478 ---- } + ######################################## # FULLTEXT INDEXING LOOKUP *************** *** 502,505 **** --- 514,518 ---- } + ######################################## # CONTENT GENERATOR LOOKUP *************** *** 513,516 **** --- 526,530 ---- } + ######################################## # OBSERVERS *************** *** 541,544 **** --- 555,559 ---- } + ######################################## # DIRECTORY/FILE LOOKUPS *************** *** 573,576 **** --- 588,592 ---- } + ######################################## # LOOKUPS, OTHER *************** *** 616,619 **** --- 632,636 ---- } + ######################################## # CLASS LOOKUP *************** *** 628,631 **** --- 645,649 ---- } + # Config shortcut *************** *** 664,667 **** --- 682,686 ---- } + # Config shortcut *************** *** 746,749 **** --- 765,782 ---- } + + sub language_handle { + my ( $self, $lang ) = @_; + if ( $self->request and my $h = $self->request->language_handle ) { + return $h; + } + elsif ( $lang ) { + return OpenInteract2::I18N->get_handle( $lang ); + } + else { + return $DEFAULT_LANGUAGE_HANDLE; + } + } + sub cleanup_request { my ( $self ) = @_; *************** *** 856,859 **** --- 889,896 ---- # XXX: Add a cleanup handler (NOT DONE) #CTX->add_handler( 'cleanup', \&my_cleanup ); + + # Get a language handle if you're not sure whether the request will + # be around + my $handle = CTX->language_handle( $some_lang ); =head1 DESCRIPTION *************** *** 1489,1492 **** --- 1526,1543 ---- Looks up the configuration for boxes, found in the 'box' section. + =head2 Object Methods: Localization + + B<language_handle( [ $language_spec ] )> + + Typically we store the language handle in the + L<OpenInteract2::Request> object -- every user provides us with a set + of useful languages and we create a handle from that. If a request is + available then we call that for the language handle. + + But sometimes you need to access localization resources when you don't + have a request available. For that, you can call this method. If you + don't provide a language we use the one referenced in the server + configuration key 'language.default_language'. + =head1 PROPERTIES |