I have seen the design of WordPress. The method of WordPress is to first make an English version, and then perform string replacement according to the settings. I feel that if we do this, once the description changes, then there will probably be a lot of changes. And this method is not suitable for websites that can separate front and back like thinkphp.
Are there any other good solutions?
I have seen the design of WordPress. The method of WordPress is to first make an English version, and then perform string replacement according to the settings. I feel that if we do this, once the description changes, then there will probably be a lot of changes. And this method is not suitable for websites that can separate front and back like thinkphp.
Are there any other good solutions?
Don’t ThinkPHP itself have a multi-language lang function? Its default template is multi-language. You can implement it by referring to it...
You can store all text in a js object. The display of all text is replaced by js variables, and then different js objects are read according to the language.
For example
a.js
<code>var lan = { HELLO: "Hello" } </code>
b.js
<code>var lan = { HELLO: "您好" } </code>
Use $().text(lan.HELLO)
in the page and read a.js or b.js according to the situation when reading the page
You can use PHP’s gettext to achieve internationalization, refer to github
In fact, it is to turn the key text of your site into a configuration file, then replace it with variables, and choose which language to read which configuration file
When I was building a small website, I used a library https://github.com/coderifous/jquery-localize
There should be many similar libraries
Basically the same idea as the above answers, this one Use jquery