CodeIgniter Forums
Validation error messages keep being loaded from system - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Validation error messages keep being loaded from system (/showthread.php?tid=90832)



Validation error messages keep being loaded from system - kabeza - 05-10-2024

Hi
I'm trying to translate the error messages from Validation service:

I've set in app/Config/App.php

Code:
public string $defaultLocale = 'es';

public array $supportedLocales = ['en', 'es'];

I've also created (as stated in userguide) the folder and file

Code:
app/Language/es/Validation.php

But the error messages keep being loaded from vendor/codeigniter4/framework/system/Language/en/Validation.php (I've confirmed this by changing strings there and trying again)

Am I ignoring anything else?


RE: Validation error messages keep being loaded from system - ALTITUDE_DEV - 05-10-2024

Hi do you have follow this steps :

Step 1. in your App.php set defaultlocale + supportedLocales
Step 2. make a file in app/Languages/es/Validation.php

example:

PHP Code:
<?php

// override core en language system validation or define your own en language validation message
return [
'keyname' => 'your Translation here'
]; 



RE: Validation error messages keep being loaded from system - kabeza - 05-10-2024

(05-10-2024, 07:27 AM)ALTITUDE_DEV Wrote: Hi do you have follow this steps :

Step 1. in your App.php set defaultlocale + supportedLocales
Step 2. make a file in app/Languages/es/Validation.php

example:

PHP Code:
<?php

// override core en language system validation or define your own en language validation message
return [
'keyname' => 'your Translation here'
]; 

Yes, I've followed the steps from userguide etc.

[Image: tNJMtjw.jpeg]


RE: Validation error messages keep being loaded from system - ozornick - 05-10-2024

Check locale in Request? dd(request()); in Controller. You may be overwriting the locale in the filter


RE: Validation error messages keep being loaded from system - kabeza - 05-13-2024

(05-10-2024, 09:13 AM)ozornick Wrote: Check locale in Request? dd(request()); in Controller. You may be overwriting the locale in the filter

The value for locale is correct, it is "es"

[Image: 5doUQA3.jpeg]


The process I do in the controller is just

Code:
     
$this->validation->setRules([
    'ssn'  => 'required|numeric|min_length[7]|max_length[8]',
    'gender' => 'required|string|min_length[1]|max_length[1]',
]);

if (!$this->validation->withRequest($this->request)->run()) {
    return $this->validation->getErrors();   
}



RE: Validation error messages keep being loaded from system - ozornick - 05-13-2024

I don't understand what the reason is. All right.
In such difficult cases, I perform the debug of the system files.
Let's say you need to track where the language is being reset. Try dd(...) variables in lang() >> and deeper in code.
And try lang('Validation.alpha', [], 'es')