diff --git a/src/Services/Parser.php b/src/Services/Parser.php index 145e504..1bde461 100644 --- a/src/Services/Parser.php +++ b/src/Services/Parser.php @@ -101,7 +101,7 @@ protected function getStrings(SplFileInfo $file): Collection */ protected function searchPattern(string $function): string { - return '/('.$function.')\(\h*[\'"](.+)[\'"]\h*[),]/U'; + return '/(' . $function . ')\([\r\n\s]{0,}\h*[\'"](.+)[\'"]\h*[\r\n\s]{0,}[),]/U'; } /** diff --git a/tests/LocalizatorTest.php b/tests/LocalizatorTest.php index 863edb2..4334297 100644 --- a/tests/LocalizatorTest.php +++ b/tests/LocalizatorTest.php @@ -165,4 +165,50 @@ public function testLocalizeCommandWhereKeysAreEscapedWithSlashes(): void // Cleanup. self::flushDirectories('lang', 'views'); } + + public function testLocalizeCommandWithMultilineMessages(): void + { + $this->createTestView("__(\n'stand with ukraine'\n)"); + + // Run localize command. + $this->artisan('localize') + ->assertExitCode(0); + + // Do created locale files exist? + self::assertJsonLangFilesExist('en'); + + // Do their contents match the expected results? + $enJsonContents = $this->getJsonLangContents('en'); + + // Did it sort the translation keys like we expected? + self::assertSame([ + 'stand with ukraine' => 'stand with ukraine', + ], $enJsonContents); + + // Cleanup. + self::flushDirectories('lang', 'views'); + } + + public function testLocalizeCommandWithMultilineMessagesAndSpaces(): void + { + $this->createTestView("{{ __(\n 'stand with ukraine' \n) }}"); + + // Run localize command. + $this->artisan('localize') + ->assertExitCode(0); + + // Do created locale files exist? + self::assertJsonLangFilesExist('en'); + + // Do their contents match the expected results? + $enJsonContents = $this->getJsonLangContents('en'); + + // Did it sort the translation keys like we expected? + self::assertSame([ + 'stand with ukraine' => 'stand with ukraine', + ], $enJsonContents); + + // Cleanup. + self::flushDirectories('lang', 'views'); + } }