koff / i18n-form-bundle
使用一些帮助轻松翻译 doctrine 对象
v4.0.7
2018-01-12 10:17 UTC
Requires
- php: ^7.0.8
- doctrine/doctrine-bundle: ^1.6.10
- doctrine/orm: ^2.5
- symfony/config: ~3.4|~4.0
- symfony/dependency-injection: ~3.4|~4.0
- symfony/form: ~3.4|~4.0
- symfony/http-kernel: ~3.4|~4.0
- symfony/twig-bundle: ~3.4|~4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.8
- symfony/phpunit-bridge: ^3.4|^4.0
- symfony/validator: ^3.4|^4.0
- symfony/yaml: ^3.4|^4.0
Suggests
- knplabs/doctrine-behaviors: For Knp strategy
- stof/doctrine-extensions-bundle: For Atlantic18/DoctrineExtensions
README
此包是从a2lix/TranslationFormBundle派生而来,经过重新组织和优化,以与 symfony flex 一起使用
需求
- Symfony flex 与 Symfony 3.4|4.0
- 您选择的 i18n Doctrine 策略
- KnpLabs/DoctrineBehaviors 与
knplabs/doctrine-behaviors
- Atlantic18/DoctrineExtensions 与
stof/doctrine-extensions-bundle
- KnpLabs/DoctrineBehaviors 与
安装
composer req koff/i18n-form-bundle
配置
完整的配置示例
# config/packages/i18n_form.yaml i18n_form: locales: [en, fr, es, de] required_locales: [fr] excluded_fields: ['id', 'locale', 'translatable'] form_theme: 'bootstrap_3' # you can use 'bootstrap_3' or 'bootstrap_4' form template
用法
基本示例
use Koff\Bundle\I18nFormBundle\Form\Type\TranslationsType; //... $builder->add('translations', TranslationsType::class);
高级示例
use Koff\Bundle\I18nFormBundle\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] ]);
- [1] 可选。如果设置,则覆盖 config.yml 中的默认值
- [2] 可选。如果设置,则覆盖 config.yml 中的默认值
- [3] 可选。如果设置,则覆盖字段的自动配置
- [3.a] 可选。 - 对于一个字段,应用于所有区域
- [3.b] 可选。 - 对于一个字段的特定区域
- [4] 可选。symfony 表单的常见选项(max_length、required、trim、read_only、constraints 等),增加了 'field_type' 和 'display' 选项
附加
TranslationsFormsType
为不共享未翻译字段的实体提供不同的方法。这里不使用策略,只使用实体中的区域字段。
use Koff\Bundle\I18nFormBundle\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' ] ]);
- [1] 可选。如果设置,则覆盖 config.yml 中的默认值
- [2 - 必需]。您必须创建的真正表单类型
- [2bis] 可选。 - 您可以设置到表单中的选项数组
TranslatedEntityType
修改了原生 'entity' symfony2 表单类型,通过读取翻译来在当前区域中显示标签
use Koff\Bundle\I18nFormBundle\Form\Type\TranslatedEntityType; //... $builder->add('medias', TranslatedEntityType::class, [ 'class' => 'App\Entity\Media', // [1 - Mandatory] 'translation_property' => 'text', // [2 - Mandatory] 'multiple' => true, // [3] ]);
- [1] 可翻译类的路径
- [2] 将显示的可翻译类的属性/方法
- [3] 'entity' symfony2 表单类型的常见选项(multiple 等)
致谢
所有荣誉归David ALLIX和他的a2lix/TranslationFormBundle
许可协议
本软件包可在 MIT 许可证下使用。