8000 [Bugfix] Prevent error translator returning the translation key · CodingSeo/laravel-json-api@a757f4c · GitHub
[go: up one dir, main page]

Skip to content

Commit a757f4c

Browse files
committed
[Bugfix] Prevent error translator returning the translation key
Fixes a change in behaviour introduced in Laravel 7.28.
1 parent 9cbf4ca commit a757f4c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
All notable changes to this project will be documented in this file. This project adheres to
33
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).
44

5+
## Unreleased
6+
7+
### Fixed
8+
- The error translator will now detect if the translated value is identical to the translation
9+
key path, and return `null` when it is. This fixes behaviour that changed in Laravel 7.28.
10+
511
## [2.1.0] - 2020-09-04
612

713
### Added

src/Document/Error/Translator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,13 @@ public function call(\Closure $closure, ...$args): ErrorInterface
529529
*/
530530
protected function trans(string $key, string $member, array $replace = [], ?string $locale = null)
531531
{
532-
return $this->translator->get(
533-
"jsonapi::errors.{$key}.{$member}",
532+
$value = $this->translator->get(
533+
$key = "jsonapi::errors.{$key}.{$member}",
534534
$replace,
535535
$locale
536536
) ?: null;
537+
538+
return ($key !== $value) ? $value : null;
537539
}
538540

539541
/**

0 commit comments

Comments
 (0)
0