Skip to content

Commit

Permalink
add support for newlines and spaces (#35)
Browse files Browse the repository at this point in the history
* added newlines and spaces to search pattern

* tests for search pattern with newlines and spaces
  • Loading branch information
rexlManu authored Mar 12, 2022
1 parent a2cf821 commit 826900c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Services/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down
46 changes: 46 additions & 0 deletions tests/LocalizatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit 826900c

Please sign in to comment.