johnkhansrc / api-platform-stream-translate-bundle
A lightweight extension allowing to translate in the ApiPlatform flow the values of the properties of an entity by a simple annotation.
Installs: 875
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 1
Type:symfony-bundle
Requires
- php: ^8.3
- api-platform/core: ^3.1
- doctrine/annotations: ^2.0
- doctrine/collections: ^2.0
- doctrine/persistence: ^3.2
- symfony/dependency-injection: ^v6.4
- symfony/translation: 6.4.*
Requires (Dev)
- phpstan/phpstan: ^1.10
README
A lightweight extension allowing to translate in the ApiPlatform flow the properties values of an entity by a simple annotation.
Requirements
- symfony/translation >=5.4
- api-platform/core: >=2.5
- doctrine/annotations >=1.0
Instalation
composer require johnkhansrc/api-platform-stream-translate-bundle
Update your services.yaml
# Using annotation Johnkhansrc\ApiPlatformStreamTranslateBundle\EventListener\StreamTranslateAnnotationListener: ~ # Or Using attribute Johnkhansrc\ApiPlatformStreamTranslateBundle\EventListener\StreamTranslateAttributeListener: ~
Usage
Annotation
use Johnkhansrc\ApiPlatformStreamTranslateBundle\Annotation\StreamTranslate; /** * @ApiResource * @ORM\Entity(repositoryClass=AnyEntityRepository::class) */ class AnyEntity { /** * @ORM\Id */ private $id; /** * Expect translation file anyDomain.xx.yaml who contain 'anykey' key * * @StreamTranslate(domain="anyDomain", key="anyKey") */ private string $anyStringPropertyKeyBasedExample; /** * Expect translation file anyDomain.xx.yaml who contain property value as key * * @StreamTranslate(domain="anyDomain") */ private string $anyStringPropertyNoKeyBasedExample; /** * * * NEW ON 2.0.0 * * * * Iterate on each embed relation, don't forget do annotate related class properties. * Tips: You can use different domain on related class property's annotation. * * @StreamTranslate(domain="anyDomain", childs=true) */ private ArrayCollection $anyStringPropertyNoKeyBasedExample; }
Attribute
use Johnkhansrc\ApiPlatformStreamTranslateBundle\Attribute\StreamTranslate; /** * @ApiResource * @ORM\Entity(repositoryClass=AnyEntityRepository::class) */ class AnyEntity { /** * @ORM\Id */ private $id; /** * Expect translation file anyDomain.xx.yaml who contain 'anykey' key */ #[StreamTranslate(domain: "anyDomain", key: "anyKey")] private string $anyStringPropertyKeyBasedExample; /** * Expect translation file anyDomain.xx.yaml who contain property value as key */ #[StreamTranslate(domain: "anyDomain")] private string $anyStringPropertyNoKeyBasedExample; /** * * * NEW ON 2.0.0 * * * * Iterate on each embed relation, don't forget do annotate related class properties. * Tips: You can use different domain on related class property's annotation. */ #[StreamTranslate(domain: "anyDomain", childs: true)] private ArrayCollection $anyStringPropertyNoKeyBasedExample; }