-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #1473 Translatable exception messages (javiereguiluz)
This PR was squashed before being merged into the master branch (closes #1473). Discussion ---------- Translatable exception messages I was working on #1424 when I realized that the proposed solution was too complicated. The problem was that we can't translate exceptions inside the templates (the natural place) because we don't store the translation parameters anywhere. So, I propose to create a new `ExceptionContext` class to store all the related information about exceptions. The idea would be to add in the translation files the public message displayed to the end-user. In contrast, the debug message stored in the log file (and displayed in the `dev` environment) would always be in English. In this example, a French user would see this in the browser: ![exception-public](https://cloud.githubusercontent.com/assets/73419/22000123/ca158084-dc3d-11e6-9109-700f2c8aa4c8.png) ...and this message in the log file: ![exception-private](https://cloud.githubusercontent.com/assets/73419/22000129/d0d2c648-dc3d-11e6-9b1b-fdacabb9e55e.png) --- This PR is still WIP but ... what do you think? Thanks! Commits ------- f62d3ea Translatable exception messages
- Loading branch information
Showing
19 changed files
with
208 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the EasyAdminBundle. | ||
* | ||
* (c) Javier Eguiluz <javier.eguiluz@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JavierEguiluz\Bundle\EasyAdminBundle\Exception; | ||
|
||
/** | ||
* @author Javier Eguiluz <javier.eguiluz@gmail.com> | ||
*/ | ||
class ExceptionContext | ||
{ | ||
private $publicMessage; | ||
private $debugMessage; | ||
private $parameters; | ||
private $statusCode; | ||
|
||
public function __construct($publicMessage, $debugMessage = '', $parameters = array(), $statusCode = 500) | ||
{ | ||
$this->publicMessage = $publicMessage; | ||
$this->debugMessage = $debugMessage; | ||
$this->parameters = $parameters; | ||
$this->statusCode = $statusCode; | ||
} | ||
|
||
public function getPublicMessage() | ||
{ | ||
return $this->publicMessage; | ||
} | ||
|
||
public function getDebugMessage() | ||
{ | ||
return $this->debugMessage; | ||
} | ||
|
||
public function getParameters() | ||
{ | ||
return $this->parameters; | ||
} | ||
|
||
public function getTranslationParameters() | ||
{ | ||
return $this->transformIntoTranslationPlaceholders($this->parameters); | ||
} | ||
|
||
public function getStatusCode() | ||
{ | ||
return $this->statusCode; | ||
} | ||
|
||
private function transformIntoTranslationPlaceholders(array $parameters) | ||
{ | ||
$placeholders = array(); | ||
foreach ($parameters as $key => $value) { | ||
if ('%' !== $key[0]) { | ||
$key = '%'.$key; | ||
} | ||
if ('%' !== substr($key, -1)) { | ||
$key = $key.'%'; | ||
} | ||
|
||
$placeholders[$key] = $value; | ||
} | ||
|
||
return $placeholders; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.