-
Notifications
You must be signed in to change notification settings - Fork 41
Respect rte allow tags in translate request #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
NarkNiro
wants to merge
1
commit into
3.0
Choose a base branch
from
wv_deepletranslate-278
base: 3.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.