After reading the Wordpress design, the Wordpress method is to first make an English version, and then replace the string according to the settings. I feel that once there is a change in description, it is estimated that there will be a lot of changes. In addition, this method is not suitable for websites that can be separated before and after thinkphp. Is there anything... I have read the Wordpress design. the Wordpress method is to first make an English version, and then replace the string according to the settings. I feel that once there is a change in description, it is estimated that there will be a lot of changes. In addition, this method is not suitable for websites that can be separated before and after thinkphp.
Is there any other good solution?
Reply content:
After reading the Wordpress design, the Wordpress method is to first make an English version, and then replace the string according to the settings. I feel that once there is a change in description, it is estimated that there will be a lot of changes. In addition, this method is not suitable for websites that can be separated before and after thinkphp.
Is there any other good solution?
ThinkPHP does not own a multi-language lang function. its default template is multi-language. can you refer to it for implementation ......
You can store all the text in a js object. the display of all the text is replaced by the js variable, and then read different js objects according to the language.
For example
A. js
var lan = { HELLO: "Hello"}
B. js
Var lan = {HELLO: "HELLO "}
Use $ (). text (lan. HELLO) on the page)
When reading the page, read a. js or B. js as needed
You can use the gettext in php to internationalize it. for details, refer to github.
In fact, it is to make the key text of your site into a configuration file, and then replace it with variables, and select which language to read and which configuration file to use.
I used a library https://github.com/coderifous/jquery-localize when I was doing a small website.
There should be a lot of similar libraries
Basically the same as the above answers, this uses jquery