@@ -25,54 +25,32 @@ The package provides message storage backend based on PHP arrays to be used with
2525
2626The package could be installed with composer:
2727
28- ``` bash
29- composer require yiisoft/translator-message-php --prefer-dist
28+ ``` shell
29+ composer require yiisoft/translator-message-php
3030```
3131
32- ## Configuration
32+ ## General usage
3333
34- In case you use [ ` yiisoft/config ` ] ( http ://github.com/yiisoft/config ) , you will get configuration automatically. If not, the following DI container configuration is necessary :
34+ The package is meant to be used with [ ` yiisoft/translator ` ] ( https ://github.com/yiisoft/translator ) :
3535
3636``` php
37- <?php
38-
39- declare(strict_types=1);
40-
41- use Yiisoft\Translator\MessageReaderInterface;
37+ use Yiisoft\Translator\CategorySource;
38+ use Yiisoft\Translator\IntlMessageFormatter;
4239use Yiisoft\Translator\Message\Php\MessageSource;
43- use Yiisoft\Aliases\Aliases;
44-
45- return [
46- MessageReaderInterface::class => [
47- 'class' => MessageSource::class,
48- '__construct()' => [
49- DynamicReference::to(fn (Aliases $aliases) => $aliases->get('@messages')),
50- ],
51- ],
52- ];
53- ```
54-
55- > Make sure the ` @messages ` alias is in the ` aliases ` section of ` $params `
5640
57- ** Note:** You can use absolutely path to translation files, if you not use [ ` yiisoft/aliases ` ] ( https://github.com/yiisoft/aliases )
58- ``` php
59- MessageReaderInterface::class => [
60- 'class' => MessageSource::class,
61- '__construct()' => [
62- '/var/www/app/resources/messages',
63- ],
64- ],
41+ $categorySource = new CategorySource(
42+ 'my-category',
43+ new MessageSource('/path/to/messages'),
44+ new IntlMessageFormatter(),
45+ );
6546```
6647
67- ## General usage
68-
69- The package is meant to be used with [ ` yiisoft/translator ` ] ( https://github.com/yiisoft/translator ) . The examples below
70- are about using it separately.
48+ The examples below are about using it separately.
7149
7250### Create an instance of message source
7351
7452``` php
75- /** @var string $path - path to your translations */
53+ /** @var string $path - full path to your translations */
7654$messageSource = new \Yiisoft\Translator\Message\Php\MessageSource($path);
7755```
7856
0 commit comments