You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel重置密码通知中Lang::get('Reset Password Notification')如何翻译?

翻译步骤

1. 翻译文件存放&内容编写

你代码中直接以英文原字符串作为Lang::get()的键,推荐直接使用JSON格式的翻译文件,路径为resources/lang/zh_CN.json,文件不存在直接新建即可。
文件内以英文原串作为键,对应中文翻译作为值,示例内容如下:

{
    "Reset Password Notification": "重置密码通知",
    "You are receiving this email because we received a password reset request for your account.": "你收到此邮件是因为我们接收到针对你账号的重置密码申请。",
    "Reset Password": "重置密码",
    "This password reset link will expire in :count minutes.": "该密码重置链接的有效期为:count分钟。",
    "If you did not request a password reset, no further action is required.": "如果你未申请重置密码,无需进行任何操作。"
}

翻译内容里的:count占位符会被Laravel自动替换为对应数值,不需要修改。

2. 语言设置(locale配置)

  • 全局默认生效:打开config/app.php配置文件,找到locale配置项,修改为对应语言标识,和你新建的翻译文件前缀保持一致即可,示例:
'locale' => 'zh_CN',
  • 临时动态切换:如果需要根据用户场景自定义语言,可在业务逻辑或中间件中调用方法动态设置:
\App::setLocale('zh_CN');

3. 自定义通知生效配置

你已经复制了默认重置密码通知到app/Notifications/PasswordReset.php,需要在App\Models\User.php中重写密码重置通知发送方法,否则系统仍会调用vendor目录下的默认通知:

public function sendPasswordResetNotification($token)
{
    $resetUrl = url(route('password.reset', [
        'token' => $token,
        'email' => $this->email
    ]));
    $this->notify(new \App\Notifications\PasswordReset($resetUrl));
}

内容的提问来源于stack exchange,提问作者Aipo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 02:06:06