页面国际化

目录

1.国际化是什么?

2.设置国际化配置文件


1.国际化是什么?

国际化(internationalization):是设计和制造容易适应不同区域要求的产品的一种方式。它要求从产品中抽离所有地域语言,国家/地区和文化相关的元素

  • 而在程序中写网页则需要使用国际化进行配置不同的请求语言 

2.设置国际化配置文件

在resources(配置文件中)中创建名为:i18n(国际化的缩写他的英文字母有18个)的包如:

 在其中进行创建配置文件:

  • login.properties  (表示默认语言)
  • login_en_US.properties     (表示英语)
  • login_zh_CN.properties     (表示中文)

注意:这里IDE会自动进行合并文件在一个包中选择OK就好如:

 

 在这些配置文件中在进行网页上的文字配制如(login_zh_CN.properties):

login.btn=登录
login.password=密码
login.remember=记住我
login.tip=请登录
login.Username=用户名
login.English=英语

还需要配置以下SpringBoot的配置文件application.yml如:

spring:
  messages:
    basename: i18n.login

 页面:

<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<meta name="description" content="">
		<meta name="author" content="">
		<title>Signin Template for Bootstrap</title>
		<!-- Bootstrap core CSS -->
		<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
		<!-- Custom styles for this template -->
		<link th:href="@{/css/signin.css}" rel="stylesheet">
	</head>

	<body class="text-center">
		<form class="form-signin" action="dashboard.html">
			<img class="mb-4" th:src="@{/img/bootstrap-solid.svg}" width="72" height="72">
			<h1 class="h3 mb-3 font-weight-normal">[[#{login.tip}]]</h1>
			<label class="sr-only" th:text="#{login.Username}">Username</label>
			<label>
				<input type="text" class="form-control" placeholder="Username" required="" autofocus="">
			</label>
			<label class="sr-only" th:text="#{login.password}">Password</label>
			<label>
				<input type="password" class="form-control" placeholder="Password" required="">
			</label>
			<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>

</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

123小步

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值