Search code examples
phplaraveltranslationtranslatelanguage-translation

Laravel use translator in a translation string


Would it be possible to use trans() in a lang file?

Eg: the line is Please fill in your :attribute Let's say :attribute is password.

Would be possible to put password in the english lang file

and then use wachtwoord in the dutch lang file for :attribute?


Solution

  • You can use language specific attributes for this inside of your language validation file lang/nl/validation.php in the attributes array for example:

    'attributes' => [
        'name' => 'naam'
        'password' => 'wachtwoord'
    ],
    

    This will translate those attributes globably on all forms.

    for a broader explanation check: Laravel validation attributes "nice names"