TYPO3 13中如何为翻译后的Content Blocks设置不同图片?
问题:TYPO3 13.4.15 + EXT:content-blocks 翻译后图片无法替换,始终显示原语言回退图
运行TYPO3 13.4.15实例,搭配最新版EXT:content-blocks,文本翻译(含回退机制)功能正常,但无法为翻译后的内容设置独立图片。界面上翻译操作的UI显示正常,但修改翻译版本的图片后,前端始终显示原语言的回退图片。
现有配置
1. Content Blocks的config.yaml配置
... fields: - label: Image identifier: image type: File allowed: common-image-types extendedPalette: true tca: config: behaviour: allowLanguageSynchronization: true appearance: showAllLocalizationLink: true showSynchronizationLink: true enabledControls: localize: true
2. EXT:sitepackage中的TCA覆盖代码
$col = 'PREFIX_image'; // 已添加正确前缀 if (isset($GLOBALS['TCA']['tt_content']['columns'][$col]['config'])) { $conf = &$GLOBALS['TCA']['tt_content']['columns'][$col]['config']; // 字段下方的语言切换器 $conf['behaviour']['allowLanguageSynchronization'] = true; // 图片字段中的IRRE本地化UI $conf['appearance']['showAllLocalizationLink'] = true; $conf['appearance']['showSynchronizationLink'] = true; $conf['appearance']['enabledControls']['localize'] = true; $conf['appearance']['useSortable'] = true; }
解决方案
1. 为图片字段添加l10n_mode配置
在Content Blocks的config.yaml中,为图片字段的TCA配置添加l10n_mode: exclude,确保翻译版本可独立编辑图片:
... fields: - label: Image identifier: image type: File allowed: common-image-types extendedPalette: true tca: config: behaviour: allowLanguageSynchronization: true appearance: showAllLocalizationLink: true showSynchronizationLink: true enabledControls: localize: true l10n_mode: exclude
2. 补充TCA覆盖代码中的l10n_mode设置
若通过config.yaml配置不生效,在EXT:sitepackage的TCA覆盖代码中直接设置字段的l10n_mode:
$col = 'PREFIX_image'; // 已添加正确前缀 if (isset($GLOBALS['TCA']['tt_content']['columns'][$col])) { // 配置字段不继承原语言值,允许独立翻译 $GLOBALS['TCA']['tt_content']['columns'][$col]['l10n_mode'] = 'exclude'; $conf = &$GLOBALS['TCA']['tt_content']['columns'][$col]['config']; // 字段下方的语言切换器 $conf['behaviour']['allowLanguageSynchronization'] = true; // 图片字段中的IRRE本地化UI $conf['appearance']['showAllLocalizationLink'] = true; $conf['appearance']['showSynchronizationLink'] = true; $conf['appearance']['enabledControls']['localize'] = true; $conf['appearance']['useSortable'] = true; }
3. 缓存清理与翻译同步重置
- 登录TYPO3后台,清除所有系统缓存(包括配置缓存)
- 进入翻译内容的编辑界面,若字段处于同步状态,点击取消同步按钮,然后重新设置翻译版本的图片
- 保存内容后刷新前端页面验证效果
关键说明
l10n_mode: exclude是解决问题的核心配置,它告知TYPO3该字段在翻译版本中不继承原语言的值,允许独立编辑。仅配置allowLanguageSynchronization不足以让字段脱离继承逻辑,必须配合正确的l10n_mode设置。
内容的提问来源于stack exchange,提问作者Urs Bo
相关产品推荐
相关产品推荐

