typo3 - 有没有办法在 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
解决方案
在处理 TYPO3 内部数据结构时,建议为此使用DataHandler。在您的情况下,您只需要提供配置数组并localize
正确设置该字段。您可以在自己的脚本中使用它,并使用后端范围,文档中提供了示例。在您的导入脚本中,您必须首先以默认语言创建记录,然后为其创建每个翻译。
推荐阅读
- mysql - 如何在mysql中找到最近的geohash?
- java - 我如何让课堂辩论?
- google-cloud-platform - 数据流 GroupByKey 和 CoGroupByKey 非常慢
- java - 在 FFT java 类中计算正弦或余弦函数的问题 - Android studio
- php - Codeigniter foreach 循环行插入到表中
- python - 跨多个盒子并行运行 Python 代码
- sql - 使用 Hibernate Envers 时 SQL 语句中的语法错误
- r - 修复 R / networkD3 包中 Sankey 流图的顺序
- linux - 从多个文件夹移动txt文件并重命名
- javascript - Mongoose save() 返回旧版本,未保存的文档版本