professional-wiki / message-builder
Mini message localization library with MessageBuilder interface and implementations
1.0.1
2025-02-21 13:41 UTC
Requires
- php: ^8.1
Requires (Dev)
- phpstan/phpstan: ^2.1.6
- phpunit/phpunit: ^10.5.45
- vimeo/psalm: ^6.8.4
This package is auto-updated.
Last update: 2025-02-21 13:55:31 UTC
README
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 supportFallbackMessageBuilder
- Fallback message builder that delegates to multiple message buildersMessageBuilderSpy
- 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
, andMessageBuilderSpy
implementations.