我正在尝试在Laravel 5.7中翻译密码重置电子邮件,默认情况下是英语.
通常 - 对于登录,注册和密码重置视图 - 您将翻译文件/resources/lang/,但我无法在电子邮件中找到正文的相应行.
如何翻译密码重置电子邮件?
刚刚发现您还可以翻译@langjson 文件中的标签:
{
"Regards": "Met vriendelijke groet",
"If you’re having trouble clicking the \":actionText\" button, copy and paste the URL below\ninto your web browser: [:actionURL](:actionURL)": "Als u problemen ondervindt bij het klikken op de knop \":actionText\" kopieert en plakt u de onderstaande URL in uw webbrowser\n[:actionURL](:actionURL)",
"All rights reserved.": "Alle rechten voorbehouden."
}
Run Code Online (Sandbox Code Playgroud)
查看所有翻译文件的存储库:
https://github.com/caouecs/Laravel-lang
在该方法中,Illuminate\Auth\Notifications\ResetPassword::toMail()您可以看到该Lang::getFromJson()方法用于填充电子邮件:
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.'));
Run Code Online (Sandbox Code Playgroud)
因此,您应该能够将这些翻译添加到resources/lang/xx.json文件中,如文档中所述(向下滚动到"将翻译字符串用作键.")
这也适用于中的电子邮件验证邮件Illuminate\Auth\Notifications\VerifyEmail.
例如,这可能是resources/lang/fr.json(原谅我25年前的高中法语)的内容
{
"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"
}
Run Code Online (Sandbox Code Playgroud)
对于这两个类,模板文件Illuminate/Notifications/resources/views/email.blade.php包含标准Blade @lang标记中的其他文本,可以使用消息文件进行翻译resources/lang/xx/messages.php
例如,这可能是以下内容resources/lang/fr/messages.php:
<?php
return [
"Regards" => "Félicitations",
];
Run Code Online (Sandbox Code Playgroud)