YII2 Multi-language configuration with cookies

Source: Internet
Author: User
Tags php language

These two days by the multi-lingual force, first summed up the document type.

1, to params.php configuration language type

2, to the view Layer site--index.php language output, the language will be changed in the field to write:

Get the page:

3, in the corresponding JS file, using jquery Ajax to obtain the language tag ID, etc., transferred to sitecontroller.php

4, to sitecontroller.php to establish the language method to receive AJAX data, and processing:

5, at the top of the sitecontroller.php, behavior add language, otherwise no permissions, AJAX data can not pass, reported forbidden 403:

6, to main.php to configure the multi-language i18n

7, write massage, field translation of the file:

8. Configure multiple languages in main.php

9, to component, configure the detection of cookies

10, to the browser, refresh, click on the language will change:

Compared to thinkphp is a lot of trouble, the next summary from the database to tune dynamic multi-language.

YII2 Multi-language configuration with cookies

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.