a2lix/translation-form-bundle
Composer 安装命令:
composer require a2lix/translation-form-bundle
包简介
Translate your doctrine objects easily with some helpers
关键字:
README 文档
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.
a2lix/translation-form-bundle 适用场景与选型建议
a2lix/translation-form-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.1M 次下载、GitHub Stars 达 338, 最近一次更新时间为 2012 年 06 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「i18n」 「translation」 「form」 「knplabs」 「doctrine2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 a2lix/translation-form-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 a2lix/translation-form-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 a2lix/translation-form-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use i18n translation PHP class for multi-language websites
A custom URL rule class for Yii 2 which allows to create translated URL rules
The bundle for easy using json-rpc api on your project
A Laravel Eloquent model trait for translatable resource
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Nette Framework adapter for I18n package
统计信息
- 总下载量: 7.1M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 345
- 点击次数: 35
- 依赖项目数: 52
- 推荐数: 3
其他信息
- 授权协议: MIT
- 更新时间: 2012-06-28
