CodeIgniter Forums
Localised 404 error message based on URI segment - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Localised 404 error message based on URI segment (/showthread.php?tid=89930)



Localised 404 error message based on URI segment - Muzikant - 02-09-2024

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?


RE: Localised 404 error message based on URI segment - kenjis - 02-09-2024

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



RE: Localised 404 error message based on URI segment - Muzikant - 02-10-2024

That is what I thought. Thank you for your answer.


RE: Localised 404 error message based on URI segment - romi62 - 04-05-2024

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.