Home >Backend Development >PHP Tutorial >laravel5 switch Chinese language
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 <pre style="font-family:'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;font-size:13.6px;margin-bottom:0px;padding-top:16px;padding-bottom:16px;line-height:1.45;background-color:rgb(246,248,250);" class="brush:php;toolbar:false;">Illuminate\Translation\TranslationServiceProvider::class,</pre>
in #config/app.php
Overtrue\LaravelLang\TranslationServiceProvider::class,Lumen in
bootstrap/app.php Add the following line:
$app->register(Overtrue\LaravelLang\TranslationServiceProvider::class);ConfigurationLaravelModify the project language
config/app.php:
'locale' => 'zh-CN',LumenModify the language in the
.env file:
APP_LOCALE=zh-CN
和正常使用一样,你如果需要额外添加语言项,请在 resources/lang/zh-CN/
下建立你自己的文件即可,也可以建立同样的文件来替换掉默认的语言部分。
例如创建文件 resources/lang/zh-CN/demo.php
:
2e93340967e67d58b1614af1ccabdadd '用户不存在', '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
:
5f7e45109fd2303311d46e630c1b92b1 '您的密码已经重置成功了,你可以使用新的密码登录了!',];
只放置你需要替换的部分即可。
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!