-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Respect rte allow tags in translate request
With this change the RTE configuration is determined from the field to be translated. To give deepl a list of allowed HTML tags. To allow a correct separation in the translated text with HTML tag.
- Loading branch information
Showing
13 changed files
with
379 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WebVision\WvDeepltranslate\Domain\Dto; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class TranslateOptions | ||
{ | ||
protected string $splitSentences = 'nonewlines'; | ||
|
||
protected bool $outlineDetection = false; | ||
|
||
protected array $splittingTags = []; | ||
|
||
protected array $nonSplittingTags = []; | ||
|
||
protected array $ignoreTags = []; | ||
|
||
protected string $tagHandling = 'xml'; | ||
|
||
protected string $targetLanguage; | ||
|
||
protected string $sourceLanguage; | ||
|
||
public function getSplitSentences(): string | ||
{ | ||
return $this->splitSentences; | ||
} | ||
|
||
public function setSplitSentences(string $splitSentences): void | ||
{ | ||
$this->splitSentences = $splitSentences; | ||
} | ||
|
||
public function isOutlineDetection(): bool | ||
{ | ||
return $this->outlineDetection; | ||
} | ||
|
||
public function setOutlineDetection(bool $outlineDetection): void | ||
{ | ||
$this->outlineDetection = $outlineDetection; | ||
} | ||
|
||
public function getSplittingTags(): array | ||
{ | ||
return $this->splittingTags; | ||
} | ||
|
||
public function setSplittingTags(array $splittingTags): void | ||
{ | ||
$this->splittingTags = $splittingTags; | ||
} | ||
|
||
public function getNonSplittingTags(): array | ||
{ | ||
return $this->nonSplittingTags; | ||
} | ||
|
||
public function setNonSplittingTags(array $nonSplittingTags): void | ||
{ | ||
$this->nonSplittingTags = $nonSplittingTags; | ||
} | ||
|
||
public function getIgnoreTags(): array | ||
{ | ||
return $this->ignoreTags; | ||
} | ||
|
||
public function setIgnoreTags(array $ignoreTags): void | ||
{ | ||
$this->ignoreTags = $ignoreTags; | ||
} | ||
|
||
public function getTagHandling(): string | ||
{ | ||
return $this->tagHandling; | ||
} | ||
|
||
public function setTagHandling(string $tagHandling): void | ||
{ | ||
$this->tagHandling = $tagHandling; | ||
} | ||
|
||
public function getTargetLanguage(): string | ||
{ | ||
return $this->targetLanguage; | ||
} | ||
|
||
public function setTargetLanguage(string $targetLanguage): void | ||
{ | ||
$this->targetLanguage = $targetLanguage; | ||
} | ||
|
||
public function getSourceLanguage(): string | ||
{ | ||
return $this->sourceLanguage; | ||
} | ||
|
||
public function setSourceLanguage(string $sourceLanguage): void | ||
{ | ||
$this->sourceLanguage = $sourceLanguage; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$param = []; | ||
$param['tag_handling'] = $this->tagHandling; | ||
|
||
if (!empty($this->splittingTags)) { | ||
$param['outlineDetection'] = $this->outlineDetection; | ||
$param['split_sentences'] = $this->splitSentences; | ||
$param['splitting_tags'] = implode(',', $this->splittingTags); | ||
} | ||
|
||
$param['source_lang'] = $this->sourceLanguage; | ||
$param['target_lang'] = $this->targetLanguage; | ||
|
||
return $param; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WebVision\WvDeepltranslate\Resolver; | ||
|
||
use TYPO3\CMS\Backend\Utility\BackendUtility; | ||
use TYPO3\CMS\Core\Configuration\Richtext; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
final class RichtextAllowTagsResolver | ||
{ | ||
private Richtext $richtext; | ||
|
||
public function __construct( | ||
?Richtext $richtext = null | ||
) { | ||
$this->richtext = $richtext ?? GeneralUtility::makeInstance(Richtext::class); | ||
} | ||
|
||
public function resolve(string $tableName, int $recordId, string $fieldName): array | ||
{ | ||
if (!isset($GLOBALS['TCA'][$tableName]['columns'])) { | ||
throw new \RuntimeException('TCA Columns ist not defined', 1689950520561); | ||
} | ||
|
||
$field = $GLOBALS['TCA'][$tableName]['columns'][$fieldName]; | ||
|
||
if (!isset($field['config']['type'])) { | ||
return []; | ||
} | ||
|
||
if ($field['config']['type'] !== 'text') { | ||
return []; | ||
} | ||
|
||
if (isset($field['config']['enableRichtext'])) { | ||
if ($field['config']['enableRichtext'] === false) { | ||
return []; | ||
} | ||
} elseif (isset($GLOBALS['TCA'][$tableName]['types']['columnsOverrides'][$fieldName]['config']['enableRichtext'])) { | ||
if ($GLOBALS['TCA'][$tableName]['types']['columnsOverrides'][$fieldName]['config']['enableRichtext'] === false) { | ||
return []; | ||
} | ||
} | ||
|
||
$record = BackendUtility::getRecord($tableName, $recordId); | ||
|
||
$allowTags = []; | ||
$rteConfig = $this->richtext->getConfiguration($tableName, $fieldName, $record['pid'], $record['CType'], $field['config']); | ||
if (isset($rteConfig['processing']['allowTags'])) { | ||
$allowTags = array_unique(array_merge($allowTags, $rteConfig['processing']['allowTags']), SORT_REGULAR); | ||
} | ||
|
||
return $allowTags; | ||
} | ||
} |
Oops, something went wrong.