From 2ee9f4fc61ce159ebb628e220e88c01d8026e0bd Mon Sep 17 00:00:00 2001 From: Manuel Donini Date: Wed, 5 Oct 2022 12:09:45 +0200 Subject: [PATCH] Catch also translation strings with parameters (#1) * Catch also translation strings with parameters * Fix: catch also white spaces or line breaks outside the translation string I changed the regex to catch translation string with parameters like this: `__('Hello :user_name', ['user_name' => $user->name])` and even this weird one: ``` __( 'Hello :user_name' , // I deliberately put this comma here ['user_name' => $user->name] ) ``` --- src/Command/TranslationHelperCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/TranslationHelperCommand.php b/src/Command/TranslationHelperCommand.php index 0ed7062..2bebed2 100644 --- a/src/Command/TranslationHelperCommand.php +++ b/src/Command/TranslationHelperCommand.php @@ -102,7 +102,7 @@ private function getTranslationKeysFromFunction(&$keys, $functionName, $content) { $matches = []; - preg_match_all("#{$functionName}\(\'(.*?)\'\)#", $content, $matches); + preg_match_all("#{$functionName}\(\s*\'(.*?)\'\s*[\)\,]#", $content, $matches); if (! empty($matches)) { foreach ($matches[1] as $match) {