Skip to content

Commit

Permalink
Strip slashes from translation keys (#17)
Browse files Browse the repository at this point in the history
Co-authored-by: Amir <[email protected]>
  • Loading branch information
Amir Rami and Amir authored May 18, 2021
1 parent 3553236 commit 632059b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Services/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function parseKeys(Collection $files): void
return $this->getStrings($file);
})
->flatten()
->map(function (string $string) {
return stripslashes($string);
})
->each(function (string $string) {
if ($this->isDotKey($string)) {
$this->defaultKeys->push($string);
Expand Down
28 changes: 28 additions & 0 deletions tests/LocalizatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,32 @@ public function testLocalizeCommandByMergingTheExistingTranslations(): void
// Cleanup.
self::flushDirectories('lang', 'views');
}

/**
* @return void
*/
public function testLocalizeCommandWhereKeysAreEscapedWithSlashes(): void
{
$this->createTestView("{{ __('Amir\'s PC') }} {{ __('Jacob\'s Ladder') }} {{ __('mom\'s spaghetti') }}");

// 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([
'Amir\'s PC' => 'Amir\'s PC',
'Jacob\'s Ladder' => 'Jacob\'s Ladder',
'mom\'s spaghetti' => 'mom\'s spaghetti',
], $enJsonContents);

// Cleanup.
self::flushDirectories('lang', 'views');
}
}

0 comments on commit 632059b

Please sign in to comment.