javascript - How to implement a multi-language website?
我想大声告诉你
我想大声告诉你 2017-05-16 13:14:05
0
7
591

Recently there is a need to build a website in different languages ​​​​of countries in Europe, America, the Middle East, Africa, Asia and Oceania around the world. For example, if you select Spain in Europe, then this website will be displayed in Spanish; if you select Belarus in Europe, then this website will be displayed in Russian; if you select Japan in Asia, then this website will be displayed in Japanese...

How to realize such a need?

As for the backend, I can only click php. Is there any good way? Please give me some advice.

我想大声告诉你
我想大声告诉你

reply all(7)
阿神

Each language corresponds to a data table or an array/object
Switching

刘奇

You can use a framework like thinkphp, one language and one language pack, that is, all the places where text is displayed are parsed with tags, and the dictionary of the corresponding tags in the language pack is used. When switching languages, you can put the language ID into cookies and select the language pack for display based on the language.

淡淡烟草味

i18n

伊谢尔伦

International support. Currently, many are implemented in compliance with i18N.

習慣沉默

Language pack bar. The preliminary project must design how to switch and implement it

巴扎黑

I don’t understand PHP’s internationalization solution, but I hope this article of mine will be helpful to you: How to internationalize a web application?

曾经蜡笔没有小新

I was doing this recently and it made me vomit.

If you are using a front-end framework, then you only need a pipe character (filter) to filter the data. As for how to filter, you can save Chinese and English comparisons in a json file.

For example, I have a zh.json file. The content is

"contact us": "联系我们"

Then I write this code in the template

{{ 'contact us' | translate }}

Then maintain a language variable globally. When I select Chinese, I set the parameter passed to translate to zh, so that I can convert English into Chinese. The same goes for other languages.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!