8

I searched a lot before asking this question but found nothing to help me. I started using Laravel as a PHP framework. As I started to do form validation, I used the Validator class to manage all my validation and error messages. But I'd like to know how I can customize the error messages (I'd like to put them in another language for example).

2
  • 1
    Start copying the file located at app/lang/en/validation.php to app/lang/es/validation.php for Spanish translation. Then change the default language with App::setLocale('es');. Commented Aug 31, 2013 at 1:00
  • ^ yep, this is one way to go.. Commented Aug 31, 2013 at 2:59

2 Answers 2

12

The documentation says:

Language strings are stored in files within the resources/lang directory. Within this directory there should be a subdirectory for each language supported by the application.

Just create a directory with the supported language code, and add a validation.php file (it is wise to just copy the one provided in English then start translating).

An example for Spanish translation would be created at resources/lang/es/validation.php. And it will look as follow:

<?php

return array(
    "required" => "El campo :attribute es requerido.",
);

After that, you will need to change the default language.

The default language for your application is stored in the app/config/app.php configuration file. You may change the active language at any time using the App::setLocale method.

Example of changing the default language at runtime:

App::setLocale('es');
Sign up to request clarification or add additional context in comments.

1 Comment

It seems like they moved it from app/lang... to ressources/lang...
5

in laravel 5 the validation.php file comes under the folder resources.

resources/lang/en/validation.php

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.