Skip to content

Commit

Permalink
[6.x] Fix bug caused by localisation refactoring (#29967)
Browse files Browse the repository at this point in the history
* Fix bug caused by localisation refactoring

In Laravel 5.8 calling __(null) would return null. Due to the code refactoring __(null) now returns a Translator object. As this is not mentioned in the Upgrade Guide I presume this is an unintended bug. This pull request resolves the issue.

Details:
In Laravel 5.8 you could run the following code in a blade:
    @Dump(trans(null))  // Returns Translator object in 5.8 and 6.
    @Dump(__(null))  // Returns null in 5.8 and Translator object in 6.

    {{ __(null) }} // Runs successfully on 5.8 fails on 6.0 see error below.

Facade\Ignition\Exceptions\ViewException
htmlspecialchars() expects parameter 1 to be string, object given (View: resources\views\welcome.blade.php)

If it is intentional the upgrade guide should be updated to put an if statement checking for null for each translatable variable that could contain null.

* Fixed code style
  • Loading branch information
marijnkampf authored and taylorotwell committed Sep 12, 2019
1 parent e879699 commit 06d22a8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Foundation/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,10 @@ function trans_choice($key, $number, array $replace = [], $locale = null)
*/
function __($key = null, $replace = [], $locale = null)
{
if (is_null($key)) {
return $key;
}

return trans($key, $replace, $locale);
}
}
Expand Down

0 comments on commit 06d22a8

Please sign in to comment.