How can I write code better for websites with multiple languages?

Source: Internet
Author: User
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

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.