Home  >  Article  >  Backend Development  >  laravel5 switch Chinese language

laravel5 switch Chinese language

不言
不言Original
2018-05-10 09:18:482577browse

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-lang

Laravel 5 Language pack, including 52 languages, based on caouecs/Laravel-lang.

Installation

composer require "overtrue/laravel-lang:~3.0"

Laraval 5.*

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

with:

Overtrue\LaravelLang\TranslationServiceProvider::class,
Lumen

in

bootstrap/app.php Add the following line:

$app->register(Overtrue\LaravelLang\TranslationServiceProvider::class);
Configuration

Laravel

Modify the project language

config/app.php

&#39;locale&#39; => &#39;zh-CN&#39;,

Lumen

Modify 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn