├── CHANGELOG.md
├── .phpunit-watcher.yml
├── config
└── common.php
├── infection.json.dist
├── psalm.xml
├── rector.php
├── src
└── IntlMessageFormatter.php
├── LICENSE.md
├── composer.json
├── .styleci.yml
└── README.md
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Yii Translator intl Message Formatter Change Log
2 |
3 |
4 | ## 1.0.1 under development
5 |
6 | - no changes in this release.
7 |
8 | ## 1.0.0 May 13, 2021
9 |
10 | - Initial release.
--------------------------------------------------------------------------------
/.phpunit-watcher.yml:
--------------------------------------------------------------------------------
1 | watch:
2 | directories:
3 | - src
4 | - tests
5 | fileMask: '*.php'
6 | notifications:
7 | passingTests: false
8 | failingTests: false
9 | phpunit:
10 | binaryPath: vendor/bin/phpunit
11 | timeout: 180
12 |
--------------------------------------------------------------------------------
/config/common.php:
--------------------------------------------------------------------------------
1 | IntlMessageFormatter::class,
10 | ];
11 |
--------------------------------------------------------------------------------
/infection.json.dist:
--------------------------------------------------------------------------------
1 | {
2 | "source": {
3 | "directories": [
4 | "src"
5 | ]
6 | },
7 | "logs": {
8 | "text": "php:\/\/stderr",
9 | "stryker": {
10 | "report": "master"
11 | }
12 | },
13 | "mutators": {
14 | "@default": true
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/psalm.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/rector.php:
--------------------------------------------------------------------------------
1 | paths([
11 | __DIR__ . '/src',
12 | __DIR__ . '/tests',
13 | ]);
14 |
15 | // register a single rule
16 | $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
17 |
18 | // define sets of rules
19 | $rectorConfig->sets([
20 | LevelSetList::UP_TO_PHP_80,
21 | ]);
22 | };
23 |
--------------------------------------------------------------------------------
/src/IntlMessageFormatter.php:
--------------------------------------------------------------------------------
1 | format($parameters);
26 |
27 | if ($result === false) {
28 | return $message;
29 | }
30 |
31 | return $result;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright © 2008 by Yii Software (https://www.yiiframework.com/)
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions
6 | are met:
7 |
8 | * Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | * Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in
12 | the documentation and/or other materials provided with the
13 | distribution.
14 | * Neither the name of Yii Software nor the names of its
15 | contributors may be used to endorse or promote products derived
16 | from this software without specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 | POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "yiisoft/translator-formatter-intl",
3 | "type": "library",
4 | "description": "Yii Translator intl Message Formatter",
5 | "keywords": [
6 | "i18n",
7 | "formatter",
8 | "formatting"
9 | ],
10 | "homepage": "https://www.yiiframework.com/",
11 | "license": "BSD-3-Clause",
12 | "support": {
13 | "issues": "https://github.com/yiisoft/translator-formatter-intl/issues?state=open",
14 | "forum": "https://www.yiiframework.com/forum/",
15 | "wiki": "https://www.yiiframework.com/wiki/",
16 | "irc": "irc://irc.freenode.net/yii",
17 | "chat": "https://t.me/yii3en",
18 | "source": "https://github.com/yiisoft/translator-formatter-intl"
19 | },
20 | "require": {
21 | "php": "^7.4|^8.0",
22 | "ext-intl": ">=1.0.2",
23 | "lib-ICU": ">=49.0",
24 | "yiisoft/translator": "^1.0"
25 | },
26 | "require-dev": {
27 | "phpunit/phpunit": "^9.5",
28 | "rector/rector": "^0.14.3",
29 | "roave/infection-static-analysis-plugin": "^1.16",
30 | "spatie/phpunit-watcher": "^1.23",
31 | "vimeo/psalm": "^4.18"
32 | },
33 | "autoload": {
34 | "psr-4": {
35 | "Yiisoft\\Translator\\Formatter\\Intl\\": "src"
36 | }
37 | },
38 | "autoload-dev": {
39 | "psr-4": {
40 | "Yiisoft\\Translator\\Formatter\\Intl\\Tests\\": "tests"
41 | }
42 | },
43 | "extra": {
44 | "config-plugin-options": {
45 | "source-directory": "config"
46 | },
47 | "config-plugin": {
48 | "common": "common.php"
49 | }
50 | },
51 | "config": {
52 | "sort-packages": true,
53 | "allow-plugins": {
54 | "infection/extension-installer": true,
55 | "composer/package-versions-deprecated": true
56 | }
57 | },
58 | "scripts": {
59 | "test": "phpunit --testdox --no-interaction",
60 | "test-watch": "phpunit-watcher watch"
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/.styleci.yml:
--------------------------------------------------------------------------------
1 | preset: psr12
2 | risky: true
3 |
4 | version: 8
5 |
6 | finder:
7 | exclude:
8 | - docs
9 | - vendor
10 | - resources
11 | - views
12 | - public
13 | - templates
14 | not-name:
15 | - UnionCar.php
16 | - TimerUnionTypes.php
17 | - schema1.php
18 |
19 | enabled:
20 | - alpha_ordered_traits
21 | - array_indentation
22 | - array_push
23 | - combine_consecutive_issets
24 | - combine_consecutive_unsets
25 | - combine_nested_dirname
26 | - declare_strict_types
27 | - dir_constant
28 | - fully_qualified_strict_types
29 | - function_to_constant
30 | - hash_to_slash_comment
31 | - is_null
32 | - logical_operators
33 | - magic_constant_casing
34 | - magic_method_casing
35 | - method_separation
36 | - modernize_types_casting
37 | - native_function_casing
38 | - native_function_type_declaration_casing
39 | - no_alias_functions
40 | - no_empty_comment
41 | - no_empty_phpdoc
42 | - no_empty_statement
43 | - no_extra_block_blank_lines
44 | - no_short_bool_cast
45 | - no_superfluous_elseif
46 | - no_unneeded_control_parentheses
47 | - no_unneeded_curly_braces
48 | - no_unneeded_final_method
49 | - no_unset_cast
50 | - no_unused_imports
51 | - no_unused_lambda_imports
52 | - no_useless_else
53 | - no_useless_return
54 | - normalize_index_brace
55 | - php_unit_dedicate_assert
56 | - php_unit_dedicate_assert_internal_type
57 | - php_unit_expectation
58 | - php_unit_mock
59 | - php_unit_mock_short_will_return
60 | - php_unit_namespaced
61 | - php_unit_no_expectation_annotation
62 | - phpdoc_no_empty_return
63 | - phpdoc_no_useless_inheritdoc
64 | - phpdoc_order
65 | - phpdoc_property
66 | - phpdoc_scalar
67 | - phpdoc_separation
68 | - phpdoc_singular_inheritdoc
69 | - phpdoc_trim
70 | - phpdoc_trim_consecutive_blank_line_separation
71 | - phpdoc_type_to_var
72 | - phpdoc_types
73 | - phpdoc_types_order
74 | - print_to_echo
75 | - regular_callable_call
76 | - return_assignment
77 | - self_accessor
78 | - self_static_accessor
79 | - set_type_to_cast
80 | - short_array_syntax
81 | - short_list_syntax
82 | - simplified_if_return
83 | - single_quote
84 | - standardize_not_equals
85 | - ternary_to_null_coalescing
86 | - trailing_comma_in_multiline_array
87 | - unalign_double_arrow
88 | - unalign_equals
89 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | This package is deprecated and is now part of
4 | yiisoft/translator.
5 |
6 |
7 |
8 | ❌
9 |
10 |
11 | ---
12 |
13 |
14 |
15 |
16 |
17 |
Yii Translator intl Message Formatter
18 |
19 |
20 |
21 | [](https://packagist.org/packages/yiisoft/translator-formatter-intl)
22 | [](https://packagist.org/packages/yiisoft/translator-formatter-intl)
23 | [](https://github.com/yiisoft/translator-formatter-intl/actions?query=workflow%3Abuild)
24 | [](https://scrutinizer-ci.com/g/yiisoft/translator-formatter-intl/?branch=master)
25 | [](https://scrutinizer-ci.com/g/yiisoft/translator-formatter-intl/?branch=master)
26 | [](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/translator-formatter-intl/master)
27 | [](https://github.com/yiisoft/translator-formatter-intl/actions?query=workflow%3A%22static+analysis%22)
28 | [](https://shepherd.dev/github/yiisoft/translator-formatter-intl)
29 |
30 | The package provides message formatter that utilizes PHP intl extension message formatting capabilities.
31 |
32 | ## Requirements
33 |
34 | - PHP 7.4 or higher.
35 | - `intl` PHP extension 1.0.2 or higher.
36 | - `ICU` library 49.0 or higher.
37 |
38 | ## Installation
39 |
40 | The package could be installed with composer:
41 |
42 | ```shell
43 | composer require yiisoft/translator-formatter-intl --prefer-dist
44 | ```
45 |
46 | ## Configuration
47 |
48 | 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:
49 |
50 | ```php
51 | IntlMessageFormatter::class,
60 | ];
61 | ```
62 |
63 | ## General usage
64 |
65 | ### Example of usage with `yiisoft/translator`
66 |
67 | ```php
68 | /** @var \Yiisoft\Translator\Translator $translator **/
69 |
70 | $categoryName = 'moduleId';
71 | $pathToModuleTranslations = './module/messages/';
72 | $additionalCategorySource = new Yiisoft\Translator\CategorySource(
73 | $categoryName,
74 | new \Yiisoft\Translator\Message\Php\MessageSource($pathToModuleTranslations),
75 | new \Yiisoft\Translator\Formatter\Intl\IntlMessageFormatter()
76 | );
77 | $translator->addCategorySource($additionalCategorySource);
78 |
79 | $translator->translate('Test string: {str}', ['str' => 'string data'], 'moduleId', 'en');
80 | // output: Test string: string data
81 | ```
82 |
83 | ### Example of usage without `yiisoft/translator` package
84 |
85 | ```php
86 |
87 | /** @var \Yiisoft\Translator\Formatter\Intl\IntlMessageFormatter $formatter */
88 | $pattern = 'Total {count, number} {count, plural, one{item} other{items}}.';
89 | $params = ['count' => 1];
90 | $locale = 'en';
91 | echo $formatter->format($pattern, $params, $locale);
92 | // output: Total 1 item.
93 |
94 | $pattern = '{gender, select, female{Уважаемая} other{Уважаемый}} {firstname}';
95 | $params = ['gender' => null, 'firstname' => 'Vadim'];
96 | echo $formatter->format($pattern, $params, 'ru');
97 | // output: Уважаемый Vadim
98 |
99 | $pattern = '{name} is {gender} and {gender, select, female{she} male{he} other{it}} loves Yii!';
100 | $params = ['name' => 'Alexander', 'gender' => 'male'];
101 | echo $formatter->format($pattern, $params, $locale);
102 | // output: Alexander is male and he loves Yii!
103 | ```
104 |
105 | To get a list of options available for locale you're using - see [https://intl.rmcreative.ru/](https://intl.rmcreative.ru/)
106 |
107 | ## Testing
108 |
109 | ### Unit testing
110 |
111 | The package is tested with [PHPUnit](https://phpunit.de/). To run tests:
112 |
113 | ```shell
114 | ./vendor/bin/phpunit
115 | ```
116 |
117 | ### Mutation testing
118 |
119 | The package tests are checked with [Infection](https://infection.github.io/) mutation framework with
120 | [Infection Static Analysis Plugin](https://github.com/Roave/infection-static-analysis-plugin). To run it:
121 |
122 | ```shell
123 | ./vendor/bin/roave-infection-static-analysis-plugin
124 | ```
125 |
126 | ### Static analysis
127 |
128 | The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:
129 |
130 | ```shell
131 | ./vendor/bin/psalm
132 | ```
133 |
134 | ## License
135 |
136 | The Yii Translator intl Message Formatter is free software. It is released under the terms of the BSD License.
137 | Please see [`LICENSE`](./LICENSE.md) for more information.
138 |
139 | Maintained by [Yii Software](https://www.yiiframework.com/).
140 |
141 | ## Support the project
142 |
143 | [](https://opencollective.com/yiisoft)
144 |
145 | ## Follow updates
146 |
147 | [](https://www.yiiframework.com/)
148 | [](https://twitter.com/yiiframework)
149 | [](https://t.me/yii3en)
150 | [](https://www.facebook.com/groups/yiitalk)
151 | [](https://yiiframework.com/go/slack)
152 |
--------------------------------------------------------------------------------