Manual:Message.php/ceb
MW 1.43+
MediaWiki file: Message.php | |
---|---|
Location: | includes/language/Message/ |
Source code: | master • 1.42.4 • 1.41.5 • 1.39.11 |
Classes: | MediaWiki\Message\Message |
MW 1.42 only
MediaWiki file: Message.php | |
---|---|
Location: | includes/Message/ |
Source code: | master • 1.42.4 • 1.41.5 • 1.39.11 |
Classes: | MediaWiki\Message\Message |
MW 1.41 and earlier
MediaWiki file: Message.php | |
---|---|
Location: | includes/language/ |
Source code: | master • 1.42.4 • 1.41.5 • 1.39.11 |
Classes: | Message |
The Message class deals with fetching and processing of interface message into a variety of formats.
It is intended to replace the old wfMsg*
functions that over time grew unusable.
See Manual:Messages API for equivalences between old and new functions.
Usage
The preferred way to create Message objects is via the msg()
method of an available RequestContext and ResourceLoader Context object; this will ensure that the message uses the correct language.
When that is not possible, the wfMessage() global function can be used, which will cause Message to get the language from the global RequestContext object.
In rare circumstances when sessions are not available or not initialized, that can lead to errors.
The most basic usage cases would be:
// Initialize a Message object using the 'some_key' message key
$message = $context->msg( 'some_key' );
// Using two parameters whose values are strings 'value1' and 'value2':
$message = $context->msg( 'some_key',
'value1', 'value2'
);
Global function wrapper
Since msg() returns a Message instance, you can chain its call with a method. Some of them return a Message instance too so you can chain them. You will find below several examples of msg() usage.
Fetching a message text for interface message:
$button = Xml::button(
$context->msg( 'submit' )->text()
);
A Message instance can be passed parameters after it has been constructed, use the params() method to do so:
$context->msg( 'welcome-to' )
->params( $wgSitename )
->text();
{GRAMMAR}} and friends work correctly:
$context->msg( 'are-friends',
$user, $friend
);
$context->msg( 'bad-message' )
->rawParams( '<script>...</script>' )
->escaped();
Pag-usab sa pinulongan
Ang mga mensahe mahimong hangyoon sa laing pinulongan o sa kasamtangang pinulongan nga gigamit sa sulod.
Ang mga pamaagi mao ang:
- Message->inContentLanguage()
- Message->inLanguage()
Usahay ang teksto sa mensahe mosulod sa database, busa kinahanglan ang pinulongan sa sulod.
wfMessage( 'file-log',
$user, $filename
)->inContentLanguage()->text();
Pagsusi kung ang mensahe naga-exist:
$context->msg( 'mysterious-message' )->exists()
// returns a boolean whether the 'mysterious-message' key exist.
Kung gusto nimo gamiton ang laing pinulongan:
$userLanguage = $user->getOption( 'language' );
wfMessage( 'email-header' )
->inLanguage( $userLanguage )
->plain();
Mahimo ra nimo i-parse ang teksto sa mga sulod o interface nga mga pinulongan.