Purpose: Front-end (only uses thymeleaf template + jquery) to achieve internationalization
Reason: The front-end does not use popular vue.js angular and other frameworks, pure HTML cannot reference constants defined in js
Using jquery assignment (maintaining 2 templates (Chinese, English) interface) Direct out
solution: use https://github.com/coderifous/jquery-localize/ a localization plug-in
a jQuery plugin that makes it easy to internationalize your web site
Steps:
1 html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
2 Language pack file
text-en.json
1 2 3 4 5 6 7 8 |
|
text-ja.json
·······
3 language_cookie.js needs to be executed natively on the server and cannot be obtained Required json file Main code The bottom layer of the code at the mark may use xmlHttpRequest to obtain the .json language package file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|