Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

igedeon's avatar

How to localize laravel jetstream messages?

Hi,

I have been trying to localize the message "The password must be at least 8 characters." but I have not found the propper way to do it.

in \vendor\laravel\fortify\src\Rules\Password.php line 76 I found

return __('The :attribute must be at least '.$this->length.' characters.');

0 likes
2 replies
igedeon's avatar

I found a solution (not sure if is the best):

  1. Create a new custom rule extended from Laravel\Fortify\Rules\Password

  2. In the new class override the message function.

  3. Use the new rule in App\Actions\Fortify\CreateNewUser

I was not able to make it work with the traditional resources/lang/en/validation.php approach.

That traditional approach expects fixed keys and the fortify class provides the final message (I guess).

ismaile's avatar

@igedeon: As you mentionned in your initial post, with your project generated through Jetstream, the password validation string comes from : \vendor\laravel\fortify\src\Rules\Password.php and the string is: __('The :attribute must be at least '.$this->length.' characters.')

A simple way to modify this string is to create an en.json file under resources/lang and put this:

{
    "The :attribute must be at least 8 characters.": "Your awesome :attribute must be at least 8 characters."
}

Please note that to illustrate the customization, I've modified the value and you would have: Your awesome password must be at least 8 characaters.

Then you can create other files for other languages such as es.json for spanish for example.

However, you can try to submit a PR to make the customization reusable for numeric values other than 8. The code:

__('The :attribute must be at least ' . $this->length . ' characters.')

could be replaced with:

__('The :attribute must be at least :length characters.', ['length' => $this->length])

Besides, you'd need to do the same for other strings using $this->length in \vendor\laravel\fortify\src\Rules\Password.php. The benefit of the PR would be to avoid customizing strings having a numeric value such as "The :attribute must be at least 8 characters.". Indeed, each validated field, using a similar validation sentence, might have a different minimum string length and this would mean repeated customization for each numeric value.

Please or to participate in this conversation.