如果用的语言是en-US的话,网页加载速度很慢,因为要加载国外镜像或者链接什么的,使用zh-CN就直接加载国内链接或者CDN,速度比较快;

---------------------------------------------------------------------------------------------------

在开发Yii2的情况下,有时候遇到错误的情况下(例如model下面的错误提示信息),

希望提示信息默认为中文,这个时候就需要修改Yii2的默认语言,最直观的方式是:

//Yii2的默认的配置文件里面
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'language' => 'zh-CN', //全局设置为中文--推荐 ]

如果只针对局部的某一个控制器和方法下的话可以使用如下的方式

//也可以在外部设置
//Yii::$app->language = 'zh-CN'; //设定为使用中文 public function actionIndex(){ Yii::$app->language = 'en'; //设定语言为英文 Yii::$app->language = 'zh-CN'; //设定为使用中文 echo Yii::t('app', 'Goodbye_flag'); echo Yii::$app->language; //得到当前的语言
}

附上yii2的默认的错误提示语中文 yiisoft\yii2\message\zh-CN\yii.php

return [
'(not set)' => '(未设置)',
'An internal server error occurred.' => '服务器内部错误。',
'Are you sure you want to delete this item?' => '您确定要删除此项吗?',
'Delete' => '删除',
'Error' => '错误',
'File upload failed.' => '文件上传失败。',
'Home' => '首页',
'Invalid data received for parameter "{param}".' => '"{param}"参数接收到无效的数据。',
'Login Required' => '需要登录',
'Missing required arguments: {params}' => '函数缺少参数:{params}',
'Missing required parameters: {params}' => '缺少参数:{params}',
'No' => '否',
'No help for unknown command "{command}".' => '命令"{command}"发生未知的错误。',
'No help for unknown sub-command "{command}".' => '子命令"{command}"发生未知的错误。',
'No results found.' => '没有找到数据。',
'Only files with these extensions are allowed: {extensions}.' => '只允许使用以下文件扩展名的文件:{extensions}。',
'Page not found.' => '页面未找到。',
'Please fix the following errors:' => '请修复以下错误',
'Please upload a file.' => '请上传一个文件。',
'Showing <b>{begin, number}-{end, number}</b> of <b>{totalCount, number}</b> {totalCount, plural, one{item} other{items}}.' => '第<b>{begin, number}-{end, number}</b>条,共<b>{totalCount, number}</b>条数据.',
'The file "{file}" is not an image.' => '文件 "{file}" 不是一个图像文件。',
'The file "{file}" is too big. Its size cannot exceed {limit, number} {limit, plural, one{byte} other{bytes}}.' => '文件"{file}"太大。它的大小不能超过{limit, number}字节。',
'The file "{file}" is too small. Its size cannot be smaller than {limit, number} {limit, plural, one{byte} other{bytes}}.' => '该文件"{file}"太小。它的大小不得小于{limit, number}字节。',
'The format of {attribute} is invalid.' => '属性 {attribute} 的格式无效。',
'The image "{file}" is too large. The height cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.' => '图像"{file}"太大。他的高度不得超过{limit, number}像素。',
'The image "{file}" is too large. The width cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.' => '图像"{file}"太大。他的宽度不得超过{limit, number}像素。',
'The image "{file}" is too small. The height cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.' => '图像"{file}"太小。他的高度不得小于{limit, number}像素。',
'The image "{file}" is too small. The width cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.' => '图像"{file}"太小。他的宽度不得小于{limit, number}像素。',
'The verification code is incorrect.' => '验证码不正确。',
'Total <b>{count, number}</b> {count, plural, one{item} other{items}}.' => '总计<b>{count, number}</b>条数据。',
'Unable to verify your data submission.' => '您提交的数据无法被验证。',
'Unknown command "{command}".' => '未知的命令 "{command}"。',
'Unknown option: --{name}' => '未知的选项:--{name}',
'Update' => '更新',
'View' => '查看',
'Yes' => '是',
'You are not allowed to perform this action.' => '您没有执行此操作的权限。',
'You can upload at most {limit, number} {limit, plural, one{file} other{files}}.' => '您最多上传{limit, number}个文件。',
'the input value' => '该输入',
'{attribute} "{value}" has already been taken.' => '{attribute}的值"{value}"已经被占用了。',
'{attribute} cannot be blank.' => '{attribute}不能为空。',
'{attribute} is invalid.' => '{attribute}是无效的。',
'{attribute} is not a valid URL.' => '{attribute}不是一条有效的URL。',
'{attribute} is not a valid email address.' => '{attribute}不是有效的邮箱地址。',
'{attribute} must be "{requiredValue}".' => '{attribute}必须为"{requiredValue}"。',
'{attribute} must be a number.' => '{attribute}必须是一个数字。',
'{attribute} must be a string.' => '{attribute}必须是一条字符串。',
'{attribute} must be an integer.' => '{attribute}必须是整数。',
'{attribute} must be either "{true}" or "{false}".' => '{attribute}的值必须要么为"{true}",要么为"{false}"。',
'{attribute} must be equal to "{compareValueOrAttribute}".' => '{attribute}的值必须等于"{compareValueOrAttribute}"。',
'{attribute} must not be equal to "{compareValueOrAttribute}".' => '{attribute}的值不得等于"{compareValueOrAttribute}"。',
'{attribute} must be greater than "{compareValueOrAttribute}".' => '{attribute}的值必须大于"{compareValueOrAttribute}"。',
'{attribute} must be greater than or equal to "{compareValueOrAttribute}".' => '{attribute}的值必须大于或等于"{compareValueOrAttribute}"。',
'{attribute} must be less than "{compareValueOrAttribute}".' => '{attribute}的值必须小于"{compareValueOrAttribute}"。',
'{attribute} must be less than or equal to "{compareValueOrAttribute}".' => '{attribute}的值必须小于或等于"{compareValueOrAttribute}"。',
'{attribute} must be no greater than {max}.' => '{attribute}的值必须不大于{max}。',
'{attribute} must be no less than {min}.' => '{attribute}的值必须不小于{min}。',
'{attribute} must be repeated exactly.' => '{attribute}必须重复。',
'{attribute} should contain at least {min, number} {min, plural, one{character} other{characters}}.' => '{attribute}应该包含至少{min, number}个字符。',
'{attribute} should contain at most {max, number} {max, plural, one{character} other{characters}}.' => '{attribute}只能包含至多{max, number}个字符。',
'{attribute} should contain {length, number} {length, plural, one{character} other{characters}}.' => '{attribute}应该包含{length, number}个字符。',
'in {delta, plural, =1{a year} other{# years}}' => '{delta}年后',
'in {delta, plural, =1{a month} other{# months}}' => '{delta}个月后',
'in {delta, plural, =1{a day} other{# days}}' => '{delta}天后',
'in {delta, plural, =1{an hour} other{# hours}}' => '{delta}小时后',
'in {delta, plural, =1{a minute} other{# minutes}}' => '{delta}分钟后',
'in {delta, plural, =1{a second} other{# seconds}}' => '{delta}秒后',
'{delta, plural, =1{a year} other{# years}} ago' => '{delta}年前',
'{delta, plural, =1{a month} other{# months}} ago' => '{delta}个月前',
'{delta, plural, =1{a day} other{# days}} ago' => '{delta}天前',
'{delta, plural, =1{an hour} other{# hours}} ago' => '{delta}小时前',
'{delta, plural, =1{a minute} other{# minutes}} ago' => '{delta}分钟前',
'just now' => '刚刚',
'{delta, plural, =1{a second} other{# seconds}} ago' => '{delta}秒前',
];

修改Yii2的默认语言language为中文zh-CN的方法的更多相关文章

  1. Android系统默认语言改为中文

    第一种方法: 修改 build/tools/buildinfo.sh echo "ro.product.locale.language=zh"echo "ro.produ ...

  2. Android系统移植与调试之------->如何修改Android的默认语言、默认时区

    修改device/other/TBDG1073/ system.prop文件 1.设置默认语言 找到device/other/TBDG1073/ system.prop文件,修改属性ro.produc ...

  3. 如何修改 linux ubuntu 默认语言

    最近学习linux中,由于安装时选择了简体中文作为默认语言,时常出现乱码现象,所以决定将默认语言改回en_US. 但是在网上找了一些教程,发觉不一定都能实现.现总结如下: (1)对于大部分linux系 ...

  4. kali系统firefox浏览器默认语言改为中文设置方法

    kali中的Firefox浏览器默认为英文,这对英语不够好的我来讲,自然是很麻烦的,下面讲一下如何将语言设置为中文. 1.打开终端,输入 apt -y install firefox-esr-l10n ...

  5. Jmeter5.1.1 把默认语言调整为中文

    进入安装目录:apache-jmeter-5.1.1\bin\ 找到 jmeter.properties文件 搜索" language=en ",前面带有"#" ...

  6. 修改ssh的默认22端口,并使用scp的方法

    修改默认的22的ssh端口只需要修改 /etc/ssh/sshd_config 中的 port 字段为你想要的端口就可以了 以后用其他机器ssh登录这台机器只需要: ssh -p (port) (ip ...

  7. CentOS修改系统默认语言与编码

    有时候在安装CentOS无意中把默认语言设置为中文,而部分SSH软件不支持中文编码,所以在远程管理的时候会出现些乱码的现象.   如何修改CentOS的默认语言呢? 请先使用root权限帐户登陆 一. ...

  8. android平台修改默认语言的那点事

    转自:https://blog.csdn.net/qinghua0706/article/details/8243858 最近开始做智能机,用的是展讯6820平台,第一个需求就是改默认语言,一般碰到不 ...

  9. CentOS6 安装中文包和变更系统默认语言

    CentOS6 安装中文包和变更系统默认语言   用 yum 安装语言包的命令是 yum groupinstall <language>-support    ,其中 <langua ...

随机推荐

  1. firefox插件之 vimperator 的使用

    简介: vimperator 是 Firefox浏览器下的一个插件,可以让我们像使用vim 一样使用 firefox浏览器,高效畅快,不用鼠标了.它的官网为:http://www.vimperator ...

  2. 10篇写给Git初学者的最佳教程(转)

    身为网页设计师或者网页开发者的你,可能已经听说过Git这个正快速成长的版本控制系统.它由GitHub维护:GitHub是一个开放性的.存储众人代码的网站.如果你想学习如何使用Git,请参考本文.在文章 ...

  3. MySQL 插入数据时,中文乱码问题的解决

    当向 MySQL 数据库插入一条带有中文的数据形如 insert into employee values(null,'张三','female','1995-10-08','2015-11-12',' ...

  4. 【Java面试题】11 什么是内部类?Static Nested Class 和 Inner Class的不同。

    Inner Class(内部类)定义在类中的类. (一般是JAVA的说法) Nested Class(嵌套类)是静态(static)内部类.(一般是C++的说法)静态内部类:1 创建一个static内 ...

  5. 在 SharePoint 2010 打开网页出错时,显示实际的错误信息

    每次打开错误页面时,SharePoint出错显示的都是友好信息“发生意外错误”,而且友好到您基本上无法明白到底出什么错,怎么办? 修改Web.config文件配置就可以了,就可以显示更详细的信息: 1 ...

  6. 【树莓派】GSM900模块

    python代码 https://github.com/JFF-Bohdan/sim-module

  7. SVN目录权限配置

    1.如果要使用SVN,需要有一个项目的保存目录,例如把该目录设为“C:\MyPro”文件夹 2.把该目录发布为SVN项目目录,则需要通过以下命令行 svnadmin create c:\mypro  ...

  8. 笔记:写Java程序,并输出

    建一个文件名为 demo.java的文件 //写框架文件 public class Demo{ //写入口文件 public static void main(String[] args){ Syst ...

  9. java socket通信-传输文件图片--传输图片

    ClientTcpSend.java   client发送类 package com.yjf.test; import java.io.DataOutputStream; import java.io ...

  10. SDUT -refresh的停车场(栈和队列)

    题目描写叙述  refresh近期发了一笔横財,开了一家停车场.因为土地有限,停车场内停车数量有限,可是要求进停车场的车辆过多. 当停车场满时,要进入的车辆会进入便道等待.最先进入便道的车辆会优先 进 ...