-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Symfony's
TranslatableInterface
in enum fields (#8212)
- Loading branch information
1 parent
f82eb21
commit bed2aaf
Showing
5 changed files
with
146 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Tests\Fixtures\Enum; | ||
|
||
use Symfony\Contracts\Translation\TranslatableInterface; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
enum TranslatableSuit: string implements TranslatableInterface | ||
{ | ||
case Hearts = 'hearts'; | ||
case Diamonds = 'diamonds'; | ||
case Clubs = 'clubs'; | ||
case Spades = 'spades'; | ||
|
||
#[\Override] | ||
public function trans(TranslatorInterface $translator, ?string $locale = null): string | ||
{ | ||
return $translator->trans( | ||
id: 'enum.suit.'.$this->value, | ||
domain: 'render-element-extension-test', | ||
locale: $locale, | ||
); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/Fixtures/Resources/translations/render-element-extension-test.en.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
D: '[trans]D[/trans]' | ||
Diamonds: '[trans]Diamonds[/trans]' | ||
enum: | ||
suit: | ||
hearts: '[trans]enum.suit.hearts[/trans]' | ||
diamonds: '[trans]enum.suit.diamonds[/trans]' | ||
clubs: '[trans]enum.suit.clubs[/trans]' | ||
spades: '[trans]enum.suit.spades[/trans]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters