Simple implementation of i18n (internationalization) code

What is i18n (internationalization)?

Each country has its own language. If the website needs to be used by people all over the world, it needs to develop international functions.

I know of two types of internationalization, one of which is different websites in different countries, that is to say, the page styles are different. The other is that the websites are all the same, but the text inside is different. There is nothing to say about the first type. After all, there are two websites. What we are talking about today is the second type.

The second type of internationalization is different. I think the best thing is that everything you see on the page is in the same language, such as static pages + pop-up windows. I think there are two ways to achieve it, one of which is completely by Back-end control, the front-end only needs to receive the return value from the back-end for display. The other is that the front-end controls the static page display of the front-end, and the pop-up text is controlled by the back-end. I think the best control method is unified control by the backend. Even if a new language is added, it will not change a lot of front-end code. You only need to add a configuration file in a different language.

Let's take the IDEA official website as an example to further explain, let's first look at the Chinese IDEA official website:

insert image description here
Select English as the language in the upper right corner, and then you can see the official English website of IDEA. This is the realization of internationalization, and the effect is as follows:

insert image description here

Compared with the above two languages, the IDEA page style has not changed, but the text displayed above has been changed

How to achieve

For each language, we can create a configuration file, which contains key and value, which contains the content to be displayed on the static page and the content of the message pop-up window, that is to say, all the information displayed to the user is in the In this configuration file, we only need to take it out from the configuration file, it sounds like a constant class.

Then the key in each configuration file is the same, but the value is different. The following is an example in Traditional Chinese, Simplified Chinese, and English as follows:

Traditional Chinese configuration file:

insert image description here

Simplified Chinese configuration file:

insert image description here

English configuration file:

insert image description here

What needs to be done is to take out the results from these configuration files and display them. For different choices of the user, it is enough to return the results of different configuration files to the user. You can refer to the class of xxl-job for the specific writing method .com.xxl.job.admin.core.util.I18nUtil

Guess you like

Origin blog.csdn.net/qq_42449963/article/details/130986431