Skip to content

Commit d030b3d

Browse files
committed
[Translation] fixed JSON loader on PHP 7 when file is empty
1 parent cdd2168 commit d030b3d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Loader/JsonFileLoader.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ public function load($resource, $locale, $domain = 'messages')
3535
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
3636
}
3737

38-
$messages = json_decode(file_get_contents($resource), true);
38+
$messages = array();
39+
if ($data = file_get_contents($resource)) {
40+
$messages = json_decode($data, true);
3941

40-
if (0 < $errorCode = json_last_error()) {
41-
throw new InvalidResourceException(sprintf('Error parsing JSON - %s', $this->getJSONErrorMessage($errorCode)));
42+
if (0 < $errorCode = json_last_error()) {
43+
throw new InvalidResourceException(sprintf('Error parsing JSON - %s', $this->getJSONErrorMessage($errorCode)));
44+
}
4245
}
4346

4447
if (null === $messages) {

0 commit comments

Comments
 (0)