From db868ef2371be34ee81c7aadca60b18a56fed2a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCrk?= Date: Mon, 2 Jun 2025 12:31:03 +0200 Subject: [PATCH] [TASK] Replace TYPO3 localization override with `EXT:deepl_base` `EXT:deepltranslate_core` replaced TYPO3 backend implementation of the localization JavaScript modal to add two custom modes to the system along with extending the `LocalizationController` to ensure processing works by mitigating the hardcoded core mode checks implemented by the TYPO3 Core. Meanwhile, a new planned extension also needs to provide one or more custom modes, which should work standalone and or next to `EXT:deepltransate_core` which makes providing hardcoded mode extension unreliable, special in a cross-mix. To mitigate this a new `EXT:deepl_base` extension has been now created to provide the overrides in a extensible way using the one or other PSR-14 event, adding a new AJAX Endpoint for the locaization modes and adjusts the JavaScript to be dynamically changeable and is based on a early `work-in-progress` change for TYPO3 v14, provided as a early and slightly enhanced backport. This change replaces the own implementation with the provided events of the shared extension, dropping obsolete code directly to keep it clean. Current PSR-14 event based implementation lacks checking if the `deepl api key` has been set and will be added with one of the following changes along with further adjustments. This change acts as a kickstart for the replacement now to open up for dual developlment on this extension and another extension on the same time and unblock that. However, it's still a working state and leads to the direction already planned. Used command(s): ```shell BIN_COMPOSER="Build/Scripts/runTests.sh -p 8.1 -t 12 -s composer -- " \ && ${BIN_COMPOSER} config minimum-stability "dev" \ && ${BIN_COMPOSER} config prefer-stable true \ && ${BIN_COMPOSER} require "web-vision/deepl-base":"1.*.*@dev" && Build/Scripts/runTests.sh -p 8.1 -t 12 -s composerUpdate \ && Build/Scripts/runTests.sh -p 8.1 -t 12 -s phpstanGenerateBaseline \ && Build/Scripts/runTests.sh -p 8.2 -t 13 -s composerUpdate \ && Build/Scripts/runTests.sh -p 8.2 -t 13 -s phpstanGenerateBaseline \ && Build/Scripts/runTests.sh -p 8.1 -t 12 -s composerUpdate ``` --- Build/Sources/Core13/localization.js | 13 - Build/Sources/Core13/localization.ts | 485 ----------------- Build/Sources/TypeScript/localization.ts | 506 ------------------ Build/phpstan/Core12/phpstan-baseline.neon | 15 - Build/phpstan/Core13/phpstan-baseline.neon | 15 - .../ApplyLocalizationModesEventListener.php | 60 +++ .../ProcessLocalizationModeEventListener.php | 36 ++ Classes/Override/LocalizationController.php | 127 ----- Configuration/JavaScriptModules.php | 4 - Configuration/Services.yaml | 14 + Resources/Public/Css/patch-105853.css | 6 - Resources/Public/JavaScript/Settings.js | 8 - Resources/Public/JavaScript/localization12.js | 467 ---------------- Resources/Public/JavaScript/localization13.js | 13 - Tests/Functional/AbstractDeepLTestCase.php | 1 + .../ContentElementsInContainerTest.php | 1 + ...lationWithModifiedTcaConfigurationTest.php | 1 + .../LocalizationInlineRegressionTest.php | 1 + .../ExtensionActiveViewHelperTest.php | 1 + composer.json | 5 +- ext_emconf.php | 1 + ext_localconf.php | 15 - 22 files changed, 119 insertions(+), 1676 deletions(-) delete mode 100644 Build/Sources/Core13/localization.js delete mode 100644 Build/Sources/Core13/localization.ts delete mode 100644 Build/Sources/TypeScript/localization.ts create mode 100644 Classes/Event/Listener/ApplyLocalizationModesEventListener.php create mode 100644 Classes/Event/Listener/ProcessLocalizationModeEventListener.php delete mode 100644 Classes/Override/LocalizationController.php delete mode 100644 Resources/Public/Css/patch-105853.css delete mode 100644 Resources/Public/JavaScript/Settings.js delete mode 100644 Resources/Public/JavaScript/localization12.js delete mode 100644 Resources/Public/JavaScript/localization13.js diff --git a/Build/Sources/Core13/localization.js b/Build/Sources/Core13/localization.js deleted file mode 100644 index 8ed6f31e..00000000 --- a/Build/Sources/Core13/localization.js +++ /dev/null @@ -1,13 +0,0 @@ -/* - * This file is part of the TYPO3 CMS project. - * - * It is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. - * - * For the full copyright and license information, please read the - * LICENSE.txt file that was distributed with this source code. - * - * The TYPO3 project - inspiring people to share! - */ -import DocumentService from"@typo3/core/document-service.js";import $ from"jquery";import{SeverityEnum}from"@typo3/backend/enum/severity.js";import AjaxRequest from"@typo3/core/ajax/ajax-request.js";import Icons from"@typo3/backend/icons.js";import Modal from"@typo3/backend/modal.js";import MultiStepWizard from"@typo3/backend/multi-step-wizard.js";import"@typo3/backend/element/icon-element.js";import{MarkupIdentifiers}from"@typo3/backend/enum/icon-types.js";class Localization{constructor(){this.triggerButton=".t3js-localize",DocumentService.ready().then((()=>{this.initialize()}))}async initialize(){const e=await Icons.getIcon("actions-localize",Icons.sizes.large),t=await Icons.getIcon("actions-edit-copy",Icons.sizes.large),a=await Icons.getIcon("actions-localize-deepl",Icons.sizes.large,null,null,MarkupIdentifiers.inline);$(this.triggerButton).removeClass("disabled"),$(document).on("click",this.triggerButton,(async l=>{l.preventDefault();const o=$(l.currentTarget),n=[],i=[];if(0===o.data("allowTranslate")&&0===o.data("allowCopy"))return void Modal.confirm(TYPO3.lang["window.localization.mixed_mode.title"],TYPO3.lang["window.localization.mixed_mode.message"],SeverityEnum.warning,[{text:TYPO3?.lang?.["button.ok"]||"OK",btnClass:"btn-warning",name:"ok",trigger:(e,t)=>t.hideModal()}]);const c=await(await this.loadAvailableLanguages(parseInt(o.data("pageId"),10),parseInt(o.data("languageId"),10))).resolve();if(o.data("allowTranslate")&&(n.push('

'+TYPO3.lang["localize.educate.translate"]+"

"),i.push("localize")),o.data("allowCopy")&&(n.push('

'+TYPO3.lang["localize.educate.copy"]+"

"),i.push("copyFromLanguage")),n.push('

'+TYPO3.lang["localize.educate.deepltranslate"]+"

"),i.push("localizedeepl"),n.push('

'+TYPO3.lang["localize.educate.deepltranslateAuto"]+"

"),i.push("localizedeeplauto"),1===i.length)MultiStepWizard.set("localizationMode",i[0]);else{const e=document.createElement("div");e.dataset.bsToggle="buttons",e.append(...n.map((e=>document.createRange().createContextualFragment(e)))),MultiStepWizard.addSlide("localize-choose-action",TYPO3.lang["localize.wizard.header_page"].replace("{0}",o.data("page")).replace("{1}",o.data("languageName")),e,SeverityEnum.notice,TYPO3.lang["localize.wizard.step.selectMode"],((e,t)=>{void 0!==t.localizationMode&&MultiStepWizard.unlockNextStep()}))}1===c.length?MultiStepWizard.set("sourceLanguage",c[0].uid):MultiStepWizard.addSlide("localize-choose-language",TYPO3.lang["localize.view.chooseLanguage"],"",SeverityEnum.notice,TYPO3.lang["localize.wizard.step.chooseLanguage"],(async(e,t)=>{void 0!==t.sourceLanguage&&MultiStepWizard.unlockNextStep(),e.html('
'+await Icons.getIcon("spinner-circle",Icons.sizes.large)+"
"),MultiStepWizard.getComponent().on("change",".t3js-language-option",(e=>{MultiStepWizard.set("sourceLanguage",$(e.currentTarget).val()),MultiStepWizard.unlockNextStep()}));const a=$("
",{class:"row"});for(const e of c){const t="language"+e.uid,l=$("",{type:"radio",name:"language",id:t,value:e.uid,class:"btn-check t3js-language-option"}),o=$("