Skip to content

Commit 826900c

Browse files
authored
add support for newlines and spaces (#35)
* added newlines and spaces to search pattern * tests for search pattern with newlines and spaces
1 parent a2cf821 commit 826900c

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/Services/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected function getStrings(SplFileInfo $file): Collection
101101
*/
102102
protected function searchPattern(string $function): string
103103
{
104-
return '/('.$function.')\(\h*[\'"](.+)[\'"]\h*[),]/U';
104+
return '/(' . $function . ')\([\r\n\s]{0,}\h*[\'"](.+)[\'"]\h*[\r\n\s]{0,}[),]/U';
105105
}
106106

107107
/**

tests/LocalizatorTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,50 @@ public function testLocalizeCommandWhereKeysAreEscapedWithSlashes(): void
165165
// Cleanup.
166166
self::flushDirectories('lang', 'views');
167167
}
168+
169+
public function testLocalizeCommandWithMultilineMessages(): void
170+
{
171+
$this->createTestView("__(\n'stand with ukraine'\n)");
172+
173+
// Run localize command.
174+
$this->artisan('localize')
175+
->assertExitCode(0);
176+
177+
// Do created locale files exist?
178+
self::assertJsonLangFilesExist('en');
179+
180+
// Do their contents match the expected results?
181+
$enJsonContents = $this->getJsonLangContents('en');
182+
183+
// Did it sort the translation keys like we expected?
184+
self::assertSame([
185+
'stand with ukraine' => 'stand with ukraine',
186+
], $enJsonContents);
187+
188+
// Cleanup.
189+
self::flushDirectories('lang', 'views');
190+
}
191+
192+
public function testLocalizeCommandWithMultilineMessagesAndSpaces(): void
193+
{
194+
$this->createTestView("{{ __(\n 'stand with ukraine' \n) }}");
195+
196+
// Run localize command.
197+
$this->artisan('localize')
198+
->assertExitCode(0);
199+
200+
// Do created locale files exist?
201+
self::assertJsonLangFilesExist('en');
202+
203+
// Do their contents match the expected results?
204+
$enJsonContents = $this->getJsonLangContents('en');
205+
206+
// Did it sort the translation keys like we expected?
207+
self::assertSame([
208+
'stand with ukraine' => 'stand with ukraine',
209+
], $enJsonContents);
210+
211+
// Cleanup.
212+
self::flushDirectories('lang', 'views');
213+
}
168214
}

0 commit comments

Comments
 (0)