Reputation: 10906
How can I change the validator language messages. For example if I want to change the 'required' text 'The kilometerszakelijk field is required.' to something else?
Upvotes: 6
Views: 36317
Reputation: 51
To configure the default language in Laravel 10x, navigate to the config/app.php file and locate the following line:
'locale' => 'ru'
Additionally, you can dynamically switch the active language in PHP using the following code snippet:
App::setLocale('ru');
To display validation messages in the active language, you need to publish the lang directory in your project by executing php artisan lang:publish. This command will generate the lang/en directory containing files such as auth.php, validation.php, and others.
Next, create a directory for your desired language within the lang/ directory and create the necessary files. For example:
lang/
en/
...
ru/
auth.php
pagination.php
passwords.php
validation.php
In the validation.php file, define your validation rules as follows:
{
'regex' => 'The :attribute field format is invalid.',
'required' => 'The :attribute field is required.',
}
This setup will ensure that validation messages are displayed in the specified language.
Upvotes: 1
Reputation: 1524
Laravel-lang
In this repository, you can find the lang files for the framework PHP, Laravel 4&5.
you can see here for use that.
Upvotes: 1
Reputation: 40909
All language specific content is stored in your resources/lang// folder. One of the files you'll find in this folder is validation.php that holds validation messages for given language, so if you want to change the translations, you'll need to edit that file.
Depending on the language that is used by the application, messages will be read from different folders in resources/lang/. You can set language/locale using
App::setLocale('en');
You can also set fallback locale (that is used when there are no translations for current language) by setting it in your config/app.php file, e.g.:
'fallback_locale' => 'en',
See more details in the docs: http://laravel.com/docs/5.0/localization
Upvotes: 13
Reputation: 73291
Create a folder named like your language code in
resources/lang
then create a file in this folder called validation.php
and in there, write something like
return [
'required' => 'Das Feld :attribute ist ein Pflichtfeld.',
]
Upvotes: 4
Reputation: 180177
For the default messages, you can adjust the translations in resources/lang/<language>/validation.php
.
You can also pass entirely custom messages to the validator.
Upvotes: 1