toovalu-github/translation-form-bundle
Composer 安装命令:
composer require toovalu-github/translation-form-bundle
包简介
Translate your doctrine objects easily with some helpers
关键字:
README 文档
README
Translate your doctrine objects easily with some helps
| Branch | Tools |
|---|---|
| 3.x (master) |
Screenshot example
Support
3.xdepends on AutoFormBundle and has higher requirements (PHP8.1+, Symfony5.4+/6.3+/7.0+). It is compatible with KnpLabs, A2lix and Prezent
Installation
Use composer:
composer require a2lix/translation-form-bundle
After the successful installation, add/check the bundle registration:
// Symfony >= 4.0 in bundles.php // ... A2lix\AutoFormBundle\A2lixAutoFormBundle::class => ['all' => true], A2lix\TranslationFormBundle\A2lixTranslationFormBundle::class => ['all' => true], // ... // Symfony >= 3.4 in AppKernel::registerBundles() $bundles = array( // ... new A2lix\AutoFormBundle\A2lixAutoFormBundle(), new A2lix\TranslationFormBundle\A2lixTranslationFormBundle(), // ...
Configuration
There is no minimal configuration. Full list of optional parameters:
# Symfony >= 4.0. Create a dedicated a2lix.yaml in config/packages with: # Symfony >= 3.4. Add in your app/config/config.yml: a2lix_translation_form: locale_provider: default # [1] locales: [en, fr, es, de] # [1-a] default_locale: en # [1-b] required_locales: [fr] # [1-c] templating: "@A2lixTranslationForm/bootstrap_4_layout.html.twig" # [2]
- Custom locale provider service id. Default one relies on [1-*] values:
- [1-a] List of translations locales to display
- [1-b] Default locale
- [1-c] List of required translations locales
- The default template is Twitter Bootstrap compatible. You can redefine your own here
Usage
In a classic formType
use A2lix\TranslationFormBundle\Form\Type\TranslationsType; ... $builder->add('translations', TranslationsType::class);
Advanced examples
use A2lix\TranslationFormBundle\Form\Type\TranslationsType; ... $builder->add('translations', TranslationsType::class, [ 'locales' => ['en', 'fr', 'es', 'de'], // [1] 'default_locale' => ['en'], // [1] 'required_locales' => ['fr'], // [1] 'fields' => [ // [2] 'description' => [ // [3.a] 'field_type' => 'textarea', // [4] 'label' => 'descript.', // [4] 'locale_options' => [ // [3.b] 'es' => ['label' => 'descripción'], // [4] 'fr' => ['display' => false] // [4] ] ] ], 'excluded_fields' => ['details'], // [2] 'locale_labels' => [ // [5] 'fr' => 'Français', 'en' => 'English', ], ]);
- Optional. If set, override the default value from config.yml
- Optional. If set, override the default value from config.yml
- Optional. If set, override the auto configuration of fields
- [3.a] Optional. - For a field, applied to all locales
- [3.b] Optional. - For a specific locale of a field
- Optional. Common options of symfony forms (max_length, required, trim, read_only, constraints, ...), which was added 'field_type' and 'display'
- Optional. Set the labels for the translation tabs. Default to the name of the locale. Translation keys can be used here.
Additional
TranslationsFormsType
A different approach for entities which don't share fields untranslated. No strategy used here, only a locale field in your entity.
use A2lix\TranslationFormBundle\Form\Type\TranslationsFormsType; ... $builder->add('translations', TranslationsFormsType::class, [ 'locales' => ['en', 'fr', 'es', 'de'], // [1] 'default_locale' => ['en'] // [1] 'required_locales' => ['fr'], // [1] 'form_type' => ProductMediaType::class, // [2 - Mandatory] 'form_options' => [ // [2bis] 'context' => 'pdf' ] ]);
- Optional. If set, override the default value from config.yml
- Mandatory. A real form type that you have to do
- [2bis] Optional. - An array of options that you can set to your form
TranslatedEntityType
Modified version of the native 'entity' symfony form type to translate the label in the current locale by reading translations
use A2lix\TranslationFormBundle\Form\Type\TranslatedEntityType; ... $builder->add('medias', TranslatedEntityType::class, [ 'class' => 'A2lix\DemoTranslationBundle\Entity\Media', // [1 - Mandatory] 'translation_property' => 'title', // [2 - Mandatory] 'multiple' => true, // [3] ]);
- Path of the translatable class
- Property/Method of the translatable class that will be display
- Common options of the 'entity' Symfony form type (multiple, ...)
Example
See Demo Bundle for more examples.
Contribution help
docker run --rm --interactive --tty --volume $PWD:/app --user $(id -u):$(id -g) composer install --ignore-platform-reqs
docker run --rm --interactive --tty --volume $PWD:/app --user $(id -u):$(id -g) composer run-script phpunit
docker run --rm --interactive --tty --volume $PWD:/app --user $(id -u):$(id -g) composer run-script cs-fixer
License
This package is available under the MIT license.
toovalu-github/translation-form-bundle 适用场景与选型建议
toovalu-github/translation-form-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.75k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「i18n」 「translation」 「form」 「knplabs」 「doctrine2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 toovalu-github/translation-form-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 toovalu-github/translation-form-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 toovalu-github/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
统计信息
- 总下载量: 3.75k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-09
