laravel多语言设置

  • 根据自己使用的laravel版本,composer安装对应的包

 

  • config/app.php中配置默认语言
'locale' => 'zh_CN',
  • 将语言文件放置在resources/lang目录中(例:resources/lang/zh_CN/demo.php)
<?php

return [
    'user_not_exists'    => '用户不存在',
    'email_has_registed' => '邮箱 :email 已经注册过!',
];
  • 使用  trans(语言文件名, 语言文件名中的key)
// 用户不存在
echo trans('demo.user_not_exists');

// 邮箱 anzhengchao@gmail.com 已经注册过!
echo trans('demo.email_has_registed', ['email' => 'anzhengchao@gmail.com']);

 

 

© 版权声明
THE END
喜欢就支持一下吧
分享