Answer the question
In order to leave comments, you need to log in
Where are the 404 and 403 error files in Yii2 (I want to translate these pages)?
In the file error.php in the views folder, I have already translated part of the text.
<div class="site-error">
<h1><?= Html::encode($this->title) ?></h1>
<div class="alert alert-danger">
<?= nl2br(Html::encode($message)) ?>
Answer the question
In order to leave comments, you need to log in
Figured it out myself:
vendor\yiisoft\yii2-gii\Module.php
if (Yii::$app instanceof \yii\web\Application && !$this->checkAccess()) {
throw new ForbiddenHttpException('You are not allowed to access this page.');
}
Hello fellow programmers.
---
The code is not as scary as it is interpreted ))
Oddly enough, I found a hint for this question in the "views/site/"
folder
File: error.php
===
The developers realized that programmers would face such a question, so they left hints:
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $name string */
/* @var $message string */
/* @var $exception Exception */
$this->title = $name;
?>
<?=$name?>
<?=$this->title;?>
<?=$message;?>
<?=Yii::t('yii','значение');?>
/* @var $exception Exception */
class HttpException extends UserException
{
/**
* @var int HTTP status code, such as 403, 404, 500, etc.
*/
public $statusCode;
/**
* Constructor.
* @param int $status HTTP status code, such as 404, 500, etc.
* @param string $message error message
* @param int $code error code
* @param \Exception $previous The previous exception used for the exception chaining.
*/
public function __construct($status, $message = null, $code = 0, \Exception $previous = null)
{
$this->statusCode = $status;
parent::__construct($message, $code, $previous);
}
/**
* @return string the user-friendly name of this exception
*/
public function getName()
{
if (isset(Response::$httpStatuses[$this->statusCode])) {
return Response::$httpStatuses[$this->statusCode];
} else {
return 'Error';
}
}
}
public $statusCode;
<?=($exception->statusCode == '404') ? $this->title = "Ошибка 404" : ''; ?>
<?=($exception->statusCode == '403') ? $this->title = "Доступ запрещён" : ''; ?>
<?=($exception->statusCode == '500') ? $this->title = "Внутренняя ошибка сервера" : ''; ?>
<?php
return [
...
'Page not found.' => 'Страница не найдена.',
'You are not allowed to perform this action.' => 'Вам не разрешено производить данное действие.',
'An internal server error occurred.' => 'Возникла внутренняя ошибка сервера.',
...
];
<?=Yii::t('yii', 'Page not found.');?> и т д...
in the application config
sourceLanguage => en
language => ru
ps read the documentation
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question