Welcome Guest, Not a member yet? Register   Sign In
Validation error messages keep being loaded from system
#1
Question 

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?
Reply
#2

(This post was last modified: 05-10-2024, 07:27 AM by ALTITUDE_DEV.)

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'
]; 
Reply
#3

(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]
Reply
#4

(This post was last modified: 05-10-2024, 09:13 AM by ozornick.)

Check locale in Request? dd(request()); in Controller. You may be overwriting the locale in the filter
Simple CI 4 project for beginners codeigniter-expenses
Reply
#5

(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();   
}
Reply
#6

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')
Simple CI 4 project for beginners codeigniter-expenses
Reply




Theme © iAndrew 2016 - Forum software by © MyBB