YII2 Multi-language settings

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.