professional-wiki/message-builder

Mini message localization library with MessageBuilder interface and implementations

1.0.1 2025-02-21 13:41 UTC

This package is auto-updated.

Last update: 2025-02-21 13:55:31 UTC


README

GitHub Workflow Status Type Coverage codecov Latest Stable Version Download count License

Message Builder is a small message localization library for PHP.

This library was extracted from the EDTF library. It can be used together with TranslateWiki, though does not depend on it.

MessageBuilder interface

interface MessageBuilder {
	/**
	 * @throws UnknownMessageKey
	 */
	public function buildMessage( string $messageKey, string ...$arguments ): string;
}

Usage

$messageBuilder = new ArrayMessageBuilder( [ 
	'hello-something' => 'Hello, $1!',
	'multi-argument-example' => 'foo $2 $1 bar $3', 
	'plural-example' => 'You have $1 {{plural:$1|item|items}} in your cart.',
] );

function someCode( MessageBuilder $messageBuilder ) {
	// Returns 'Hello, world!'
	$messageBuilder->getMessage( 'hello-something', [ 'world' ] );
}

For a real world usage example, see the EDTF library.

Implementations

  • ArrayMessageBuilder - In-memory message builder with PLURAL keyword support
  • FallbackMessageBuilder - Fallback message builder that delegates to multiple message builders
  • MessageBuilderSpy - Message builder that records all messages built for testing

Development

Start by installing the project dependencies by executing

composer install

You can run test and static analysis via Make. See Makefile for available commands. If you do not have Make, you can run the commands listed in the Makefile manually.

To run all checks run by the GitHub Actions CI, simply run make.

Release notes

Version 1.0.1 (2025-02-21)

  • Removed superfluous ext-json dependency.

Version 1.0.0 (2025-02-20)

  • Initial release with ArrayMessageBuilder, FallbackMessageBuilder, and MessageBuilderSpy implementations.