diff --git a/Classes/Hooks/AllowLanguageSynchronizationHook.php b/Classes/Hooks/AllowLanguageSynchronizationHook.php index 688c5bb2..15d9b829 100644 --- a/Classes/Hooks/AllowLanguageSynchronizationHook.php +++ b/Classes/Hooks/AllowLanguageSynchronizationHook.php @@ -1,6 +1,6 @@ isRecordDeletePlaceholder($row) && !isset($translations[$lUid_OnPage]) && $this->getBackendUserAuthentication()->checkLanguageAccess($lUid_OnPage) + && DeeplBackendUtility::checkCanBeTranslated($pageId, $lUid_OnPage) ) { $out .= DeeplBackendUtility::buildTranslateButton( $table, diff --git a/Classes/Override/DeeplRecordListController.php b/Classes/Override/DeeplRecordListController.php index 84c1350f..e1643836 100644 --- a/Classes/Override/DeeplRecordListController.php +++ b/Classes/Override/DeeplRecordListController.php @@ -30,29 +30,20 @@ protected function languageSelector($requestUri): string $this->id, $requestUri ); + if ($options == '') { - return ''; + return $originalOutput; } - $deeplSelectLabel = LocalizationUtility::translate( - 'backend.label', - 'wv_deepltranslate' - ); - return str_replace( '
', '
', $originalOutput ) . '
' - . '
' - . '' - . '
' - . '' - . '
' - . '
' + . '' . '
' . '
'; } diff --git a/Classes/Override/v10/DatabaseRecordList.php b/Classes/Override/v10/DatabaseRecordList.php index bcdba9ac..06c7051c 100644 --- a/Classes/Override/v10/DatabaseRecordList.php +++ b/Classes/Override/v10/DatabaseRecordList.php @@ -58,6 +58,10 @@ public function makeLocalizationPanel($table, $row): array && $this->isEditable($table) && !isset($translations['translations'][$lUid_OnPage]) && $this->getBackendUserAuthentication()->checkLanguageAccess($lUid_OnPage) + && DeeplBackendUtility::checkCanBeTranslated( + ($table === 'pages') ? $row['uid'] : $row['pid'], + $lUid_OnPage + ) ) { $language = BackendUtility::getRecord('sys_language', $lUid_OnPage, 'title'); $lNew .= DeeplBackendUtility::buildTranslateButton( diff --git a/Classes/Override/v10/DeeplPageLayoutView.php b/Classes/Override/v10/DeeplPageLayoutView.php index 42df2cf0..6746abd8 100644 --- a/Classes/Override/v10/DeeplPageLayoutView.php +++ b/Classes/Override/v10/DeeplPageLayoutView.php @@ -30,20 +30,14 @@ public function languageSelector($id) $this->id, GeneralUtility::getIndpEnv('REQUEST_URI') ); + if ($options == '') { - return ''; + return $originalOutput; } $originalOutput = str_ireplace('
', '', $originalOutput); return $originalOutput . '
' - . sprintf( - '', - LocalizationUtility::translate( - 'backend.label', - 'wv_deepltranslate' - ) - ) . '
'; diff --git a/Classes/Override/v10/DeeplRecordListController.php b/Classes/Override/v10/DeeplRecordListController.php index 675ca052..bcb2309a 100644 --- a/Classes/Override/v10/DeeplRecordListController.php +++ b/Classes/Override/v10/DeeplRecordListController.php @@ -35,18 +35,11 @@ protected function languageSelector($id): string ); if ($options == '') { - return ''; + return $originalOutput; } return str_ireplace('', '', $originalOutput) . '
' - . sprintf( - '', - LocalizationUtility::translate( - 'backend.label', - 'wv_deepltranslate' - ) - ) . '' diff --git a/Classes/Utility/DeeplBackendUtility.php b/Classes/Utility/DeeplBackendUtility.php index 6d604117..bafbf2d4 100644 --- a/Classes/Utility/DeeplBackendUtility.php +++ b/Classes/Utility/DeeplBackendUtility.php @@ -17,6 +17,9 @@ use TYPO3\CMS\Core\Imaging\IconRegistry; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; +use WebVision\WvDeepltranslate\Exception\LanguageIsoCodeNotFoundException; +use WebVision\WvDeepltranslate\Exception\LanguageRecordNotFoundException; +use WebVision\WvDeepltranslate\Service\LanguageService; class DeeplBackendUtility { @@ -187,7 +190,7 @@ private static function getIcon(string $iconFlag): Icon $deeplIcon = GeneralUtility::makeInstance( IconFactory::class )->getIcon( - 'actions-localize-deepl', + 'deepl-grey-logo', Icon::SIZE_OVERLAY ); GeneralUtility::makeInstance(IconRegistry::class) @@ -248,11 +251,13 @@ public static function buildTranslateDropdown( } // If any languages are left, make selector: if (!empty($availableTranslations)) { - $output = sprintf( - '', - htmlspecialchars(LocalizationUtility::translate('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:new_language')) - ); + $output = ''; foreach ($availableTranslations as $languageUid => $languageTitle) { + // check if language can be translated with DeepL + // otherwise continue to next + if (!DeeplBackendUtility::checkCanBeTranslated($id, $languageUid)) { + continue; + } // Build localize command URL to DataHandler (tce_db) // which redirects to FormEngine (record_edit) // which, when finished editing should return back to the current page (returnUrl) @@ -268,12 +273,39 @@ public static function buildTranslateDropdown( $targetUrl = self::buildBackendRoute('tce_db', $params); $output .= ''; } + if ($output !== '') { + $output = sprintf( + '%s', + htmlspecialchars(LocalizationUtility::translate('backend.label', 'wv_deepltranslate')), + $output + ); + } return $output; } return ''; } + public static function checkCanBeTranslated(int $pageId, int $languageId): bool + { + $languageService = GeneralUtility::makeInstance(LanguageService::class); + $site = $languageService->getCurrentSite('pages', $pageId); + if ($site === null) { + return false; + } + try { + $languageService->getSourceLanguage($site['site']); + } catch (LanguageIsoCodeNotFoundException $e) { + return false; + } + try { + $languageService->getTargetLanguage($site['site'], $languageId); + } catch (LanguageIsoCodeNotFoundException|LanguageRecordNotFoundException $e) { + return false; + } + return true; + } + private static function getBackendUserAuthentication(): BackendUserAuthentication { return $GLOBALS['BE_USER']; diff --git a/Classes/ViewHelpers/DeeplTranslateViewHelper.php b/Classes/ViewHelpers/DeeplTranslateViewHelper.php index 0d0f7490..9040bbda 100644 --- a/Classes/ViewHelpers/DeeplTranslateViewHelper.php +++ b/Classes/ViewHelpers/DeeplTranslateViewHelper.php @@ -5,6 +5,7 @@ namespace WebVision\WvDeepltranslate\ViewHelpers; use TYPO3\CMS\Backend\View\PageLayoutContext; +use TYPO3\CMS\Extbase\Utility\LocalizationUtility; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; use WebVision\WvDeepltranslate\Utility\DeeplBackendUtility; @@ -33,13 +34,21 @@ public function render(): array $siteLanguage->getLanguageId() != -1 && $siteLanguage->getLanguageId() != 0 ) { + if (!DeeplBackendUtility::checkCanBeTranslated($context->getPageId(), $siteLanguage->getLanguageId())) { + continue; + } $languageMatch[$siteLanguage->getTitle()] = $siteLanguage->getLanguageId(); } } + if (count($languageMatch) === 0) { + return $options; + } foreach ($context->getNewLanguageOptions() as $key => $possibleLanguage) { if ($key === 0) { - $options[] = $possibleLanguage; + continue; + } + if (!array_key_exists($possibleLanguage, $languageMatch)) { continue; } $parameters = [ diff --git a/Resources/Private/Backend/Partials/PageLayout/LanguageColumns.html b/Resources/Private/Backend/Partials/PageLayout/LanguageColumns.html index 2014a809..fa038b9a 100644 --- a/Resources/Private/Backend/Partials/PageLayout/LanguageColumns.html +++ b/Resources/Private/Backend/Partials/PageLayout/LanguageColumns.html @@ -3,9 +3,9 @@ xmlns:deepl="http://typo3.org/ns/WebVision/WvDeepltranslate/ViewHelpers" xmlns:f="http://typo3.org/ns/TYPO3Fluid/Fluid/ViewHelpers" > - +
@@ -16,16 +16,21 @@
-
- -
- -
-
+ + +
+ +
+ +
+
+
+
diff --git a/Resources/Private/Backend/Partials/v10/PageLayout/LanguageColumns.html b/Resources/Private/Backend/v10/Partials/PageLayout/LanguageColumns.html similarity index 91% rename from Resources/Private/Backend/Partials/v10/PageLayout/LanguageColumns.html rename to Resources/Private/Backend/v10/Partials/PageLayout/LanguageColumns.html index ca82152c..c5a7ba74 100644 --- a/Resources/Private/Backend/Partials/v10/PageLayout/LanguageColumns.html +++ b/Resources/Private/Backend/v10/Partials/PageLayout/LanguageColumns.html @@ -3,9 +3,9 @@ xmlns:deepl="http://typo3.org/ns/WebVision/WvDeepltranslate/ViewHelpers" xmlns:f="http://typo3.org/ns/TYPO3Fluid/Fluid/ViewHelpers" > - +
@@ -15,14 +15,19 @@
-
- - -
+ + +
+ + +
+
+
diff --git a/ext_typoscript_setup.txt b/ext_typoscript_setup.txt index 6e94b657..48090c92 100644 --- a/ext_typoscript_setup.txt +++ b/ext_typoscript_setup.txt @@ -26,6 +26,6 @@ module.tx_backend.view { } } -[compatVersion("10.4")] - module.tx_backend.view.partialRootPaths.10 = EXT:wv_deepltranslate/Resources/Private/Backend/Partials/v10 +[typo3.version < "11.5"] + module.tx_backend.view.partialRootPaths.10 = EXT:wv_deepltranslate/Resources/Private/Backend/v10/Partials [END]