Download the PHP package neatous/doctrine-extensions-translatable without Composer
On this page you can find all versions of the php package neatous/doctrine-extensions-translatable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download neatous/doctrine-extensions-translatable
More information about neatous/doctrine-extensions-translatable
Files in neatous/doctrine-extensions-translatable
Package doctrine-extensions-translatable
Short Description A Doctrine extension for managing translatable entities and their translations.
License MIT
Informations about the package doctrine-extensions-translatable
Doctrine Extensions: Translatable
A Doctrine extension for managing translatable entities and their translations. This library was extracted from the KnpLabs/DoctrineBehaviors project to provide a more lightweight solution for translatable behavior.
Installation
This library is available via Composer.
First, make sure you have Composer installed. If not, you can follow the instructions here.
Then, require the package in your project:
This command will add neatous/doctrine-extensions-translatable to your composer.json file and install the necessary dependencies, including doctrine/orm, doctrine/persistence, doctrine/collections, and nette/utils.
Usage
1. Define your Translatable Entity
Your translatable entity should use the TranslatableTrait and implement TranslatableInterface.
2. Define your Translation Entity
Each translatable entity needs an associated translation entity. This entity will hold the translatable fields for a specific locale. It should use TranslationTrait and implement TranslationInterface.
3. Configure Doctrine Mapping
The EventSubscriber will automatically map the one-to-many relationship between your translatable entity and its translations. However, you need to ensure Doctrine can find your entities.
Make sure your YourEntity class includes a constructor that calls initializeTranslationsCollection():
And your YourEntityTranslation class should specify its translatable entity class:
4. Register the Event Subscriber
You need to register the EventSubscriber in your Doctrine configuration. This is typically done in your dependency injection container.
You will also need to provide an implementation of LocaleProviderInterface.
Example (Symfony services.yaml):
Example MyLocaleProvider.php:
5. Using Translatable Entities
Now you can interact with your translatable entity:
Contributing
Contributions are welcome! Please feel free to open issues or pull requests on the GitHub repository.
License
This library is open-sourced under the MIT License.
All versions of doctrine-extensions-translatable with dependencies
doctrine/orm Version ^2.14 || ^3.0
doctrine/collections Version ^2.0
doctrine/persistence Version ^3.0 || ^4.0