File tree Expand file tree Collapse file tree
src/Symfony/Component/Translation/Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -71,6 +71,9 @@ public function assertCatalogue(MessageCatalogue $catalogue): void
7171 'translatable-short-fqn ' .$ expectedNowdoc => 'prefixtranslatable-short-fqn ' .$ expectedNowdoc ,
7272 'translatable-short-fqn concatenated message with heredoc and nowdoc ' => 'prefixtranslatable-short-fqn concatenated message with heredoc and nowdoc ' ,
7373 'translatable-short-fqn default domain ' => 'prefixtranslatable-short-fqn default domain ' ,
74+ 'text_align.left.label ' => 'prefixtext_align.left.label ' ,
75+ 'text_align.center.label ' => 'prefixtext_align.center.label ' ,
76+ 'text_align.right.label ' => 'prefixtext_align.right.label ' ,
7477 ],
7578 'not_messages ' => [
7679 'other-domain-test-no-params-short-array ' => 'prefixother-domain-test-no-params-short-array ' ,
@@ -111,5 +114,7 @@ public function assertCatalogue(MessageCatalogue $catalogue): void
111114
112115 $ this ->assertEquals (['sources ' => [self ::FIXTURES_FOLDER . 'translatable-short-fqn.html.php:2 ' ]], $ catalogue ->getMetadata ('translatable-short-fqn single-quoted key ' ));
113116 $ this ->assertEquals (['sources ' => [self ::FIXTURES_FOLDER . 'translatable-short-fqn.html.php:37 ' ]], $ catalogue ->getMetadata ('translatable-short-fqn other-domain-test-no-params-short-array ' , 'not_messages ' ));
117+
118+ $ this ->assertEquals (['sources ' => [self ::FIXTURES_FOLDER . 'translatable-backed-enum.html.php:17 ' ]], $ catalogue ->getMetadata ('text_align.left.label ' ));
114119 }
115120}
Original file line number Diff line number Diff line change 1+ This template is used for translation message extraction tests
2+ <?php
3+ // @See https://symfony.com/doc/current/reference/forms/types/enum.html#example-usage
4+
5+ use Symfony \Contracts \Translation \TranslatableInterface ;
6+ use Symfony \Contracts \Translation \TranslatorInterface ;
7+
8+ enum TextAlign: string implements TranslatableInterface
9+ {
10+ case Left = 'Left aligned ' ;
11+ case Center = 'Center aligned ' ;
12+ case Right = 'Right aligned ' ;
13+
14+ public function trans (TranslatorInterface $ translator , ?string $ locale = null ): string
15+ {
16+ return match ($ this ) {
17+ self ::Left => $ translator ->trans ('text_align.left.label ' , locale: $ locale ),
18+ self ::Center => $ translator ->trans ('text_align.center.label ' , locale: $ locale ),
19+ self ::Right => $ translator ->trans ('text_align.right.label ' , locale: $ locale ),
20+ };
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments