Yii2.0实现语言包切换功能

在yii2.0高级模板框架中,以前台为例,首先  在前台frontend 下面建立  messages/zh-CN 
在 messages文件夹中创建一个文件:  ①common.php                                                     
如果是使用的后台目录,就在  backend/config/main.php 中添加如下的配置文件
return  [
                     'language'=>'zh-CN',//选择中文语言包
        ......        
                         components =>[ 
                         'i18n'=>[
 'translations'=>[
                              '*' =>[
                     'class'=>'yiii18nPhpMessageSource',
                     'fileMap'=>[
                                    'common'=>'common.php'
                                                           ]
                                                 ]
                           ]
]
                   ],
]
添加language和i18n之后,基本上已经完成
 
在common.php 中添加peizhi.png
 

在说出页面展示即可

main.png
     如果出现index.png
就代表成功
原文地址:https://www.cnblogs.com/liuzhen123/p/8059278.html