How to achieve multilingual switching on a website?

how does a website achieve multilingual switching?

Mar.28,2021

many i18n class libraries, the principle is that according to the locale html or js according to the configuration variable to obtain the corresponding language, eg. Stream of jquery-i18n-properties, vue-i18n


the content of a website is divided into dynamic and static:
1. Dynamic data here, in a narrow sense, refers to those obtained from the database and processed and returned to the foreground. This needs to be distinguished by adding language-related information when sending the request
2. Static data, now the general practice is to define multiple json files, the content is a field containing all the translations and worthy variables
such as: cn.json: {user:' username'}, en.json: {user:'username'},.
one for each translation. The same variable name, and then translate it according to the language, and use the variable directly when using it. -- assign the global variable of the language at the source of the global variable. Remember to reassign the global variable when switching the language.
the above is manual Chinese and English

now many frameworks have defined file schemas-i18n. Just put the data in this way and use it directly

Menu