CodeIgniter Forums
Model validation field translation - 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: Model validation field translation (/showthread.php?tid=76718)



Model validation field translation - snelledre - 06-12-2020

All,

Is it possible to translate the field in model validation?

In the controller it can with :

Translation of message and validation labels
To use translated strings from language files, we can simply use the dot syntax. Let’s say we have a file with translations located here: app/Languages/en/Rules.php. We can simply use the language lines defined in this file, like this:

Code:
$validation->setRules([
        'username' => [
            'label'  => 'Rules.username',
            'rules'  => 'required|is_unique[users.username]',
            'errors' => [
                'required' => 'Rules.username.required'
            ]
        ],
        'password' => [
            'label'  => 'Rules.password',
            'rules'  => 'required|min_length[10]',
            'errors' => [
                'min_length' => 'Rules.password.min_length'
            ]
        ]
    ]
);


But in the documentation is no example for model validation.

André


RE: Model validation field translation - snelledre - 06-12-2020

Now i named the tables in the database in dutch, with this way i get the error messages all in dutch.
But it's cleaner to name the tables in english and translate them in codeigniter to the dutch languages.