Spring boot国际化

国际化

根据浏览器,语言设置的信息
自动切换国际化支持

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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值