Thinkphp to build a multi-language project implementation method including JS multi-language _php example

Source: Internet
Author: User
Tags pack

The example of this article is about how to build a multi language project implementation method including JS thinkphp. Share to everyone for your reference. The implementation methods are as follows:

First, the question:

The project needs to be developed in English, so a multi-language project needs to be built.

Project use thinkphp frame, vaguely remember thinkphp have multi-language settings, read the Help manual, sure enough, this on the edge of the experiment to begin:

Second, the realization method:

thinkphp using App_begain to detect and switch language packs, language packs and project-related, architecture, etc. are relatively simple, specific here: http://www.thinkphp.cn/info/188.html

When you're done, you can use the URL. "? L=en-us "to dynamically switch and debug, very good.

JS here found that the multilingual is not good to deal with, the total can not all assign past, anyway, many languages will not always be configured, simply automatically generate the corresponding multi-language JS file, and then the page according to Lang_set to dynamically request the corresponding multi-language files, in the basic action class of _initialize The following build function is called within the () method:

Copy Code code as follows:

In this way, the current language pack is generated before each visit, and then invoked within the TPL.

In this way, each time automatically loaded, this JS is permanently cached, if the language pack changes, only need to modify the Thinkphp language pack, and then delete the old JS language pack, let him automatically regenerate.

JS can be used in this way: Top10_title = $LANG. _new_language so that the whole project is bilingual, and is a configuration can be.

I hope this article will be helpful to everyone's thinkphp framework program design.

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.