a2lix / translation-form-bundle
Translate your doctrine objects easily with some helpers
Installs: 6 682 341
Dependents: 57
Suggesters: 2
Security: 0
Stars: 332
Watchers: 11
Forks: 138
Open Issues: 0
Type:symfony-bundle
pkg:composer/a2lix/translation-form-bundle
Requires
- php: ^8.4
- a2lix/auto-form-bundle: ^1.0
- symfony/config: ^7.4|^8.0
- symfony/dependency-injection: ^7.4|^8.0
- symfony/doctrine-bridge: ^7.4|^8.0
- symfony/event-dispatcher: ^7.4|^8.0
- symfony/form: ^7.4|^8.0
- symfony/http-kernel: ^7.4|^8.0
- symfony/intl: ^7.4|^8.0
- symfony/options-resolver: ^7.4|^8.0
- symfony/translation: ^7.4|^8.0
- symfony/ux-twig-component: ^2.31
Requires (Dev)
- doctrine/orm: ^3.5.8
- friendsofphp/php-cs-fixer: ^3.91.3
- knplabs/doctrine-behaviors: ^3.0.0
- kubawerlos/php-cs-fixer-custom-fixers: ^3.35.1
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.1.33
- phpstan/phpstan-doctrine: ^2.0.12
- phpstan/phpstan-phpunit: ^2.0.10
- phpstan/phpstan-strict-rules: ^2.0.7
- phpstan/phpstan-symfony: ^2.0.9
- phpunit/phpunit: ^12.5.2
- rector/rector: ^2.2.14
- stof/doctrine-extensions-bundle: ^1.14
- symfony/cache: ^7.4.1|^8.0.1
- symfony/validator: ^7.4|^8.0.2
- symfony/var-dumper: ^7.4
Suggests
- knplabs/doctrine-behaviors: For Knp strategy
- prezent/doctrine-translatable-bundle: For Prezent strategy
- stof/doctrine-extensions-bundle: For Gedmo strategy
- dev-master
- dev-main / 4.x-dev
- 4.0.1
- 4.0.0
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.10
- 3.0.9
- 3.0.8
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 3.0.0-beta.1
- 2.x-dev
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.2
- 2.1.1
- 2.1
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.x-dev
- 1.3
- 1.2
- 1.1
- 1.0
- 0.x-dev
- 0.4.0
- 0.3.10
- 0.3.9
- 0.3.8
- 0.3.5
- 0.3.0
- 0.2.0
- dev-draft
This package is auto-updated.
Last update: 2025-12-11 17:10:16 UTC
README
A small, flexible Symfony bundle that helps you build forms to manage translations for Doctrine entities. It integrates with common translation strategies (Gedmo Personal Translation and Knp DoctrineBehaviors) and provides form types, helpers and Twig components to make working with multilingual data easier.
Key features
- Easy form handling for translatable entities (Knp & Gedmo strategies).
- Support for one-record-per-locale patterns via
TranslationsFormsType. TranslatedEntityTypefor entity choice labels using translations.- Centralized locale configuration via
LocaleProvider. - Twig helpers and a
LocaleSwitchercomponent.
Note
Use A2lixAutoFormBundle for automatic form generation and customization.
Tip
A complete demonstration is also available at a2lix/demo.
Screenshot example
Installation
- Install the bundle with Composer:
composer require a2lix/translation-form-bundle
Basic configuration
Add a minimal configuration in config/packages/a2lix.yaml:
a2lix_translation_form: enabled_locales: [en, fr, de] # Optional. Default from framework.enabled_locales default_locale: en # Optional. Default from framework.default_locale required_locales: [en] # Optional. Default [] # templating: "@A2lixTranslationForm/bootstrap_5_layout.html.twig"
If you keep the default setup, the bundle will automatically prepend the chosen form theme (Bootstrap 5 layout by default) into Twig's form_themes.
Compatibility: Gedmo & Knp
- Gedmo PersonalTranslation: Fully supported. When using Gedmo's personal translation mapping, the bundle renders translation fields as separate translation objects and manages creation and removal of
Gedmotranslation entities. - KnpDoctrineBehaviors: Fully supported. For Knp-style translations (one translation object per locale), fields are bound directly to locale forms.
Usage examples
TranslationsType (Knp or Gedmo)
use A2lix\TranslationFormBundle\Form\Type\TranslationsType; use Symfony\Component\Form\Extension\Core\Type\FormType; $builder->add('translations', TranslationsType::class, [ 'translatable_class' => App\Entity\Post::class, // Optional: // 'locale_labels' => ['en' => 'English', 'fr' => 'Français'], // 'theming_granularity' => 'field', // or 'locale_field' ]);
TranslationsFormsType (one-record-per-locale)
use A2lix\TranslationFormBundle\Form\Type\TranslationsFormsType; $builder->add('medias', TranslationsFormsType::class, [ 'form_type' => App\Form\CompanyMediaType::class, 'form_options' => [ 'data_class' => App\Entity\CompanyMediaLocale::class, ], ]);
TranslatedEntityType (entity choices with translation labels)
use A2lix\TranslationFormBundle\Form\Type\TranslatedEntityType; $builder->add('category', TranslatedEntityType::class, [ 'class' => App\Entity\Category::class, 'translation_property' => 'title', ]);
Locale selection widget
use A2lix\TranslationFormBundle\Form\Type\TranslationsLocalesSelectorType; $builder->add('locales', TranslationsLocalesSelectorType::class, [ // uses the bundle's LocaleProvider to populate choices ]);
Twig helpers & components
Locale rendering function:
{{ locale_render('en') }} {# -> 'English' (localized) #}
{{ locale_render('en', 'locale_upper') }} {# -> 'EN' #}
{{ locale_render('fr', 'locale_name_title') }}{# -> 'Français' #}
LocaleSwitcher component:
{# Render basic badges #} <twig:A2lixTranslationForm:LocaleSwitcher render="basic" /> {# Render dropdown #} <twig:A2lixTranslationForm:LocaleSwitcher render="dropdown" />
LocaleProvider
The bundle centralizes locale configuration through a LocaleProviderInterface. By default, SimpleLocaleProvider is registered and configured from bundle settings. You can replace it with your own service by changing locale_provider in the bundle configuration.
Integration with AutoFormBundle
This bundle integrates cleanly with a2lix/auto-form-bundle. When using AutoType with translatable entities, TranslationsType and TranslationsFormsType can be automatically configured and rendered based on entity metadata and bundle options.
License
This package is available under the MIT license — see the LICENSE file.
