Welcome Guest, Not a member yet? Register   Sign In
locale do not work on 404
#1

PHP 8.1, CodeIgniter 4.3.7 fresh instalation, production mode.

Copy "es" folder from languages zip to "app/Language" and change "app/Config/App.php" that way:
PHP Code:
public $defaultLocale 'es';
public 
$negotiateLocale false;
public 
$supportedLocales = ['es''en'];
public 
$appTimezone 'Europe/Madrid'

In browser go to URL + "ajskldf", and see 404 error page:
Code:
404 - File Not Found

Sorry! Cannot seem to find the page you were looking for.

I try:
PHP Code:
php spark x 

I see the error message translated:
Code:
CodeIgniter v4.3.7 Command Line Tool - Server Time: 2023-08-22 10:09:35 UTC+02:00

Comando "x" no encontrado.

I know in develop mode this message is hard coded, but message is diferent, is like:
Code:
404 - File Not Found

Can't find a route for 'get: ajskldf'.

I'm talking about production mode 404 not being translated.
Reply
#2

See https://github.com/codeigniter4/translat...anguage/es
There is no translation for Errors.pageNotFound.
Reply
#3

Indeed there is no file called Errors. But in HTML.php (https://github.com/codeigniter4/translat...s/HTTP.php) we have:
Code:
    // Page Not Found
    'pageNotFound'      => 'Página no encontrada', // 'Page Not Found',
    'emptyController'    => 'Ningún controlador especificado.', // 'No Controller specified.',
    'controllerNotFound' => 'Controlador o su método no encontrado: {0}::{1}', // 'Controller or its method is not found: {0}::{1}',
    'methodNotFound'    => 'No se encontró el método del controlador: {0}', // 'Controller method is not found: {0}',

in previous version of framework worked as spected.

In 4.2.0 and 4.2.1 there was a bug:

https://forum.codeigniter.com/showthread.php?tid=82276

and was fixed in 4.2.2:

https://github.com/codeigniter4/CodeIgniter4/pull/6202

But now, I'm testing 4.3.7 and fails again I don't know why.
Reply
#4

It is because there is no translation for Errors.pageNotFound.
Forget about 4.2.
Reply
#5

Just for other people reference:

For 404 not found locale, is needed a file called app/Languages/XX/Errors.php with the following 4 strings:
Code:
return [
    'pageNotFound'    => '404 - pagina non trovata',
    'sorryCannotFind' => 'Spiacente! Non riesco a trovare la pagina che stavi cercando.',
    'whoops'          => 'Ops!',
    'weHitASnag'      => 'Sembra che abbiamo incontrato un intoppo. Per favore riprova più tardi...',
];

Although translation site release is for 4.3.6 there are plenty of languages without this file.

Thank you, kenjis, for pointing me in the right direction.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB