Skip to content

Commit ca9b39a

Browse files
author
rotimi
committed
Increased localization in \SlimMvcTools\HtmlErrorRenderer
1 parent 26a9887 commit ca9b39a

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

src/HtmlErrorRenderer.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ public function __invoke(\Throwable $exception, bool $displayErrorDetails): stri
2222

2323
if ($displayErrorDetails) {
2424

25+
$detailsText = $this->getLocalizedText('html_error_renderer_text_details', 'Details');
26+
2527
$html = "<p>{$this->defaultErrorDescription}:</p>";
26-
$html .= '<h2>Details</h2>';
28+
$html .= "<h2>{$detailsText}</h2>";
2729
$html .= $this->renderExceptionFragment($exception);
2830

2931
} else {
@@ -54,13 +56,20 @@ public function renderHtmlBody(string $title = '', string $html = ''): string {
5456

5557
private function renderExceptionFragment(\Throwable $exception): string {
5658

57-
$html = sprintf('<div><strong>Type:</strong> %s</div>', $exception::class);
59+
$typeText = $this->getLocalizedText('html_error_renderer_text_type', 'Type');
60+
$codeText = $this->getLocalizedText('html_error_renderer_text_code', 'Code');
61+
$mssgText = $this->getLocalizedText('html_error_renderer_text_mssg', 'Message');
62+
$fileText = $this->getLocalizedText('html_error_renderer_text_file', 'File');
63+
$lineText = $this->getLocalizedText('html_error_renderer_text_line', 'Line');
64+
$traceText = $this->getLocalizedText('html_error_renderer_text_trace', 'Trace');
65+
66+
$html = sprintf("<div><strong>{$typeText}:</strong> %s</div>", $exception::class);
5867
$code = $exception->getCode();
59-
$html .= sprintf('<div><strong>Code:</strong> %s</div>', $code);
60-
$html .= sprintf('<div><strong>Message:</strong> %s</div>', nl2br(htmlentities($exception->getMessage()), false));
61-
$html .= sprintf('<div><strong>File:</strong> %s</div>', $exception->getFile());
62-
$html .= sprintf('<div><strong>Line:</strong> %s</div>', $exception->getLine());
63-
$html .= '<h2>Trace</h2>';
68+
$html .= sprintf("<div><strong>{$codeText}:</strong> %s</div>", $code);
69+
$html .= sprintf("<div><strong>{$mssgText}:</strong> %s</div>", nl2br(htmlentities($exception->getMessage()), false));
70+
$html .= sprintf("<div><strong>{$fileText}:</strong> %s</div>", $exception->getFile());
71+
$html .= sprintf("<div><strong>{$lineText}:</strong> %s</div>", $exception->getLine());
72+
$html .= "<h2>{$traceText}</h2>";
6473

6574
return $html . sprintf('<pre>%s</pre>', nl2br(htmlentities($exception->getTraceAsString()), false) );
6675
}

tests/fake-smvc-app-root/config/languages/en_US.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,12 @@
5353
\Slim\Exception\HttpNotImplementedException::class . '_description' => "The server does not support the functionality required to fulfill the request.",
5454
\Slim\Exception\HttpTooManyRequestsException::class . '_description' => "The client application has surpassed its rate limit, or number of requests they can send in a given period of time.",
5555
\Slim\Exception\HttpUnauthorizedException::class . '_description' => "The request requires valid user authentication.",
56+
57+
'html_error_renderer_text_details' => 'Details',
58+
'html_error_renderer_text_type' => 'Type',
59+
'html_error_renderer_text_code' => 'Code',
60+
'html_error_renderer_text_mssg' => 'Message',
61+
'html_error_renderer_text_file' => 'File',
62+
'html_error_renderer_text_line' => 'Line',
63+
'html_error_renderer_text_trace' => 'Trace',
5664
];

tests/fake-smvc-app-root/config/languages/fr_CA.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,12 @@
5353
\Slim\Exception\HttpNotImplementedException::class . '_description' => "Le serveur ne prend pas en charge les fonctionnalités requises pour répondre à la demande.",
5454
\Slim\Exception\HttpTooManyRequestsException::class . '_description' => "L'application client a dépassé sa limite de débit, ou le nombre de requêtes qu'elle peut envoyer au cours d'une période de temps donnée.",
5555
\Slim\Exception\HttpUnauthorizedException::class . '_description' => "La demande nécessite une authentification utilisateur valide.",
56+
57+
'html_error_renderer_text_details' => 'Détails',
58+
'html_error_renderer_text_type' => 'Type',
59+
'html_error_renderer_text_code' => 'Code',
60+
'html_error_renderer_text_mssg' => 'Message',
61+
'html_error_renderer_text_file' => 'Fichier',
62+
'html_error_renderer_text_line' => 'Ligne',
63+
'html_error_renderer_text_trace' => 'Tracé',
5664
];

0 commit comments

Comments
 (0)