Skip to content
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

feat: option to (partly) prevent syncing and translation #32

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Classes/ContentRepository/NodeTranslationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions Configuration/NodeTypes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@
metaKeywords:
options:
automaticTranslation: true


6 changes: 6 additions & 0 deletions Configuration/Settings.Neos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ Neos:
Fusion:
defaultContext:
'Sitegeist.LostInTranslation': 'Sitegeist\LostInTranslation\Eel\TranslationHelper'
Neos:
userInterface:
translation:
autoInclude:
'Sitegeist.LostInTranslation':
- '*'
17 changes: 17 additions & 0 deletions NodeTypes/Mixin/TranslationMeta.yaml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="Sitegeist.LostInTranslation" source-language="en" target-language="de" datatype="plaintext">
<body>
<trans-unit id="properties.preventTranslation">
<source>Prevent automatic sync &amp; translation</source>
<target>Automatische Synchronisierung &amp; Übersetzung verhindern</target>
</trans-unit>
<trans-unit id="properties.preventTranslation.ui.help.message">
<source>When set, this node (and children) will not be automatically synced and translated even when sync is enabled.</source>
<target>Wenn diese Option gesetzt ist, wird diese Node (und die untergeordneten Nodes) nicht automatisch synchronisiert und übersetzt, selbst wenn die Synchronisierung aktiviert ist.</target>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="Sitegeist.LostInTranslation" source-language="en" datatype="plaintext">
<body>
<trans-unit id="groups.translation">
<source>Translation options</source>
</trans-unit>
<trans-unit id="properties.preventTranslation">
<source>Prevent automatic sync &amp; translation</source>
</trans-unit>
<trans-unit id="properties.preventTranslation.ui.help.message">
<source>When set, this node (and children) will not be automatically synced and translated even when sync is enabled.</source>
</trans-unit>
</body>
</file>
</xliff>