在开发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 {begin, number}-{end, number} of {totalCount, number} {totalCount, plural, one{item} other{items}}.' => '第{begin, number}-{end, number}条,共{totalCount, number}条数据.',

'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 {count, number} {count, plural, one{item} other{items}}.' => '总计{count, number}条数据。',

'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}秒前',

];

如何改变php的语言变中文,修改Yii2的默认语言language为中文zh-CN的方法相关推荐

  1. android 英文语言设置字体,修改安卓ROM默认语言方法

    修改安卓ROM默认语言方法 (2012-06-06 19:29:41) 标签: 安卓 默认语言 中文 手机博客 安卓Android手机的ROM目前主要有三大类: ①官方发布的正版: ②民间开发团队发布 ...

  2. 修改ubuntu系统默认语言(linux中文乱码)

    查看Linux版本信息 solin@zabbix-server:~$ uname -p x86_64 solin@zabbix-server:~$ lsb_release -a No LSB modu ...

  3. android系统语言切换及系统烧写默认语言设置

    Android 4.3 1 . 语言全局切换 重写Setting后需要全局切换语言(中英.中阿等),查看原生的Setting代码,抽出切换语言部分,具体实现如下: zh_CN,这是原始localeSt ...

  4. c语言变长数组_2018级C语言大作业 - 祖玛

    C语言 - 祖玛https://www.zhihu.com/video/1226223520021295104 分享18级同学大一上学期用C语言实现的祖玛.分步骤代码.图片音乐素材.可执行程序可从百度 ...

  5. win10(企业英文版)有关中文乱码 与 系统默认语言转换

    一.我本机是win10 企业英文版,但是对于一些中文文件,会出现乱码问题,比如一些对英文系统支持不好的软件,一些txt文本,以前写的代码里的中文注释等等. 解决方式: 1.[home]+R 输入con ...

  6. 修改Linux系统默认语言

    RHEL/CentOS : 修改 /etc/sysconfig/i18n 的 LANG变量 英文:en_US.UTF8 中文:zh_CN.UTF8 1 2 3 [root@cloevm ~]# cat ...

  7. c语言根据学分修改成绩,用c语言编写学分管理系统-成绩管理系统

    1.用用 c c 语言编写学分管理系统语言编写学分管理系统- -成绩管理系统成绩管理系统#include#include#include #include#include#define LEN siz ...

  8. 苹果计算机如何改变错误文字,教你如何修改MAC系统默认文字

    先来看一下最终的效果图吧-, g, [' k+ x8 f( |! f 七度苹果电脑软件 " ]$ o! @, L* _  O8 s 七度苹果电脑软件 8 s, a7 M) z5 Q 七度苹果 ...

  9. c语言 获取文件修改时间,(C语言)获取并修改文件夹时间(创建时间、修改时间、访问时间)...

    背景 在Windows系统下没有提供可以对文件夹时间属性修改的方法或者API,在上一篇文章中我们提到了文件时间的函数,那么我们可以以打开文件的方式打开文件夹,然后通过修改文件时间的API函数对文件夹时 ...

最新文章

  1. 【重磅干货】Python、机器学习、深度学习算法实战和应用必备书籍
  2. 使用WebBrowser与msHtml开发WinForms下的HtmlEditor控件
  3. 自学Zabbix3.0版本以上资产清单inventory
  4. 操作系统:内存连续分配方式采用的几种算法及各自优劣
  5. C++STL模板库适配器之stack容器
  6. opengl 深度详解_OpenGL中的深度测试
  7. FastReport.Net 使用字符串
  8. win10下markdownpad2显示问题
  9. Linux单用户能做什么,Linux单用户模式详解 及应用场景
  10. 使用Elizabeth为您的应用程序生成随机数据
  11. 未来新型计算机可能有,上海科学家构建出新型“DNA逻辑门”DNA分子有望成未来超级计算机...
  12. [转载] Python中的string模块的学习
  13. asp.net中英文转换
  14. Python中神奇的迭代器和生成器
  15. 计算思维的本质是什么
  16. 计算机flash听课记录范文,Flash之《遮罩动画》听课记录
  17. Docker 安装 It seems there is already a Binary at
  18. 微信带参二维码数据解析
  19. ubuntu20.04没有声音如何处理
  20. 传奇服务器都有哪些文件,传奇服务端MonUseItems文件夹什么用?

热门文章

  1. BZOJ 2244 [SDOI2011]拦截导弹 (三维偏序CDQ+线段树)
  2. [bbk2907]第3集 - Chapter 02 - RAC的安装过程中需要注意的要点
  3. asp.net 初步入门使用正则抓取网页信息
  4. java Statement与preparedStatement的区别
  5. Android应用程序管理系列(二)——PackageManager 包管理者
  6. java—IO流——读取键盘输入的字母并转换成大写字母输出在控制台上
  7. HashMap源码及原理
  8. C# switch语句中,可以放哪些类型
  9. 四平方和(程序设计)
  10. 【00】why集搜客网络爬虫?