-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Use alternative language paths for locallang
Resolves: #1057
- Loading branch information
1 parent
eda00ff
commit 12b4c99
Showing
5 changed files
with
321 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/Rector/v9/v3/MoveLanguageFilesFromExtensionLangRector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\Rector\v9\v3; | ||
|
||
use Nette\Utils\Strings; | ||
use PhpParser\Node; | ||
use PhpParser\Node\Scalar\String_; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Rector\Core\RectorDefinition\CodeSample; | ||
use Rector\Core\RectorDefinition\RectorDefinition; | ||
|
||
/** | ||
* @see https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/9.3/Deprecation-84680-MoveLastLanguageFilesAwayFromExtlangAndRemoveExtlangCompletely.html | ||
*/ | ||
final class MoveLanguageFilesFromExtensionLangRector extends AbstractRector | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private const MAPPING_OLD_TO_NEW_PATHS = [ | ||
'lang/Resources/Private/Language/locallang_alt_intro.xlf' => '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 | ||
), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
tests/Rector/v9/v3/MoveLanguageFilesFromExtensionLang/Fixture/move_language_files.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
<?php | ||
|
||
namespace Ssch\TYPO3Rector\Tests\Rector\v9\v3\MoveLanguageFilesFromExtensionLang\Fixture; | ||
use TYPO3\CMS\Core\Localization\LanguageService; | ||
|
||
/** Keep it in the comments LLL:EXT:lang/Resources/Private/Language/locallang_alt_intro.xlf */ | ||
|
||
class MySpecialClass | ||
{ | ||
protected $itemsConfiguration = [ | ||
'edit' => [ | ||
'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'); | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Ssch\TYPO3Rector\Tests\Rector\v9\v3\MoveLanguageFilesFromExtensionLang\Fixture; | ||
use TYPO3\CMS\Core\Localization\LanguageService; | ||
|
||
/** Keep it in the comments LLL:EXT:lang/Resources/Private/Language/locallang_alt_intro.xlf */ | ||
|
||
class MySpecialClass | ||
{ | ||
protected $itemsConfiguration = [ | ||
'edit' => [ | ||
'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'); | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
...v9/v3/MoveLanguageFilesFromExtensionLang/MoveLanguageFilesFromExtensionLangRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\Tests\Rector\v9\v3\MoveLanguageFilesFromExtensionLang; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Ssch\TYPO3Rector\Rector\v9\v3\MoveLanguageFilesFromExtensionLangRector; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class MoveLanguageFilesFromExtensionLangRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideDataForTest() | ||
*/ | ||
public function test(SmartFileInfo $file): void | ||
{ | ||
$this->doTestFileInfo($file); | ||
} | ||
|
||
public function provideDataForTest(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
protected function getRectorClass(): string | ||
{ | ||
return MoveLanguageFilesFromExtensionLangRector::class; | ||
} | ||
} |