From cffd61b3ccde7062a83b7c85cc87bec238793fd2 Mon Sep 17 00:00:00 2001 From: Henjo Hoeksma Date: Thu, 13 Jul 2023 11:51:55 +0200 Subject: [PATCH 1/2] feat: option to (partly) prevent syncing and translation --- .../NodeTranslationService.php | 18 +++++++++++++++++- Configuration/NodeTypes.yaml | 2 -- Configuration/Settings.Neos.yaml | 6 ++++++ NodeTypes/Mixin/TranslationMeta.yaml | 17 +++++++++++++++++ README.md | 5 +++++ .../de/NodeTypes/Mixin/TranslationMeta.xlf | 15 +++++++++++++++ .../en/NodeTypes/Mixin/TranslationMeta.xlf | 16 ++++++++++++++++ 7 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 NodeTypes/Mixin/TranslationMeta.yaml create mode 100644 Resources/Private/Translations/de/NodeTypes/Mixin/TranslationMeta.xlf create mode 100644 Resources/Private/Translations/en/NodeTypes/Mixin/TranslationMeta.xlf diff --git a/Classes/ContentRepository/NodeTranslationService.php b/Classes/ContentRepository/NodeTranslationService.php index 2988b12..ccd8012 100644 --- a/Classes/ContentRepository/NodeTranslationService.php +++ b/Classes/ContentRepository/NodeTranslationService.php @@ -4,12 +4,12 @@ namespace Sitegeist\LostInTranslation\ContentRepository; -use InvalidArgumentException; use Neos\ContentRepository\Domain\Model\NodeInterface; use Neos\ContentRepository\Domain\Model\Workspace; use Neos\ContentRepository\Domain\Repository\NodeDataRepository; use Neos\ContentRepository\Domain\Service\Context; use Neos\ContentRepository\Domain\Service\ContextFactory; +use Neos\ContentRepository\Exception\NodeException; use Neos\Flow\Annotations as Flow; use Neos\Neos\Service\PublishingService; use Neos\Neos\Utility\NodeUriPathSegmentGenerator; @@ -155,9 +155,17 @@ public function afterNodePublish(NodeInterface $node, Workspace $workspace): voi * @param NodeInterface $targetNode * @param Context $context * @return void + * @throws NodeException */ public function translateNode(NodeInterface $sourceNode, NodeInterface $targetNode, Context $context): void { + if ( + $targetNode->hasProperty('preventTranslation') && $targetNode->getProperty('preventTranslation') === true || + $targetNode->getParent() && $targetNode->getParent()->hasProperty('preventTranslation') && $targetNode->getParent()->getProperty('preventTranslation') === true + ) { + return; + } + $propertyDefinitions = $sourceNode->getNodeType()->getProperties(); $sourceDimensionValue = $sourceNode->getContext()->getTargetDimensions()[$this->languageDimensionName]; @@ -286,6 +294,14 @@ public function syncNode(NodeInterface $sourceNode, string $workspaceName = 'liv $context = $this->getContextForLanguageDimensionAndWorkspaceName($presetIdentifier, $workspaceName); $context->getFirstLevelNodeCache()->flush(); + // If the parent element (i.e. a content collection) has preventTranslations on, make sure we do not sync changes - and translations + if ($sourceNode->getParent()) { + $parentTargetNode = $context->adoptNode($sourceNode->getParent()); + if ($parentTargetNode && $parentTargetNode->hasProperty('preventTranslation') && $parentTargetNode->getProperty('preventTranslation') === true) { + continue; + } + } + $targetNode = $context->adoptNode($sourceNode); // Move node if targetNode has no parent or node parents are not matching diff --git a/Configuration/NodeTypes.yaml b/Configuration/NodeTypes.yaml index a404ccc..56269b8 100644 --- a/Configuration/NodeTypes.yaml +++ b/Configuration/NodeTypes.yaml @@ -16,5 +16,3 @@ metaKeywords: options: automaticTranslation: true - - diff --git a/Configuration/Settings.Neos.yaml b/Configuration/Settings.Neos.yaml index 349363a..a6a2f16 100644 --- a/Configuration/Settings.Neos.yaml +++ b/Configuration/Settings.Neos.yaml @@ -2,3 +2,9 @@ Neos: Fusion: defaultContext: 'Sitegeist.LostInTranslation': 'Sitegeist\LostInTranslation\Eel\TranslationHelper' + Neos: + userInterface: + translation: + autoInclude: + 'Sitegeist.LostInTranslation': + - '*' diff --git a/NodeTypes/Mixin/TranslationMeta.yaml b/NodeTypes/Mixin/TranslationMeta.yaml new file mode 100644 index 0000000..77ecae0 --- /dev/null +++ b/NodeTypes/Mixin/TranslationMeta.yaml @@ -0,0 +1,17 @@ +'Sitegeist.LostInTranslation:Mixin.TranslationMeta': + abstract: true + ui: + inspector: + groups: + translation: + label: i18n + icon: 'icon-globe' + properties: + preventTranslation: + type: boolean + ui: + label: i18n + help: + message: i18n + inspector: + group: translation diff --git a/README.md b/README.md index 69db9bb..182f073 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,11 @@ Sitegeist: - 'Hamburg' ``` +### Ignoring Nodes (when in sync-mode) +Optionally you can use the `Sitegeist.LostInTranslation:Mixin.TranslationMeta` mixin in your node configuration to +enable the option to prevent the translation to be changed when sync mode is active, but you would like to exclude +a specific node (or container element). + ## Eel Helper The package also provides two Eel helper to translate texts in Fusion. diff --git a/Resources/Private/Translations/de/NodeTypes/Mixin/TranslationMeta.xlf b/Resources/Private/Translations/de/NodeTypes/Mixin/TranslationMeta.xlf new file mode 100644 index 0000000..0019924 --- /dev/null +++ b/Resources/Private/Translations/de/NodeTypes/Mixin/TranslationMeta.xlf @@ -0,0 +1,15 @@ + + + + + + Prevent automatic sync & translation + Automatische Synchronisierung & Übersetzung verhindern + + + When set, this node (and children) will not be automatically synced and translated even when sync is enabled. + Wenn diese Option gesetzt ist, werden dieser Node (und die untergeordneten Node) nicht automatisch synchronisiert und übersetzt, selbst wenn die Synchronisierung aktiviert ist. + + + + diff --git a/Resources/Private/Translations/en/NodeTypes/Mixin/TranslationMeta.xlf b/Resources/Private/Translations/en/NodeTypes/Mixin/TranslationMeta.xlf new file mode 100644 index 0000000..efcd6be --- /dev/null +++ b/Resources/Private/Translations/en/NodeTypes/Mixin/TranslationMeta.xlf @@ -0,0 +1,16 @@ + + + + + + Translation options + + + Prevent automatic sync & translation + + + When set, this node (and children) will not be automatically synced and translated even when sync is enabled. + + + + From 756ba79c44a3cfea61931276e1c7ca2fe0e4a904 Mon Sep 17 00:00:00 2001 From: Henjo Hoeksma Date: Thu, 13 Jul 2023 12:50:49 +0200 Subject: [PATCH 2/2] task: updated translation --- .../Private/Translations/de/NodeTypes/Mixin/TranslationMeta.xlf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/Private/Translations/de/NodeTypes/Mixin/TranslationMeta.xlf b/Resources/Private/Translations/de/NodeTypes/Mixin/TranslationMeta.xlf index 0019924..22f666a 100644 --- a/Resources/Private/Translations/de/NodeTypes/Mixin/TranslationMeta.xlf +++ b/Resources/Private/Translations/de/NodeTypes/Mixin/TranslationMeta.xlf @@ -8,7 +8,7 @@ When set, this node (and children) will not be automatically synced and translated even when sync is enabled. - Wenn diese Option gesetzt ist, werden dieser Node (und die untergeordneten Node) nicht automatisch synchronisiert und übersetzt, selbst wenn die Synchronisierung aktiviert ist. + Wenn diese Option gesetzt ist, wird diese Node (und die untergeordneten Nodes) nicht automatisch synchronisiert und übersetzt, selbst wenn die Synchronisierung aktiviert ist.