From 68f51e36715963a3ed64e5fc3b1b6c0a69f686df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Dobro=C5=88?= Date: Tue, 27 Jun 2023 21:17:45 +0200 Subject: [PATCH] Reduce the number of fbt namespaces during collecting --- src/fbt/Services/CollectFbtsService.php | 10 +++++++++- src/fbt/Services/TranslationsGeneratorService.php | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/fbt/Services/CollectFbtsService.php b/src/fbt/Services/CollectFbtsService.php index 0fa7643..022d07c 100644 --- a/src/fbt/Services/CollectFbtsService.php +++ b/src/fbt/Services/CollectFbtsService.php @@ -11,6 +11,7 @@ use fbt\Transform\NodeVisitor; use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Ternary; @@ -77,6 +78,13 @@ public function collectFromFiles(string $path, string $src, string $fbtCommonPat FbtHooks::storePhrases(); } + protected function compileCode(Expr $fbtFunctionClassCall): string + { + $code = $this->printer->prettyPrintExpr($fbtFunctionClassCall); + + return preg_replace('/\b(fbt\\\+)fbt/', 'fbt', $code); + } + protected function matchFbtCalls(Node $node): bool { return ($node instanceof FuncCall @@ -114,7 +122,7 @@ protected function collectFromOneFile(string $source, string $path): bool echo "\033[15m$path \033[0m" . PHP_EOL; foreach ($fbtFunctionCalls as $fbtFunctionCall) { - $code = $this->printer->prettyPrintExpr($fbtFunctionCall); + $code = $this->compileCode($fbtFunctionCall); $line = $fbtFunctionCall->getLine(); try { diff --git a/src/fbt/Services/TranslationsGeneratorService.php b/src/fbt/Services/TranslationsGeneratorService.php index fda3483..48f326f 100644 --- a/src/fbt/Services/TranslationsGeneratorService.php +++ b/src/fbt/Services/TranslationsGeneratorService.php @@ -251,8 +251,8 @@ public function generateTranslations(string $source, $translationsPath, $inputPa { "fb-locale": "sk_SK", "translations": [] - }, - } + } + ] }' ); }