首页 > 解决方案 > 有没有办法在 TYPO3 9 中通过 extbase 创建域对象翻译?

问题描述

我正在将一些带有 JSON 的产品导入到我的 TYPO3 扩展中。

当我从 TYPO3 8 升级到 TYPO3 9 时,我在 ImportService 上创建翻译时遇到问题。似乎无法设置数据库中的 l10n_parent,尽管正在设置 _localizedUid 和 _versionedUid。

/**
 * @param DomainObjectInterface $object
 * @param $targetLanguageUid
 * @return DomainObjectInterface|null
 */
public function translate($object, $targetLanguageUid)
{
    /** @var AbstractDomainObject $objectCopy */
    $objectCopy = new $this->objectType;
    $properties = ObjectAccess::getGettableProperties($object);
    foreach ($properties as $propertyName => $propertyValue) {
        ObjectAccess::setProperty($objectCopy, $propertyName, $propertyValue);
    }
    $objectCopy->_setProperty('_localizedUid', $object->getUid());
    $objectCopy->_setProperty('_languageUid', $targetLanguageUid);
    $objectCopy->_setProperty('_versionedUid', $object->getUid());
    return $objectCopy;
}

预期结果:数据库中的 l10n_parent 为例如 403(原始对象的 uid)
实际结果:数据库中的 l10n_parent 为 0

标签: typo3translationextbasetypo3-9.x

解决方案


在处理 TYPO3 内部数据结构时,建议为此使用DataHandler。在您的情况下,您只需要提供配置数组并localize正确设置该字段。您可以在自己的脚本中使用它,并使用后端范围,文档中提供了示例。在您的导入脚本中,您必须首先以默认语言创建记录,然后为其创建每个翻译。


推荐阅读