SpringBoot的国际化
1.## 关于SpringBoot页面国际化的操作:
(1)、编写国际化配置文件;
PS:en_US代表英语、zh_CN代表中文形式
在语言文件中配置各个语言:
2.、使用ResourceBundleMessageSource管理国际化资源文件
2.1 在SpringBoot中已经自动配置好了管理国际化资源文件的组件;
3)、在页面使用fmt:message取出国际化内容 :
PS:注意要修改代码格式(改成UTF-8),不然就会出现乱码
在页面文件中利用Thymeleaf表达式在页面显示对应的语言:
th:text="#{login.tip}" th:placeholder="#{login.username}" th:text="#{login.password}"
[[#{login.remember}]] 都是thymeleaf表达式
<body class="text-center">
<form class="form-signin" action="dashboard.html" th:action="@{/user/login}" method="post">
<img class="mb-4" th:src="@{asserts/img/bootstrap-solid.svg}" src="asserts/img/bootstrap-solid.svg" alt="" width="72" height="72">
<h1 class="h3 mb-3 font-weight-normal" th:text="#{login.tip}">Please sign in</h1>
<p style="color: red" th:text="${msg}" th:if="${not #strings.isEmpty(msg)}" ></p>
<label class="sr-only" th:text="#{login.username}">Username</label>
<input type="text" name="username" class="form-control" placeholder="Username" th:placeholder="#{login.username}" required="" autofocus="">
<label class="sr-only" th:text="#{login.password}">Password</label>
<input type="password" name="password" class="form-control" placeholder="Password" th:placeholder="#{login.password}" required="">
<div class="checkbox mb-3">
<label>
<input type="checkbox" value="remember-me" > [[#{login.remember}]]
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit" th:text="#{login.sign}">Sign in</button>
<p class="mt-5 mb-3 text-muted">© 2017-2018</p>
<a class="btn btn-sm" th:href="@{/login(l='zh_CN')}">中文</a>
<a class="btn btn-sm" th:href="@{/login(l='en_US')}">English</a>
</form>
</body>