johnkhansrc / api-platform-stream-translate-bundle
一个轻量级的扩展,允许通过简单的注解在ApiPlatform流程中翻译实体属性的值。
3.2.0
2023-12-01 12:41 UTC
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
一个轻量级的扩展,允许通过简单的注解在ApiPlatform流程中翻译实体的属性值。
要求
- symfony/translation >=5.4
- api-platform/core: >=2.5
- doctrine/annotations >=1.0
安装
composer require johnkhansrc/api-platform-stream-translate-bundle
更新你的services.yaml
# Using annotation Johnkhansrc\ApiPlatformStreamTranslateBundle\EventListener\StreamTranslateAnnotationListener: ~ # Or Using attribute Johnkhansrc\ApiPlatformStreamTranslateBundle\EventListener\StreamTranslateAttributeListener: ~
使用方法
注解
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; }
属性
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; }