diff --git a/config/v9/typo3-93.php b/config/v9/typo3-93.php index 18f85f4e0..20d0c864f 100644 --- a/config/v9/typo3-93.php +++ b/config/v9/typo3-93.php @@ -8,6 +8,7 @@ use Ssch\TYPO3Rector\Rector\v9\v3\BackendUserAuthenticationSimplelogRector; use Ssch\TYPO3Rector\Rector\v9\v3\BackendUtilityGetModuleUrlRector; use Ssch\TYPO3Rector\Rector\v9\v3\CopyMethodGetPidForModTSconfigRector; +use Ssch\TYPO3Rector\Rector\v9\v3\MoveLanguageFilesFromExtensionLangRector; use Ssch\TYPO3Rector\Rector\v9\v3\PropertyUserTsToMethodGetTsConfigOfBackendUserAuthenticationRector; use Ssch\TYPO3Rector\Rector\v9\v3\RemoveColPosParameterRector; use Ssch\TYPO3Rector\Rector\v9\v3\UseMethodGetPageShortcutDirectlyFromSysPageRector; @@ -40,4 +41,5 @@ $services->set(UseMethodGetPageShortcutDirectlyFromSysPageRector::class); $services->set(CopyMethodGetPidForModTSconfigRector::class); $services->set(BackendUserAuthenticationSimplelogRector::class); + $services->set(MoveLanguageFilesFromExtensionLangRector::class); }; diff --git a/src/Rector/v9/v3/MoveLanguageFilesFromExtensionLangRector.php b/src/Rector/v9/v3/MoveLanguageFilesFromExtensionLangRector.php new file mode 100644 index 000000000..82f891079 --- /dev/null +++ b/src/Rector/v9/v3/MoveLanguageFilesFromExtensionLangRector.php @@ -0,0 +1,78 @@ + 'about/Resources/Private/Language/Modules/locallang_alt_intro.xlf', + 'lang/Resources/Private/Language/locallang_alt_doc.xlf' => 'backend/Resources/Private/Language/locallang_alt_doc.xlf', + 'lang/Resources/Private/Language/locallang_login.xlf' => 'backend/Resources/Private/Language/locallang_login.xlf', + 'lang/Resources/Private/Language/locallang_common.xlf' => 'core/Resources/Private/Language/locallang_common.xlf', + 'lang/Resources/Private/Language/locallang_core.xlf' => 'core/Resources/Private/Language/locallang_core.xlf', + 'lang/Resources/Private/Language/locallang_general.xlf' => 'core/Resources/Private/Language/locallang_general.xlf', + 'lang/Resources/Private/Language/locallang_misc.xlf' => 'core/Resources/Private/Language/locallang_misc.xlf', + 'lang/Resources/Private/Language/locallang_mod_web_list.xlf' => 'core/Resources/Private/Language/locallang_mod_web_list.xlf', + 'lang/Resources/Private/Language/locallang_tca.xlf' => 'core/Resources/Private/Language/locallang_tca.xlf', + 'lang/Resources/Private/Language/locallang_tsfe.xlf' => 'core/Resources/Private/Language/locallang_tsfe.xlf', + 'lang/Resources/Private/Language/locallang_wizards.xlf' => 'core/Resources/Private/Language/locallang_wizards.xlf', + 'lang/Resources/Private/Language/locallang_browse_links.xlf' => 'recordlist/Resources/Private/Language/locallang_browse_links.xlf', + 'lang/Resources/Private/Language/locallang_tcemain.xlf' => 'workspaces/Resources/Private/Language/locallang_tcemain.xlf', + ]; + + public function getNodeTypes(): array + { + return [String_::class]; + } + + /** + * @param String_ $node + */ + public function refactor(Node $node): ?Node + { + $value = $this->getValue($node); + + foreach (self::MAPPING_OLD_TO_NEW_PATHS as $oldPath => $newPath) { + if (Strings::contains($value, $oldPath)) { + return new String_(str_replace($oldPath, $newPath, $value)); + } + } + + return null; + } + + /** + * @codeCoverageIgnore + */ + public function getDefinition(): RectorDefinition + { + return new RectorDefinition('', [ + new CodeSample(<<<'PHP' +use TYPO3\CMS\Core\Localization\LanguageService; +$languageService = new LanguageService(); +$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.no_title'); +PHP + , <<<'PHP' +use TYPO3\CMS\Core\Localization\LanguageService; +$languageService = new LanguageService(); +$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.no_title'); +PHP + ), + ]); + } +} diff --git a/stubs/Core/Localization/LanguageService.php b/stubs/Core/Localization/LanguageService.php index f295108aa..4f892f725 100644 --- a/stubs/Core/Localization/LanguageService.php +++ b/stubs/Core/Localization/LanguageService.php @@ -11,6 +11,9 @@ final class LanguageService { public function init(string $language): void { + } + public function sL($label): void + { } } diff --git a/tests/Rector/v9/v3/MoveLanguageFilesFromExtensionLang/Fixture/move_language_files.php.inc b/tests/Rector/v9/v3/MoveLanguageFilesFromExtensionLang/Fixture/move_language_files.php.inc new file mode 100644 index 000000000..da179a3bb --- /dev/null +++ b/tests/Rector/v9/v3/MoveLanguageFilesFromExtensionLang/Fixture/move_language_files.php.inc @@ -0,0 +1,207 @@ + [ + 'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.edit', + 'iconIdentifier' => 'actions-page-open', + 'callbackAction' => 'editFile' + ], + 'rename' => [ + 'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.rename', + 'iconIdentifier' => 'actions-edit-rename', + 'callbackAction' => 'renameFile' + ], + 'upload' => [ + 'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.upload', + 'iconIdentifier' => 'actions-edit-upload', + 'callbackAction' => 'uploadFile' + ], + 'new' => [ + 'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.new', + 'iconIdentifier' => 'actions-document-new', + 'callbackAction' => 'createFile' + ], + 'info' => [ + 'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.info', + 'iconIdentifier' => 'actions-document-info', + 'callbackAction' => 'openInfoPopUp' + ], + 'divider' => [ + 'type' => 'divider' + ], + 'copy' => [ + 'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.copy', + 'iconIdentifier' => 'actions-edit-copy', + 'callbackAction' => 'copyFile' + ], + 'copyRelease' => [ + 'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.copy', + 'iconIdentifier' => 'actions-edit-copy-release', + 'callbackAction' => 'copyReleaseFile' + ], + 'cut' => [ + 'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.cut', + 'iconIdentifier' => 'actions-edit-cut', + 'callbackAction' => 'cutFile' + ], + 'cutRelease' => [ + 'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.cutrelease', + 'iconIdentifier' => 'actions-edit-cut-release', + 'callbackAction' => 'cutReleaseFile' + ], + 'pasteInto' => [ + 'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.pasteinto', + 'iconIdentifier' => 'actions-document-paste-into', + 'callbackAction' => 'pasteFileInto' + ], + 'divider2' => [ + 'type' => 'divider' + ], + 'delete' => [ + 'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.delete', + 'iconIdentifier' => 'actions-edit-delete', + 'callbackAction' => 'deleteFile' + ], + ]; + + /** + * @var string + */ + private $labels = 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:'; + + protected function getLabel($key) + { + return sprintf($this->labels . $key); + } +} + +$languageService = new LanguageService(); +$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_alt_intro.xlf'); +$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_alt_doc.xlf'); +$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_login.xlf'); +$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf'); +$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf'); +$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf'); +$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf'); +$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf'); +$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf'); +$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_tsfe.xlf'); +$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf'); +$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_browse_links.xlf'); +$languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_tcemain.xlf'); + +$coreLabels = 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:'; +$languageService->sL($coreLabels.'labels.reload'); + +?> +----- + [ + 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.edit', + 'iconIdentifier' => 'actions-page-open', + 'callbackAction' => 'editFile' + ], + 'rename' => [ + 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.rename', + 'iconIdentifier' => 'actions-edit-rename', + 'callbackAction' => 'renameFile' + ], + 'upload' => [ + 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.upload', + 'iconIdentifier' => 'actions-edit-upload', + 'callbackAction' => 'uploadFile' + ], + 'new' => [ + 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.new', + 'iconIdentifier' => 'actions-document-new', + 'callbackAction' => 'createFile' + ], + 'info' => [ + 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.info', + 'iconIdentifier' => 'actions-document-info', + 'callbackAction' => 'openInfoPopUp' + ], + 'divider' => [ + 'type' => 'divider' + ], + 'copy' => [ + 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.copy', + 'iconIdentifier' => 'actions-edit-copy', + 'callbackAction' => 'copyFile' + ], + 'copyRelease' => [ + 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.copy', + 'iconIdentifier' => 'actions-edit-copy-release', + 'callbackAction' => 'copyReleaseFile' + ], + 'cut' => [ + 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.cut', + 'iconIdentifier' => 'actions-edit-cut', + 'callbackAction' => 'cutFile' + ], + 'cutRelease' => [ + 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.cutrelease', + 'iconIdentifier' => 'actions-edit-cut-release', + 'callbackAction' => 'cutReleaseFile' + ], + 'pasteInto' => [ + 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.pasteinto', + 'iconIdentifier' => 'actions-document-paste-into', + 'callbackAction' => 'pasteFileInto' + ], + 'divider2' => [ + 'type' => 'divider' + ], + 'delete' => [ + 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.delete', + 'iconIdentifier' => 'actions-edit-delete', + 'callbackAction' => 'deleteFile' + ], + ]; + + /** + * @var string + */ + private $labels = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:'; + + protected function getLabel($key) + { + return sprintf($this->labels . $key); + } +} + +$languageService = new LanguageService(); +$languageService->sL('LLL:EXT:about/Resources/Private/Language/Modules/locallang_alt_intro.xlf'); +$languageService->sL('LLL:EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf'); +$languageService->sL('LLL:EXT:backend/Resources/Private/Language/locallang_login.xlf'); +$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf'); +$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf'); +$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf'); +$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf'); +$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf'); +$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf'); +$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_tsfe.xlf'); +$languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_wizards.xlf'); +$languageService->sL('LLL:EXT:recordlist/Resources/Private/Language/locallang_browse_links.xlf'); +$languageService->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang_tcemain.xlf'); + +$coreLabels = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:'; +$languageService->sL($coreLabels.'labels.reload'); + +?> diff --git a/tests/Rector/v9/v3/MoveLanguageFilesFromExtensionLang/MoveLanguageFilesFromExtensionLangRectorTest.php b/tests/Rector/v9/v3/MoveLanguageFilesFromExtensionLang/MoveLanguageFilesFromExtensionLangRectorTest.php new file mode 100644 index 000000000..8c4c2fe3b --- /dev/null +++ b/tests/Rector/v9/v3/MoveLanguageFilesFromExtensionLang/MoveLanguageFilesFromExtensionLangRectorTest.php @@ -0,0 +1,31 @@ +doTestFileInfo($file); + } + + public function provideDataForTest(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + protected function getRectorClass(): string + { + return MoveLanguageFilesFromExtensionLangRector::class; + } +}