diff --git a/src/Scanner.php b/src/Scanner.php index 31c794ff..c78e5a13 100644 --- a/src/Scanner.php +++ b/src/Scanner.php @@ -48,6 +48,8 @@ public function findTranslations() foreach ($this->disk->allFiles($this->scanPaths) as $file) { if (preg_match_all("/$matchingPattern/siU", $file->getContents(), $matches)) { foreach ($matches[2] as $key) { + // Decode php strings, so in the final JSON e.g. __('Don\'t') becomes "Don't" instead of "Don\\'t" + $key = stripcslashes($key); if (preg_match("/(^[a-zA-Z0-9:_-]+([.][^\1)\ ]+)+$)/siU", $key, $arrayMatches)) { [$file, $k] = explode('.', $arrayMatches[0], 2); $results['group'][$file][$k] = ''; diff --git a/tests/ScannerTest.php b/tests/ScannerTest.php index bceee00e..45389c36 100644 --- a/tests/ScannerTest.php +++ b/tests/ScannerTest.php @@ -31,7 +31,7 @@ public function it_finds_all_translations() $this->scanner = app()->make(Scanner::class); $matches = $this->scanner->findTranslations(); - $this->assertEquals($matches, ['single' => ['single' => ['This will go in the JSON array' => '', 'This will also go in the JSON array' => '', 'trans' => '']], 'group' => ['lang' => ['first_match' => ''], 'lang_get' => ['first' => '', 'second' => ''], 'trans' => ['first_match' => '', 'third_match' => ''], 'trans_choice' => ['with_params' => '']]]); + $this->assertEquals($matches, ['single' => ['single' => ['This will go in the JSON array' => '', 'This will also go in the JSON array' => '', 'This will go in the JSON array, and it\'ll properly unescape the apostrophe.' => '', 'trans' => '']], 'group' => ['lang' => ['first_match' => ''], 'lang_get' => ['first' => '', 'second' => ''], 'trans' => ['first_match' => '', 'third_match' => ''], 'trans_choice' => ['with_params' => '']]]); $this->assertCount(2, $matches); } } diff --git a/tests/fixtures/scan-tests/__.txt b/tests/fixtures/scan-tests/__.txt index 8b04d350..27cb283c 100644 --- a/tests/fixtures/scan-tests/__.txt +++ b/tests/fixtures/scan-tests/__.txt @@ -3,4 +3,6 @@ __('This will go in the JSON array') __( 'This will also go in the JSON array' -) \ No newline at end of file +) + +__('This will go in the JSON array, and it\'ll properly unescape the apostrophe.') \ No newline at end of file