https://github.com/professionalwiki/messagebuilder
Mini library with MessageBuilder interface and implementations for message localization
https://github.com/professionalwiki/messagebuilder
Last synced: 2 months ago
JSON representation
Mini library with MessageBuilder interface and implementations for message localization
- Host: GitHub
- URL: https://github.com/professionalwiki/messagebuilder
- Owner: ProfessionalWiki
- License: gpl-2.0
- Created: 2025-02-20T15:58:34.000Z (2 months ago)
- Default Branch: master
- Last Pushed: 2025-02-20T21:29:09.000Z (2 months ago)
- Last Synced: 2025-02-20T21:30:32.558Z (2 months ago)
- Language: PHP
- Size: 16.6 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Message Builder
[](https://github.com/ProfessionalWiki/MessageBuilder/actions?query=workflow%3ACI)
[](https://shepherd.dev/github/ProfessionalWiki/MessageBuilder)
[](https://codecov.io/gh/ProfessionalWiki/MessageBuilder)
[](https://packagist.org/packages/professional-wiki/message-builder)
[](https://packagist.org/packages/professional-wiki/message-builder)
[](LICENSE)Message Builder is a small message localization library for PHP.
This library was extracted from the [EDTF library](https://github.com/ProfessionalWiki/EDTF).
It can be used together with [TranslateWiki](https://translatewiki.net/), though does not depend on it.## MessageBuilder interface
```php
interface MessageBuilder {
/**
* @throws UnknownMessageKey
*/
public function buildMessage( string $messageKey, string ...$arguments ): string;
}
```## Usage
```php
$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](https://github.com/ProfessionalWiki/EDTF).
## 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.0 (2025-02-20)
* Initial release with `ArrayMessageBuilder`, `FallbackMessageBuilder`, and `MessageBuilderSpy` implementations.