国际化
根据浏览器,语言设置的信息
自动切换国际化支持
Spring MVC实现过程
1、编写国际化配置文件
2、使用ResourceBundleMessageSource管理国际化资源文件
3、在页面使用fmt:message取出国际化内容
Spring boot实现过程
1、编写国际化配置文件
抽取页面需要显示的国际化消息
Login,默认配置
Login_en_US,英文配置
Login_zh_CN,中文配置
Resource Bundle
直接编辑,每个字段的值
2、自动配置
SpringBoot自动配置好了
管理国际化资源文件的组件
MessageSourceAutoConfiguration
自定义的配置文件
可以直接放在类路径下叫messages.properties
这样,可以不用做任何的配置,直接使用国际化功能
指定配置文件
messageSource
setBasenames
设置国际化资源文件的基础名
基础名,表示去掉语言国家代码的
3、去页面获取国际化的值
#{ }
,获取国际化信息
th:text,是标签体里面的内容
Input是一个字节数的,没有标签体
可以使用行内写法
<input type="checkbox" value="remember-me"/> [[#{login.remember}]]
<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.btn}">Sign in</button>
<p class="mt-5 mb-3 text-muted">© 2017-2018</p>
<a class="btn btn-sm" th:href="@{/index.html(l='zh_CN')}">中文</a>
<a class="btn btn-sm" th:href="@{/index.html(l='en_US')}">English</a>
</form>
</body>