PHP code example of johnkhansrc / api-platform-stream-translate-bundle

1. Go to this page and download the library: Download johnkhansrc/api-platform-stream-translate-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

johnkhansrc / api-platform-stream-translate-bundle example snippets


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;
}