Internationalization of JS files in SPRING MVC projects

General requirements: SPRING MVC project transformation, requires both Chinese and English versions.

Solution:
1.SPRING MVC itself comes with I18N configuration. Two new configuration files with names like messages_en_US.properties and messages_zh_CN.properties are used to configure English and Chinese.
2. The JSP page refers to the spring tag library, and the <spring:message code="msg.code"> tag can load the corresponding message according to the current locale.
3. Add the following content to the JSP:
<script>
var i18n=new Object();
i18n['yes']='<spring:message code="msg.yes"/>';
</script>

4. The corresponding JS file can directly refer to i18n['yes'].

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326693346&siteId=291194637