search

Home  >  Q&A  >  body text

javascript - How to implement a multi-language website?

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.

我想大声告诉你我想大声告诉你2773 days ago669

reply all(7)I'll reply

  • 阿神

    阿神2017-05-16 13:16:05

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

    reply
    0
  • 怪我咯

    怪我咯2017-05-16 13:16:05

    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.

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-16 13:16:05

    i18n

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-16 13:16:05

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

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-16 13:16:05

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

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 13:16:05

    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?

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:16:05

    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.

    reply
    0
  • Cancelreply