Last modified: 2013-04-23 13:23:54 UTC
Random idea from something PleaseStand said. Message instances could explicitly support taking a message object as a parameter. This way the message could inherit the context it's parent is in (eg: language). Especially useful if the message instance is going to be passed somewhere else and the context changed. $this->msg( 'foo' )->params( wfMessage( 'bar' )->params( 'foo' ) )->inLanguage( 'en_CA' );
That looks potentially confusing to unaware reader.
Is it? It's basically: wfMessage( 'foo' ) ->inLanguage( 'en_CA' ) ->params( wfMessage( 'bar' ) ->params( 'foo' ) ); vs. wfMessage( 'foo' ) ->inLanguage( 'en_CA' ) ->params( wfMessage( 'bar' ) ->params( 'foo' ) ->inLanguage( 'en_CA' ) );
Well... actually right now you kind of need to do: wfMessage( 'foo' ) ->inLanguage( 'en_CA' ) ->params( wfMessage( 'bar' ) ->params( 'foo' ) ->inLanguage( 'en_CA' ) ->plain() ); Since __toString defaults to parse.
This could be further extended by allowing use of closures. Simple example (using a helper function textCB()): wfMessage( 'foo', wfMessage( 'bar', 'foo' )->textCB() )->inLanguage( 'en_CA' ); More complex example: $tsHTML = function ( $ctx ) use ( $ts ) { return Html::element( 'span', array( 'title' => wfTimestamp( TS_ISO_8601, $ts ) ), $ctx->getLanguage()->timeanddate( $ts ), ); ); }; wfMessage( 'bar' )->rawParams( $tsHTML )->inLanguage( 'en_CA' ); where MessageContext $ctx would only implement msg(), getLanguage(), getContentLanguage(), and getTitle(), to ensure that all relevant information is actually included in the Message object being passed around. Unfortunately, my specific case (the one I discussed with Daniel Friesen on IRC) requires $ctx->getRequest()->getIP(); however, this may come in handy elsewhere.