繁体   English   中英

如何翻译 Laravel 5.7 中的密码重置电子邮件?

[英]How can I translate the password reset email in Laravel 5.7?

我正在尝试在 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文件中(向下滚动到“使用翻译字符串作为键”。)

这也适用于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."
}

查看所有翻译文件的存储库:

https://github.com/caouecs/Laravel-lang

我正在尝试在 Laravel 5.7 中翻译密码重置电子邮件,默认情况下为英语。

通常——对于登录、注册和密码重置视图——你会翻译/resources/lang/下的文件,但我在电子邮件中找不到正文的相应行。

如何翻译密码重置电子邮件?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM