Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
908 views
in Technique[技术] by (71.8m points)

php - How can I translate the password reset email in Laravel 5.7?

I'm trying to translate the password reset email, which is English by default, in Laravel 5.7.

Normally – for the login, registration, and password reset views – you would translate the files under /resources/lang/, but I can't find the corresponding lines for the body on the emails.

How can I translate the password reset email?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In the method IlluminateAuthNotificationsResetPassword::toMail() you can see the Lang::getFromJson() method is used to populate the email:

return (new MailMessage)
    ->subject(Lang::getFromJson('Reset Password Notification'))
    ->line(Lang::getFromJson('You are receiving this email because we received a password reset request for your account.'))
    ->action(Lang::getFromJson('Reset Password'), url(config('app.url').route('password.reset', $this->token, false)))
    ->line(Lang::getFromJson('If you did not request a password reset, no further action is required.'));

So you should be able to add these translations to the resources/lang/xx.json file as described in the documentation (scroll down to "Using Translation Strings As Keys.")

This also applies to the email verification message in IlluminateAuthNotificationsVerifyEmail.

For example, this could be the content of resources/lang/fr.json (forgive my high school French from 25 years ago)

{
    "If you did not request a password reset, no further action is required.": "Si vous ne demandez pas le réinitialisation de votre mot de passe, vous ne pouvez rien faire"
}

For both classes, the template file Illuminate/Notifications/resources/views/email.blade.php contains additional text that is in standard Blade @lang tags, which can be translated using message files at resources/lang/xx/messages.php

For example, this could be the content of resources/lang/fr/messages.php:

<?php
return [
    "Regards" => "Félicitations",
];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...