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.
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
Then I write this code in the template
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.