How to write code for a multi-language website?

WBOY
Release: 2016-07-06 13:51:13
Original
1056 people have browsed it

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?

Reply content:

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>
Copy after login

b.js

<code>var lan = {
    HELLO: "您好"
}
</code>
Copy after login

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template