From f0b4d134c9f2efe78621de958ce6f341ced6a029 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Fri, 5 Nov 2021 17:05:27 +0100 Subject: [PATCH] =?UTF-8?q?TASK:=20Add=20the=20configuration=20of=20=C3=B2?= =?UTF-8?q?ptions.deeplLanguage`=20for=20languagePresets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../NodeTranslationService.php | 15 +++++++-- README.md | 32 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Classes/ContentRepository/NodeTranslationService.php b/Classes/ContentRepository/NodeTranslationService.php index 437a0eb..c5411c6 100644 --- a/Classes/ContentRepository/NodeTranslationService.php +++ b/Classes/ContentRepository/NodeTranslationService.php @@ -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; @@ -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; } diff --git a/README.md b/README.md index 28b202d..39fbef0 100644 --- a/README.md +++ b/README.md @@ -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.