Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to resolve the request translation #4065

Closed
cansozeri opened this issue Jun 26, 2014 · 18 comments
Closed

Unable to resolve the request translation #4065

cansozeri opened this issue Jun 26, 2014 · 18 comments

Comments

@cansozeri
Copy link

Hi,

If possible can you include the message "Unable to resolve the request" into the yii.php so this error message can be translated.

//in module php
throw new InvalidRouteException('Unable to resolve the request "' . ($id === '' ? $route : $id . '/' . $route) . '".');

//in controller.php

 throw new InvalidRouteException('Unable to resolve the request: ' . $this->getUniqueId() . '/' . $id);
@samdark
Copy link
Member

samdark commented Jun 26, 2014

Is it displayed to end user?

@cansozeri
Copy link
Author

Yes, in my error page it is displaying ..

ekran alnts

@samdark
Copy link
Member

samdark commented Jun 26, 2014

Is it actually useful for end user?

@cansozeri
Copy link
Author

I think yes it is : ) Sometimes there will be a missing link on the website and we have to trigger an error if this link is missing. So in a translated site an english error is weird. If it is not so hard I think you should add this error in translation file ...

@samdark
Copy link
Member

samdark commented Jun 26, 2014

Yes, it's probably OK to display something but does Unable to resolve request X actually tell user something useful?

@samdark
Copy link
Member

samdark commented Jun 26, 2014

btw., do you have YII_DEBUG=false?

@cansozeri
Copy link
Author

Ok what am I going to display to my user then : )) Yes my debug is false now and the error message is same .. This is my error function in controller.

 public function actionError()
    {

        $message = Yii::$app->errorHandler->error;
        return $this->render('error.htm',[
            'message' => $message,
        ]

        );
    }

@klevron
Copy link
Contributor

klevron commented Jun 26, 2014

#3593

I keep thinking exceptions shown to users should be translated.

@cansozeri
Copy link
Author

Now if my link is missing or misconfigured controller view etc.. The user should see this error message. "Unable to resolve the request". So it is really weird to see an english error on a translated site .. If another thing I can do to prevent this it is ok, but if not then it should be great to add this error message in translation file.

@samdark
Copy link
Member

samdark commented Jun 26, 2014

Shouldn't user get just a regular 404 in this case w/o any cryptic messages that are intended for developers?

@cansozeri
Copy link
Author

Ok sounds good how can I do this ?? I send my controller error function above ..

@samdark
Copy link
Member

samdark commented Jun 26, 2014

Via application config you can customize error handler settings:

'components' => [
    'errorHandler' => [
        'errorView' => '@app/views/errorHandler/error.php',
    ],
]

Then copy framework's views/errorHandler/error.php to your protected/views/errorHandler/error.php and customize it.

@cansozeri
Copy link
Author

I did this I have my own error.php file. I am asking that I have sent the error to my view file and when exception occurs it is coming with this message.

So I think I can do this like this.

if(404==Yii::$app->errorHandler->error->code){
$message = 'Translated message';
}

@samdark
Copy link
Member

samdark commented Jun 26, 2014

Something like

if ($code === 404) {
    $message = 'Translated message';
}

@samdark
Copy link
Member

samdark commented Jun 26, 2014

In a view you already have all data so no need to call Yii::$app->errorHandler.

@cansozeri
Copy link
Author

Ok thanx ...

@cansozeri
Copy link
Author

I did this because I want to do it with my controller but exception messages not affected with my controller. Is it normal ?? My error.htm loaded succesfully but without loading the error controller.
Because I have deleted the error function and it still works and show the error page : ))

'errorHandler' => [
            'errorAction' => 'site/error',
        ],

in site controller

/* I added this method as per documentation */

    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
                'view'=>'@app/views/site/error.htm',
            ],     
        ];
    }

 public function actionError()
    {

        if(404==Yii::$app->errorHandler->error->code)
        {
            $message = 'Translated message';
        }
        else
        {
            $message = Yii::$app->errorHandler->error;
        }

        return $this->render('error.htm',[
            'message' => $message,
        ]

        );
  }

@samdark
Copy link
Member

samdark commented Jun 26, 2014

Remove public function actions().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants