forked from ptteng/PPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspringmvc_I18N.html
167 lines (148 loc) · 8.75 KB
/
springmvc_I18N.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>葡萄藤PPT</title>
<link rel="stylesheet" href="https://ptteng.github.io/PPT/css/reveal/reveal.css">
<!-- PPT主题,可以在/css/reveal/theme/中选择其他主题,目前暂时只能使用该模板 -->
<link rel="stylesheet" href="https://ptteng.github.io/PPT/css/reveal/theme/ptt.css">
<!-- syntax highlighting 代码高亮主题 -->
<link rel="stylesheet" href="https://ptteng.github.io/PPT/lib/reveal/css/zenburn.css">
<!-- 打印和PDF输出样式 -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'https://ptteng.github.io/PPT/css/reveal/print/pdf.css' : '../css/reveal/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<img src="https://ptteng.github.io/PPT/img/demo/logo.png" alt="" usemap="#pttmap" class="base-logo">
<map name="pttmap">
<area shape="rect" coords="0,0,276,58" href="http://www.jnshu.com" alt="" target="_blank"/>
</map>
<div class="reveal">
<div class="slides">
<section class="present" style="top: 178.5px; display: block;">
<h2>SpringMVC国际化</h2>
<p></p>
<h3>java分享会</h3>
<p>分享人:上海分院 唐坤</p>
</section>
<section>
<p>1.背景介绍</p>
<p>2.知识剖析</p>
<p>3.编码实战</p>
<p>4.常见问题</p>
<p>5.解决方案</p>
<p>6.扩展思考</p>
<p>7.参考文献</p>
<p>8.更多讨论</p>
</section>
<section>
<h3>1.背景介绍</h3>
</section>
<section>
<h3>需求</h3>
<p>很多网站的用户分布在世界各地,因此网站需要针对不同国家的用户展示不同语言的内容,因此就有了国际化实现的需求,大多数网站都会在网站的头部或尾部设置语言切换链接,这样就可以直接切换成相应的内容。</p>
</section>
<section>
<p>国际化(Internationalization)指的是同一个网站可以支持多种不同的语言,以方便不同国家,不同语种的用户访问。
关于国际化我们想到的最简单的方案就是为不同的国家创建不同的网站,比如苹果公司,他的英文官网是:http://www.apple.com而中国官网是http://www.apple.com/cn<br></p>
<p>苹果公司这种方案并不适合全部公司,而我们希望相同的一个网站,而不同人访问的时候可以根据用户所在的区域显示不同的语言文字,而网站的布局样式等不发生改变。</p>
</section>
<section>
<h3>具体需求</h3>
1.在页面上能够根据浏览器的情况对文本(不是内容),时间,数字进行本地化处理
2.可以在bean中获取国际化资源文件locale对应的消息
3.可以通过超链接获取locale,而不再依赖于浏览器的语言设置情况
</section>
<section>
<p>于是就有了我们说的国际化,国际化总的来说就是同一个网站不同国家的人来访问可以显示出不同的语言。</p>
<p>国际化的英文Internationalization,但是由于拼写过长,有人想了一个简单的写法叫做I18N,代表的是Internationalization这个单词,以I开头,以N结尾,而中间是18个字母,所以简写为I18N。以后我们说I18N和国际化是一个意思。
</p>
</section>
<section>
<p>2.知识剖析 </p>
</section>
<section>
<p>首先我们需要知道,用户使用的是哪种语言,这个问题最好解决,因为浏览器在发送请求时会发送如下请求头:Accept-Language: zh-CN,en-US</p>
<p>下一步需要我们根据不同的语言显示不同的内容.</p>
<p>那我们想一下,如果说我们在页面中把这些诸如:用户名、密码等信息都写死了,那么,将不能再修改</p>
<p>所以在页面中这些需要国际化的内容都是需要动态获取的,也就是他们实际上都是变量。</p>
</section>
<section>
<p>我们一般采取的方式是将这些需要国际化的内容写到一个资源配置文件中,然后程序根据不同的语言加载不同的文件,就达到了一个国际化的目的。在国际化Spring MVC应用的时候,是将语言区域(Locale)相关的文本元素单独存在一个独立的属性文件中,然后不同的Locale对应的属性文件就构成了一个ResourceBundle,在Spring MVC显示本地化的消息时就会根据所在的区域显示对应的文本。</p>
</section>
<section>
<h3>3.编码实战</h3>
<img src="
http://qingshantang.oss-cn-beijing.aliyuncs.com/QQ%E6%88%AA%E5%9B%BE20171215132003.png" alt="国际化">
</section>
<section>
<h3>具体操作</h3>
1.配置国际化资源文件,
</section>
<section>
<h3>4.常见问题</h3>
<p>为什么在properties文件里输入中文是乱码呢?</p>
</section>
<section>
java读properties文件的时候,只认识ascii码,如\u4e00这种,不认识汉字。
所以你properties文件的编码字符集只要包括ascii码就行,gbk,utf-8神马的都一样
</section>
<section>
<h3>5.解决方案</h3>
<p>转换成Unicode码</p>
</section>
<section>
<p>6.拓展思考</p>
<p></p>
</section>
<section>
<h3>7.参考文献</h3>
<a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-servlet">https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-servlet</a>
<a href="http://www.jianshu.com/p/fe88527c7bb5?utm_campaign=hugo&utm_medium=reader_share&utm_content=note&utm_source=qq">http://www.jianshu.com/p/fe88527c7bb5?utm_campaign=hugo&utm_medium=reader_share&utm_content=note&utm_source=qq</a>
</section>
<section>
<h4>鸣谢</h4>
<p><small><h4>BY : 上海分院 唐坤</h4></small></p>
</section>
</div>
</div>
<script src="https://ptteng.github.io/PPT/lib/reveal/js/head.min.js"></script>
<script src="https://ptteng.github.io/PPT/lib/reveal/reveal.js"></script>
<script>
// 以下为常见配置属性的默认值
// {
// controls: true, // 是否在右下角展示控制条
// progress: true, // 是否显示演示的进度条
// slideNumber: false, // 是否显示当前幻灯片的页数编号,也可以使用代码slideNumber: 'c / t' ,表示当前页/总页数。
// history: false, // 是否将每个幻灯片改变加入到浏览器的历史记录中去
// keyboard: true, // 是否启用键盘快捷键来导航
// overview: true, // 是否启用幻灯片的概览模式,可使用"Esc"或"o"键来切换概览模式
// center: true, // 是否将幻灯片垂直居中
// touch: true, // 是否在触屏设备上启用触摸滑动切换
// loop: false, // 是否循环演示
// rtl: false, // 是否将演示的方向变成RTL,即从右往左
// fragments: true, // 全局开启和关闭碎片。
// autoSlide: 0, // 两个幻灯片之间自动切换的时间间隔(毫秒),当设置成 0 的时候则禁止自动切换,该值可以被幻灯片上的 ` data-autoslide` 属性覆盖
// transition: 'default', // 切换过渡效果,有none/fade/slide/convex/concave/zoom
// transitionSpeed: 'default', // 过渡速度,default/fast/slow
// mouseWheel: true, //是否启用通过鼠标滚轮来切换幻灯片
// }
// 初始化幻灯片
Reveal.initialize({
history: true,
dependencies: [
{ src: 'https://ptteng.github.io/PPT/plugin/markdown/marked.js' },
{ src: 'https://ptteng.github.io/PPT/plugin/markdown/markdown.js' },
{ src: 'https://ptteng.github.io/PPT/plugin/notes/notes.js', async: true },
{ src: 'https://ptteng.github.io/PPT/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }
]
});
</script>
</body>
</html>