koff/i18n-form-bundle

使用一些帮助轻松翻译 doctrine 对象

安装次数: 14,052

依赖项: 0

建议者: 0

安全性: 0

星标: 7

关注者: 3

分支: 1

开放问题: 1

类型:symfony-bundle

v4.0.7 2018-01-12 10:17 UTC

This package is auto-updated.

Last update: 2024-09-12 12:05:39 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality StyleCI Coverage Status

此包是从a2lix/TranslationFormBundle派生而来,经过重新组织和优化,以与 symfony flex 一起使用

需求

安装

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 许可证下使用。