定制 heimrichhannot/contao-multilingual-fields-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

heimrichhannot/contao-multilingual-fields-bundle

Composer 安装命令:

composer require heimrichhannot/contao-multilingual-fields-bundle

包简介

This utility bundle offers functionality for backend editor's to translate arbitrary fields of any table-driven data container in the Contao CMS.

README 文档

README

This utility bundle offers functionality for backend editor's to translate arbitrary fields of any table-driven data container in the Contao CMS.

Features

  • define which fields of which data containers should be translatable
  • adds a button to the backend palette for switching into translation mode
  • content elements: optionally add a select field to the backend palette in order to display the corresponding content element only for the selected language

Impressions

Edit languages button The button for editing the languages (right) and the button for showing certain content elements only for the selected language (left, for tl_content only)

Edit languages Editors can specify which of the fields should be translated for which languages

Use case

The use case for this bundle is to have an automatic and structured process for adding translatable fields to a data container. Also, you get a nice and editor-friendly way to edit translations in the backend ;-)

What doesn't the bundle do?

Currently for most data containers this bundle is a utility bundle for just bringing a nice and editor-friendly way to edit translations in the backend. It's up to you how to use the fields.

Besides tl_content there's no out-of-the-box support for contao's frontend modules!

But you can of course use the created fields in your templates (if the modules passes the data there).

How does it work?

The bundle works quite simply: it looks into your project's <project_dir>/config/config.yml and based on that adds the fields defined here as translatable fields.

Example: Imagine the following config.yml (position is the field representing the job of the member in the company):

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

This would end up in your DCA being automatically modified the following way:

// ...
[
    // 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 ''"
    ]
]

Installation & configuration

  1. Run composer require heimrichhannot/contao-multilingual-fields-bundle.
  2. Create the file <project_dir>/config/config.yml if not already existing and specify your translatable fields:
    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. Clear the project's cache (<project_dir>/var/cache).
  4. Update the database. The new fields should be created now.

Insert tags

The following new insert tags are available. These take into account the translated jumpTo url and alias.

Name Example
{{mf_news_url::<id>::<language>}} {{mf_news_url::1::de}}
{{mf_event_url::<id>::<language>}} {{mf_event_url::5::es}}
{{mf_faq_url::<id>::<language>}} {{mf_faq_url::8::en}}

heimrichhannot/contao-multilingual-fields-bundle 适用场景与选型建议

heimrichhannot/contao-multilingual-fields-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 163 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 04 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「translation」 「field」 「fields」 「contao」 「multilingual」 「dca」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 heimrichhannot/contao-multilingual-fields-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 heimrichhannot/contao-multilingual-fields-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 heimrichhannot/contao-multilingual-fields-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 163
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 5
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2021-04-16