如何在Laravel 5.7中翻译密码重置电子邮件? [英] How can I translate the password reset email in Laravel 5.7?

查看:101
本文介绍了如何在Laravel 5.7中翻译密码重置电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

通常-对于登录,注册和密码重置视图-您可以翻译/resources/lang/下的文件,但我在电子邮件中找不到与正文对应的行.

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?

推荐答案

在方法Illuminate\Auth\Notifications\ResetPassword::toMail()中,您可以看到Lang::getFromJson()方法用于填充电子邮件:

In the method Illuminate\Auth\Notifications\ResetPassword::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.'));

因此,您应该能够将这些翻译添加到resources/lang/xx.json文件 (向下滚动至将翻译字符串用作键".)

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.")

这也适用于Illuminate\Auth\Notifications\VerifyEmail中的电子邮件验证消息.

This also applies to the email verification message in Illuminate\Auth\Notifications\VerifyEmail.

例如,这可能是resources/lang/fr.json的内容(原谅我25年前的高中法语)

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"
}


对于这两个类,模板文件Illuminate/Notifications/resources/views/email.blade.php包含标准Blade @lang标记中的其他文本,可以使用resources/lang/xx/messages.php


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

例如,这可能是resources/lang/fr/messages.php的内容:

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

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

这篇关于如何在Laravel 5.7中翻译密码重置电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆