码迷,mamicode.com
首页 > 编程语言 > 详细

[Java中实现国际化] - 配合thymeleaf实现中英文自动切换(多语言)

时间:2019-01-17 10:20:08      阅读:387      评论:0      收藏:0      [点我收藏+]

标签:ima   sheet   screen   lan   min   control   ane   some   efault   

MOOC该链接第三章第二节

尚硅谷SpringBoot全集 web开发国际化 xjbo  (7天,过期可以留言索取)

技术分享图片

resources下建立文件

上到下为: 默认的,英语(美国),中文(中国)

en

login.btn=Sign In
login.password=PassWord
login.remember=Remember Me
login.tip=Please sign in
login.username=UserName

zh

login.btn=登录
login.password=密码
login.remember=记住我
login.tip=请登录
login.username=用户名

 

页面:

<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>登录页面</title>

    <!-- Bootstrap Core CSS -->
    <link href="/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="/vendor/metisMenu/metisMenu.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="/dist/css/sb-admin-2.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn‘t work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

    <div class="container">
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                <div class="login-panel panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title" th:text="#{login.tip}">Please sign in</h3>
                    </div>
                    <div class="panel-body">
                        <form role="form">
                            <fieldset>
                                <div class="form-group">
                                    <input class="form-control" placeholder="UserName" name="UserName" type="text"
                                            th:placeholder="#{login.username}" autofocus>
                                </div>
                                <div class="form-group">
                                    <input class="form-control" placeholder="PassWord" name="PassWord" type="password"
                                            th:placeholder="#{login.password}">
                                </div>
                                <div class="checkbox">
                                    <label>
                                        <input name="remember" type="checkbox" value="Remember Me">[[#{login.remember}]]
                                    </label>
                                </div>
                                <!-- Change this to a button or input when using this as a form -->
                                <a href="index.html" class="btn btn-lg btn-success btn-block" th:text="#{login.btn}">Login</a>
                            </fieldset>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- jQuery -->
    <script src="/vendor/jquery/jquery.min.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="/vendor/bootstrap/js/bootstrap.min.js"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="/vendor/metisMenu/metisMenu.min.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="../dist/js/sb-admin-2.js"></script>

</body>

</html>

别忘记引入thymeleaf依赖以及配置它

pom

        <!--thymeleaf依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

properties

#thymeleaf
spring.thymeleaf.prefix=/views/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.cache=false
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**

spring.messages.basename=i18n.login
spring.messages.basename=i18n.register
spring.messages.basename=i18n.other

 

技术分享图片

技术分享图片

 待加入非thymeleaf的html. jsp使用方式

[Java中实现国际化] - 配合thymeleaf实现中英文自动切换(多语言)

标签:ima   sheet   screen   lan   min   control   ane   some   efault   

原文地址:https://www.cnblogs.com/ukzq/p/10280559.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!