百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

TranslationFormBundle

> 数据库
开源

利用一些专用的 Symfony 表单类型简化翻译

337 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

利用一些专用的 Symfony 表单类型简化翻译

A2lix TranslationForm Bundle

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.
  • TranslatedEntityType for entity choice labels using translations.
  • Centralized locale configuration via LocaleProvider.
  • Twig helpers and a LocaleSwitcher component.

[!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:
bash
composer require a2lix/translation-form-bundle

Basic configuration

Add a minimal configuration in config/packages/a2lix.yaml:

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 Gedmo translation 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)

php
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)

php
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)

php
use A2lix\TranslationFormBundle\Form\Type\TranslatedEntityType;

$builder->add('category', TranslatedEntityType::class, [
    'class' => App\Entity\Category::class,
    'translation_property' => 'title',
]);

Locale selection widget

php
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:

twig
{{ locale_render('en') }}                     {# -> 'English' (localized) #}
{{ locale_render('en', 'locale_upper') }}     {# -> 'EN' #}
{{ locale_render('fr', 'locale_name_title') }}{# -> 'Français' #}

LocaleSwitcher component:

twig
{# Render basic badges #}

{# 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.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPbundledoctrinephpsymfony

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库