Skip to content

Commit

Permalink
Merge pull request #1 from sitegeist/feature/configureDeeplLanguageFo…
Browse files Browse the repository at this point in the history
…rPresets

TASK: Add the configuration of òptions.deeplLanguage` for languagePresets
  • Loading branch information
mficzel authored Nov 5, 2021
2 parents df5b9ad + f0b4d13 commit 5008159
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Classes/ContentRepository/NodeTranslationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class NodeTranslationService
protected $languageDimensionName;

/**
* @Flow\InjectConfiguration(package="", path="nodeTranslation.languageDimensionName")
* @Flow\InjectConfiguration(package="Neos.ContentRepository", path="contentDimensions")
* @var array
*/
protected $contentDimensionConfiguration;
Expand All @@ -62,7 +62,18 @@ public function afterAdoptNode(NodeInterface $node, Context $context, $recursive
$sourceLanguage = explode('_', $node->getContext()->getTargetDimensions()[$this->languageDimensionName])[0];
$targetLanguage = explode('_', $context->getTargetDimensions()[$this->languageDimensionName])[0];

if ($sourceLanguage == $targetLanguage) {
$sourceLanguagePreset = $this->contentDimensionConfiguration[$this->languageDimensionName]['presets'][$sourceLanguage];
$targetLanguagePreset = $this->contentDimensionConfiguration[$this->languageDimensionName]['presets'][$targetLanguage];

if (array_key_exists('options', $sourceLanguagePreset) && array_key_exists('deeplLanguage', $sourceLanguagePreset['options'])) {
$sourceLanguage = $sourceLanguagePreset['options']['deeplLanguage'];
}

if (array_key_exists('options', $targetLanguagePreset) && array_key_exists('deeplLanguage', $targetLanguagePreset['options'])) {
$targetLanguage = $targetLanguagePreset['options']['deeplLanguage'];
}

if (empty($sourceLanguage) || empty($targetLanguage) || ($sourceLanguage == $targetLanguage)) {
return;
}

Expand Down
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,38 @@ Sitegeist:
languageDimensionName: 'language'
```

If a preset of the language dimension uses a locale identifier that is not compatible with DeepL the deeplLanguage can
be configured explicitly for this preset via `options.deeplLanguage`. If this value is set to null the language will neither
ne used as source nor as target for translations.

```
Neos:
ContentRepository:
contentDimensions:
'language':
presets:
#
# Danish a different loacale identifier than deepl so this has to be configured explicitly
#
'dk':
label: 'Dansk'
values: ['dk']
uriSegment: 'dk'
options:
deeplLanguage: 'da'
#
# Bavarian language not support by DeepL and is disabled
#
'de_bar':
label: 'Bayrisch'
values: ['de_bar','de']
uriSegment: 'de_bar'
options:
deeplLanguage: ~
```

To configure a property for automatic translation the setting `options.translateOnAdoption: true` can be used on any
property of type "string". Some very common fields from `Neos.Neos:Document` are already configured to do so by default.

Expand Down

0 comments on commit 5008159

Please sign in to comment.