• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validation field label language

#1
I have add validation rules in Validation class, like this:

public $updateSettings  =  [
                'site_name'            =>      ['label' => 'site_name', 'rules'  =>  'required'],
        ];



Now how I can get label from language file? right now I got error message from /system/Languages, but the issue with label is not take the language from /App/Language.

Help me with this, please.
Reply

#2
NO Answers ?!
Reply

#3
(04-22-2020, 06:56 AM)maaa.om Wrote: NO Answers ?!

Take a breather and relax. This are a community based forum. Either no one know your answer, or they don't actually know what you are asking for. Haven't used the language class myself, and based on the description I don't what you want, so I can't recommend any specific part of the user guide.

So a good start are writing more in depth and providing more coding examples.
Reply

#4
(04-22-2020, 10:20 AM)jreklund Wrote:
(04-22-2020, 06:56 AM)maaa.om Wrote: NO Answers ?!

Take a breather and relax. This are a community based forum. Either no one know your answer, or they don't actually know what you are asking for. Haven't used the language class myself, and based on the description I don't what you want, so I can't recommend any specific part of the user guide.

So a good start are writing more in depth and providing more coding examples.

Thanks for your replay, actually what I want how I can display filed name from my language file in validation message?
Reply

#5
Hi, that part haven't made it to the official user guide. But here's what it says in the development branch:

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:

PHP 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'
            ]
        ]
    ]
); 
Reply

#6
(04-27-2020, 10:25 AM)jreklund Wrote: Hi, that part haven't made it to the official user guide. But here's what it says in the development branch:

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:

PHP 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'
            ]
        ]
    ]
); 


I did this in Config/Validation.php


PHP Code:
public $updateSettings  =   [
                'site_name'             =>      ['label' => 'App.site_name''rules'  =>  'required'],
        ]; 

But still give site_name, not what site_name in App language file.
Reply

#7
Ok, that's too bad. Haven't tested it myself so can't you any more pointers.
Reply

#8
PHP Code:
                'site_name'             =>      ['label' => 'App.site_name''rules'  =>  'required'],
        ]; 

But still give site_name, not what site_name in App language file.

Hi. Not sure, about user guide. When I had to make a custom language thing in my code I wrote like this:

'site_name'             =>      ['label' => lang('language_file.site_name', [], 'language_folder'), 'rules'  =>  'required'],

This was written in controller, so I'm not sure if it answers your question. But you can try it.
You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
Reply

#9
(04-28-2020, 08:08 AM)Leo Wrote:
PHP Code:
                'site_name'             =>      ['label' => 'App.site_name''rules'  =>  'required'],
        ]; 

But still give site_name, not what site_name in App language file.

Hi. Not sure, about user guide. When I had to make a custom language thing in my code I wrote like this:

'site_name'             =>      ['label' => lang('language_file.site_name', [], 'language_folder'), 'rules'  =>  'required'],

This was written in controller, so I'm not sure if it answers your question. But you can try it.


I can not access lang() function in property declarations:


PHP Code:
protected $validationRules      =   [
'site_name'             =>      ['label' => lang('language_file.site_name', [], 'language_folder'), 'rules'  =>  'required'],
]; 
Reply

#10
That's why the dot syntax was introduced. If you want to use this feature, be sure to use the latest version from development branch. Or wait until v4.0.3 will be ready.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.