This article mainly introduces the switching of Chinese language in laravel5. It has certain reference value. Now I share it with you. Friends in need can refer to it
Laravel 5 Language pack, including 52 languages, based on caouecs/Laravel-lang.
composer require "overtrue/laravel-lang:~3.0"
After completing the above operation, copy the project file ## Replace the next line
in #config/app.phpIlluminate\Translation\TranslationServiceProvider::class,
Overtrue\LaravelLang\TranslationServiceProvider::class,
bootstrap/app.phpAdd the following line:
$app->register(Overtrue\LaravelLang\TranslationServiceProvider::class);
config/app.php:
'locale' => 'zh-CN',
.envfile:
APP_LOCALE=zh-CN
和正常使用一样,你如果需要额外添加语言项,请在resources/lang/zh-CN/
下建立你自己的文件即可,也可以建立同样的文件来替换掉默认的语言部分。
例如创建文件resources/lang/zh-CN/demo.php
:
'用户不存在', 'email_has_registed' => '邮箱 :email 已经注册过!',];
然后在任何地方:
echo trans('demo.user_not_exists'); // 用户不存在 echo trans('demo.email_has_registed', ['email' => 'anzhengchao@gmail.com']);// 邮箱 anzhengchao@gmail.com 已经注册过!
我们假设想替换掉密码重围成功的提示文字为例,创建resources/lang/zh-CN/passwords.php
:
'您的密码已经重置成功了,你可以使用新的密码登录了!',];
只放置你需要替换的部分即可。
resources/lang/
目录下:$ php artisan lang:publish [LOCALES] {--force}
examples:
$ php artisan lang:publish zh-CN,zh-HK,th,tk
以上就是本篇文章的全部内容了,更多相关内容请关注PHP中文网。
The above is the detailed content of laravel5 switch Chinese language. For more information, please follow other related articles on the PHP Chinese website!