heimrichhannot/contao-multilingual-fields-bundle

此实用程序包为Contao CMS后端编辑器提供功能,用于翻译任何表格数据容器的任意字段。

0.5.1 2022-08-23 12:37 UTC

This package is auto-updated.

Last update: 2024-09-23 16:57:33 UTC


README

此实用程序包为Contao CMS后端编辑器提供功能,用于翻译任何表格数据容器的任意字段。

功能

  • 定义哪些数据容器的哪些字段应可翻译
  • 添加按钮到后端调色板以切换到翻译模式
  • 内容元素:可选地添加下拉字段到后端调色板,以便仅显示所选语言的相应内容元素

印象

编辑语言按钮编辑语言按钮(右)和仅显示所选语言内容元素的按钮(左,仅对tl_content有效)

编辑语言编辑器可以指定哪些字段应翻译为哪些语言

用例

此包的用例是有一个自动和结构化的过程,用于将可翻译字段添加到数据容器。此外,您还可以在后端以优雅且易于编辑的方式编辑翻译 ;-)

此包不做什么?

目前,对于大多数数据容器,此包仅为提供优雅且易于编辑的翻译编辑方式的实用程序包。如何使用字段取决于您。

除了tl_content之外,没有对Contao前端模块的现成支持!

但您当然可以在模板中使用创建的字段(如果模块将数据传递到那里)。

它是如何工作的?

此包工作非常简单:它会查看您项目的 <project_dir>/config/config.yml,并根据此添加此处定义的可翻译字段。

示例:想象以下 config.yml(位置表示成员在公司中的职位)

huh_multilingual_fields:
  fallback_language: de
  languages:
    - en
  data_containers:
    tl_member:
      fields:
        - { name: position }

这将自动修改您的DCA如下

// ...
[
    // the original position field is nearly unchanged -> only some meta field links are set in eval
    'position' => [
        'exclude'   => true,
        'search'    => true,
        'inputType' => 'text',
        'eval'      => [
            'maxlength' => 128,
            'tl_class' => 'w50',
            'mandatory' => true,
            'isTranslatedField' => true,
            'translationConfig' => [
                'en' => [
                    'field' => 'en_position',
                    'selector' => 'en_translate_position'
]               ]
            ]
         ],
        'sql'       => "varchar(128) NOT NULL default ''"
    ],
    // automatically created: the selector field and the translation field
    // the selector field (subpalette and selector is also set)
    'en_translate_position' => [
        'label'     => ['Translate (English)', 'Click this option in order to translate the field for the given language.'],
        'exclude'   => true,
        'inputType' => 'checkbox',
        'eval'      => [
            'tl_class' => 'w50',
            'submitOnChange' => true,
            'translationField' => 'en_position',
            'translatedField' => 'position'
        ],
        'sql'       => "char(1) NOT NULL default ''",
    ],
    // the translation field
    'en_position' => [
        'label'     => ['Position (English)', '<the description as given>'], // generated automatically out of the label of the "position" field
        'exclude'   => true,
        'search'    => true,
        'inputType' => 'text',
        'eval'      => [
            'maxlength' => 128,
            'tl_class' => 'w50',
            'mandatory' => true,
            'translatedField' => 'position',
            'translationSelectorField' => 'en_translate_position'
         ],
        'sql'       => "varchar(128) NOT NULL default ''"
    ]
]

安装 & 配置

  1. 运行 composer require heimrichhannot/contao-multilingual-fields-bundle
  2. 如果尚不存在,创建文件 <project_dir>/config/config.yml 并指定您的可翻译字段
    huh_multilingual_fields:
      fallback_language: de
      content_language_select: # add a select field to content element palettes for displaying elements only for the specified language
        enabled: true # default: false
        types: # if not set, the select field is added to all tl_content types
          - text
      languages:
        - en
      data_containers:
        tl_member:
          sql_condition: tl_member.firstname LIKE ? # optional; activate the functionality only for some entities
          sql_condition_values:
            - "%%john%%" # be careful about escaping; in yaml the reserved character "%" can't be in first place and need to be be escaped
          fields:
            - { name: alias, is_alias_field: true, alias_base_field: lastname }
            - { name: lastname }
            - { name: position }
  3. 清除项目的缓存(《<project_dir>/var/cache)。
  4. 更新数据库。现在应该创建了新字段。

插入标签

以下可用的新插入标签考虑了翻译的jumpTo URL和别名。