File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
src/Symfony/Component/Translation Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ CHANGELOG
55---
66
77 * Deprecate ` TranslatableMessage::__toString `
8+ * Add ` Symfony\Component\Translation\StaticMessage `
89
9107.3
1011---
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the Symfony package.
5+ *
6+ * (c) Fabien Potencier <fabien@symfony.com>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Symfony \Component \Translation ;
13+
14+ use Symfony \Contracts \Translation \TranslatableInterface ;
15+ use Symfony \Contracts \Translation \TranslatorInterface ;
16+
17+ class StaticMessage implements TranslatableInterface
18+ {
19+ public function __construct (
20+ private string $ message ,
21+ ) {
22+ }
23+
24+ public function getMessage (): string
25+ {
26+ return $ this ->message ;
27+ }
28+
29+ public function trans (TranslatorInterface $ translator , ?string $ locale = null ): string
30+ {
31+ return $ this ->getMessage ();
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the Symfony package.
5+ *
6+ * (c) Fabien Potencier <fabien@symfony.com>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Symfony \Component \Translation \Tests ;
13+
14+ use PHPUnit \Framework \TestCase ;
15+ use Symfony \Component \Translation \Loader \ArrayLoader ;
16+ use Symfony \Component \Translation \StaticMessage ;
17+ use Symfony \Component \Translation \Translator ;
18+
19+ class StaticMessageTest extends TestCase
20+ {
21+ public function testTrans ()
22+ {
23+ $ translator = new Translator ('en ' );
24+ $ translator ->addLoader ('array ' , new ArrayLoader ());
25+ $ translator ->addResource ('array ' , [
26+ 'Symfony is great! ' => 'Symfony est super ! ' ,
27+ ], 'fr ' , '' );
28+
29+ $ translatable = new StaticMessage ('Symfony is great! ' );
30+
31+ $ this ->assertSame ('Symfony is great! ' , $ translatable ->trans ($ translator , 'fr ' ));
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments