The problem of SpringBoot+Freemarker internationalization

problem description

now there is a requirement that background management can switch the language of the system, rather than automatically depending on the user"s region. It is somewhat similar to Wordpress"s language choice, as shown in figure

Source: https://www.wpdaxue.com/admin.

what methods have you tried

has looked around the Internet and automatically switched according to the user"s region or the language of the browser. What is needed now is to keep the language in the same state after the user has set it up, that is to say, it is the language everywhere. Save the user settings have been done, using the key-value to store, that is, you can add a language as key data.


Is the

page from Freemarker render? If so, all the multilingual text in the template, when translating, do not follow the system locale, but translate according to the language in your key-value, because this is used very frequently and is usually cached until the next time you change the language.

if this language setting is set independently by each logged-in user, you also need to store this language setting in the settings of the current user, that is, you need to go to the current logged-in user first when translating, and then look up the language set by the current logged-in user.

Menu