From: Chris W. <la...@us...> - 2004-10-24 15:04:11
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26002 Modified Files: Action.pm Log Message: add message_from_key_or_param() as shortcut to pull a messge from a localization key or an action parameter Index: Action.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Action.pm,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** Action.pm 27 Sep 2004 05:01:56 -0000 1.55 --- Action.pm 24 Oct 2004 15:03:52 -0000 1.56 *************** *** 875,878 **** --- 875,893 ---- } + # confusing name -- the title would suggest we want the message key + # first, but we want to also pass along optional arguments to the + # message key and they should be next to the key argument... + + sub message_from_key_or_param { + my ( $self, $param_name, $message_key, @key_args ) = @_; + if ( $message_key ) { + my $language_handle = CTX->request->language_handle; + my $msg = $language_handle->maketext( $message_key, @key_args ); + return $msg if ( $msg ); + } + return $self->param( $param_name ); + } + + sub view_messages { my ( $self, $messages ) = @_; *************** *** 2460,2463 **** --- 2475,2498 ---- Returns: nothing + B<message_from_param_or_key( $param_name, $message_key, @key_arguments )> + + Shortcut for returning a message from either the localized message + store or from the given parameter. For instance, you might have an + action configured: + + [myaction] + title = This is a generic title + title_key = mypkg.myaction.title + + If you call: + + my $msg = $myaction->message_from_param_or_key( 'title', 'title_key' ); + + The C<$msg> variable should have whatever is in the localization table + for 'mypkg.myaction.title'. If 'title_key' wasn't defined the method + would return 'This is a generic title'. + + Returns: message from localization tables or from the action parameter + B<view_messages( [ \%messages ] )> |