To use the Translatable behavior with API Platform, you must implement the TranslatableInterface and TranslationInterface on your entities. Instead of defining translatable properties directly on the main entity, you access them through the translate() method provided by the TranslatableTrait. This allows the API to return different values based on the current request locale.
1. Configure the Main Entity
Implement TranslatableInterface and use TranslatableTrait. Use the translate() method within your getters to fetch data from the translation entity.
2. Configure the Translation Entity
Implement TranslationInterface and use TranslationTrait. This entity holds the actual translatable fields (e.g., title).
3. Handle Locales via Request Headers
To make the API respond to different languages, implement a Symfony EventSubscriber that listens to the KernelEvents::REQUEST event. This subscriber should parse the Accept-Language header and set the request locale accordingly.
### Main Entity Example
```php
use Knp//... (see full example below)