YII2 Multi-language settings
1. Set default language: In mail.php config file plus: ' Language ' = ' zh_cn '
2. Multi-language switching
HTML code:
Urlmanager->createurl (['/test/language ', ' lang ' = ' zh_cn ']);? > > Chinese urlmanager->createurl (['/test/language ', ' lang ' = ' en '); > ">english
Controller code:
Language Toggle Public Function Actionlanguage () { $language = \yii:: $app->request->get (' Lang '); if (Isset ($language)) { \yii:: $app->session[' language ']= $language; } Switch the language back to where to return to $this->goback (\yii:: $app->request->headers[' Referer '); }
3. Multi-language file messages path
4. Modify the entry file web/index.php:
(New Yii\web\application ($config))->run ();
Switch
$application = new Yii\web\application ($config);
$application-language = Isset (\yii:: $app->session[' language '])? \yii:: $app->session[' language ']: ' ZH_CN ';
$application, run ();
This allows for language switching.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the YII2 multi-language settings, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.