【发布时间】:2021-07-06 10:52:02
【问题描述】:
我正在尝试在 Laravel 5.7 中翻译密码重置电子邮件,默认为英文。
通常 - 对于登录、注册和密码重置视图 - 您会翻译 /resources/lang/ 下的文件,但我在电子邮件中找不到正文的相应行。
如何翻译密码重置邮件?
【问题讨论】:
我正在尝试在 Laravel 5.7 中翻译密码重置电子邮件,默认为英文。
通常 - 对于登录、注册和密码重置视图 - 您会翻译 /resources/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.'));
因此您应该能够将这些翻译添加到resources/lang/xx.json 文件as described in the documentation(向下滚动到“使用翻译字符串作为键”。)
这也适用于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"
}
对于这两个类,模板文件 Illuminate/Notifications/resources/views/email.blade.php 包含标准 Blade @lang 标记中的附加文本,可以使用位于 resources/lang/xx/messages.php 的消息文件进行翻译
例如,这可能是resources/lang/fr/messages.php的内容:
<?php
return [
"Regards" => "Félicitations",
];
【讨论】:
刚刚发现您还可以翻译 json 文件中的 @lang 标签:
{
"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."
}
查看所有翻译文件的存储库:
【讨论】: