首先要在resources/lang目录下设置对应的语言包,创建相应的配置信息文件,该目录下有语言实例。
Artisan::command('testLang', function () {
//第一种方法:先设置传参的语言
\Illuminate\Support\Facades\App::setLocale('zh-cn');
dd(trans('message.auth_error_email'));
dd(Lang::get('message.auth_error_email'));
})->describe('Display an inspiring quote');
Artisan::command('testLang', function () {
//第二种方法:直接在参数中设置$locale的值
dd(trans('message.auth_error_email',$replace = [],$locale = "en-us"));
dd(Lang::get('message.auth_error_email',$replace = [],$locale = "zh-cn"));
})->describe('Display an inspiring quote');
本文介绍了在Laravel框架中如何设置多语言环境,包括在resources/lang目录下创建语言包,以及通过Artisan命令演示两种设置语言的方法:一是通过设置应用程序的locale,二是直接在trans或Lang::get函数中指定locale。
676

被折叠的 条评论
为什么被折叠?



