a2lix / translation-form-bundle
使用一些辅助工具轻松地将 doctrine 对象进行翻译
3.2.4
2024-04-09 14:08 UTC
Requires
- php: ^8.1
- a2lix/auto-form-bundle: ^0.4
- symfony/config: ^5.4.30|^6.3|^7.0
- symfony/dependency-injection: ^5.4.30|^6.3|^7.0
- symfony/doctrine-bridge: ^5.4.30|^6.3|^7.0
- symfony/event-dispatcher: ^5.4.30|^6.3|^7.0
- symfony/form: ^5.4.30|^6.3|^7.0
- symfony/http-foundation: ^5.4.30|^6.3|^7.0
- symfony/http-kernel: ^5.4.30|^6.3|^7.0
- symfony/options-resolver: ^5.4.30|^6.3|^7.0
Requires (Dev)
- doctrine/orm: ^2.15
- friendsofphp/php-cs-fixer: ^3.45
- knplabs/doctrine-behaviors: ^2.3
- kubawerlos/php-cs-fixer-custom-fixers: ^3.18
- matthiasnoback/symfony-dependency-injection-test: ^5.0
- phpstan/phpstan: ^1.10
- rector/rector: ^0.18
- symfony/cache: ^5.4.30|^6.3|^7.0
- symfony/phpunit-bridge: ^5.4.30|^6.3|^7.0
- symfony/validator: ^5.4.30|^6.3|^7.0
- vimeo/psalm: ^5.18
Suggests
- knplabs/doctrine-behaviors: For Knp strategy
- prezent/doctrine-translatable-bundle: For Prezent strategy
- dev-master / 3.x-dev
- 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
This package is auto-updated.
Last update: 2024-09-02 18:03:05 UTC
README
使用一些辅助工具轻松地将 doctrine 对象进行翻译
屏幕截图示例
支持
3.x
依赖于 AutoFormBundle 并且有更高的要求(PHP8.1+, Symfony5.4+/6.3+/7.0+)。它与 KnpLabs、A2lix 和 Prezent 兼容
安装
使用 composer
composer require a2lix/translation-form-bundle
安装成功后,添加/检查捆绑注册
// 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(), // ...
配置
没有最小配置。可选参数的完整列表
# 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]
- 自定义地区提供者服务 ID。默认依赖于 [1-*] 值
- [1-a] 要显示的翻译地区列表
- [1-b] 默认地区
- [1-c] 必须翻译的地区列表
- 默认模板与 Twitter Bootstrap 兼容。您可以在此处重新定义自己的模板
使用方法
在经典表单类型中
use A2lix\TranslationFormBundle\Form\Type\TranslationsType; ... $builder->add('translations', TranslationsType::class);
高级示例
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', ], ]);
- 可选。如果设置,则覆盖配置.yml 中的默认值
- 可选。如果设置,则覆盖配置.yml 中的默认值
- 可选。如果设置,则覆盖字段的自动配置
- [3.a] 可选。- 对于一个字段,应用于所有地区
- [3.b] 可选。- 对于一个特定字段的地区
- 可选。symfony 表单的常见选项(max_length、required、trim、read_only、constraints 等),其中添加了 'field_type' 和 'display'
- 可选。设置翻译选项卡的标签。默认为地区名称。可以使用翻译键在这里。
附加
TranslationsFormsType
对于不共享未翻译字段的实体,采用不同的方法。此处没有使用策略,仅使用实体中的地区字段。
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' ] ]);
- 可选。如果设置,则覆盖配置.yml 中的默认值
- 必须。您必须做的真实表单类型
- [2bis] 可选。- 您可以设置到表单中的选项数组
TranslatedEntityType
对原生 'entity' symfony 表单类型的修改版本,通过读取翻译来在当前地区翻译标签
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] ]);
- 可翻译类的路径
- 可翻译类中将被显示的属性/方法
- 'entity' symfony 表单类型的常见选项(multiple 等)
示例
有关更多示例,请参阅 Demo Bundle。
贡献帮助
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
许可证
此软件包可在 MIT 许可证 下使用。