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.