The Yii2 framework is famous for its performance and has many users. Sometimes our projects may require multi-language support, so how to configure the language pack of Yii2? Let’s set up the language pack of Yii2 today.
The multi-language version of yii2 is almost similar to yii1
1. Set the default language: Add: 'language'=>'zh-CN'
# to the mail.php configuration file ##2. Multi-language switching<a href="<?php echo Yii::$app->urlManager->createUrl(['/ebay/user/language','lang'=>'zh-CN']);?>">中文</a> <a href="<?php echo Yii::$app->urlManager->createUrl(['/ebay/user/language','lang'=>'en']);?>">英文</a>
///语言切换 public function actionLanguage(){ $language= \Yii::$app->request->get('lang'); if(isset($language)){ \Yii::$app->session['language']=$language; } //切换完语言哪来的返回到哪里 $this->goBack(\Yii::$app->request->headers['Referer']); }
Add a sentence to the entry file web/index.php
This way you can switch the language
Yii::$app->language
Related recommendations :
Yii2 uses camel case Instance analysis of named form access controller
Detailed explanation of the registration and creation methods of components in Yii2
The above is the detailed content of Yii2 language pack settings. For more information, please follow other related articles on the PHP Chinese website!