- 创建一个国际化配置文件夹
- 在文件夹中直接创建国际化配置文件login.properties
- 创建中文配置文件
- 此时idea识别出文件夹为国际化文件,我们可通过如下方式添加其他国家语言的配置文件
- 添加完配置文件,点开其中一个配置相关国际化参数
- 将配置文件路径配置到application.properties中
注意:idea 2018版本不能将路径配置为spring.messages.basename=i18n.login,否则会出现如下情况
- 使用thymeleaf中的 #{......} 将其取出即可
<form class="form-signin" action="dashboard.html">
<img class="mb-4" src="asserts/img/bootstrap-solid.svg" th: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>
<label class="sr-only" th:text="#{login.username}">Username</label>
<input type="text" class="form-control" placeholder="Username" th:placeholder="#{login.username}" required=""
autofocus="">
<label class="sr-only" th:text="#{login.password}">Password</label>
<input type="password" class="form-control" placeholder="Password" th:placeholder="#{login.password}"
required="">
<div class="checkbox mb-3">
<label>
<input type="checkbox" value="remember-me"> [[#{login.remenber}]]
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit" th:text="#{login.btn}">Sign in</button>
<p class="mt-5 mb-3 text-muted">© 2017-2018</p>
<a class="btn btn-sm">中文</a>
<a class="btn btn-sm">English</a>
</form>
-
验证结果