Welcome Guest, Not a member yet? Register   Sign In
Localised 404 error message based on URI segment
#1

(This post was last modified: 02-09-2024, 12:23 PM by Muzikant.)

Hi. I am trying to get a localised 404 error message, if URI segment with supported language is present. If it is not present, it should fallback to default language, as it is with basic localisation.

There is a support for localisation:
PHP Code:
$routes->get('{locale}/books''App\Books::index'); 

And override method for 404 error mesage.
PHP Code:
$routes->set404Override('App\Errors::show404'); 

Is it possible to get something like this?
PHP Code:
$routes->set404Override('{locale}\App\Errors::show404'); 

If you know what I mean. Or I have to check URI segments manually in the override method? Do you have any suggestions?
Reply
#2

You need to write code for it in the 404 controller.
You can get the URI segments:
PHP Code:
$segments $this->request->getUri()->getSegments(); 
Reply
#3

That is what I thought. Thank you for your answer.
Reply
#4

A localized 404 error message based on URI segment enhances user experience by providing context-specific guidance in the user's preferred language, aiding navigation and reducing frustration.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB