Jump to content

Message (PHP library)

From mediawiki.org

Message, provides interfaces and value objects for internationalization (i18n) of applications in PHP, using 'en' as the default language code.

Installing

[edit]

To use it inside your application, run composer require wikimedia/message, or add a dependency in your composer.json.

If you prefer using git, that's also an option: git clone https://gerrit.wikimedia.org/r/mediawiki/libs/Message, and autoload the library however you wish to.

If you wish to develop and contribute on the library, see developer account for gaining access to our code review system.

Usage

[edit]
use Wikimedia\Message\MessageValue;
use Wikimedia\Message\MessageParam;
use Wikimedia\Message\ParamType;

// Constructor interface
$message = new MessageValue( 'message-key', [
    'parameter',
    new MessageValue( 'another-message' ),
    new MessageParam( ParamType::NUM, 12345 ),
] );

// Fluent interface
$message = MessageValue::new( 'message-key' )
    ->params( 'parameter', new MessageValue( 'another-message' ) )
    ->numParams( 12345 );

// Formatting
$messageFormatter = $serviceContainer->get( 'MessageFormatterFactory' )->getTextFormatter( 'de' );
$output = $messageFormatter->format( $message );
[edit]