-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
416 lines (341 loc) · 14.9 KB
/
index.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Internationalize AngularJS: Lightning Talk</title>
<meta name="description" content="Presentaion slides from the ngEurope Lightning Talk on the same topic">
<meta name="author" content="Rahul Doshi">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="bower_components/reveal.js/css/reveal.min.css">
<link rel="stylesheet" href="css/theme.css">
<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="bower_components/reveal.js/lib/css/zenburn.css">
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if( window.location.search.match( /print-pdf/gi ) ) {
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'bower_components/reveal.js/css/print/pdf.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
}
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<aside class="logos">
<a href="http://angularjs.org">
<img class="angularjs" src="img/angularjs.png">
</a>
<a href="http://doshprompt.github.io/angular-localization">
<small>
<i class="fa fa-plus"></i>
</small>
<i class="fa fa-globe"></i>
</a>
</aside>
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1 style="margin: 50px 0 .5em">
Internationalize AngularJS
</h1>
<h3 style="margin-bottom: 1em">
Lightning Talk
</h3>
<p>
<small>Presented by <a href="mailto:[email protected]">Rahul Doshi</a> | <a href="http://twitter.com/doshprompt">@doshprompt</a></small>
</p>
<p style="margin-top: -25px">
<small>
from
<a href="http://dailymotion.com">
<img src="img/dailymotion.png" class="logo-dailymotion">
</a>
</small>
</p>
</section>
<section>
<h2>Architecture</h2>
<p>
Our solution is based on a simple architecture.
We will have a folder for each language that we would like to support.
Inside will be localized resource files
for each route or module we want to support.
</p>
<p>
We will also pick a default language
that will be used to fall back to the site’s native language
if a given user’s language is not supported.
</p>
<p>
100% of the code is run on the front-end within the browser,
and no special server-side support needs to be provided.
</p>
</section>
<section>
<p>The proposed directory structure:</p>
<pre><code>lang
├── en-US
│ ├── common.json
│ ├── login.json
│ ├── home.json
│ └── ...
├── fr-FR
│ ├── common.json
│ ├── login.json
│ ├── home.json
│ └── ...
└── ...
</pre></code>
<p>Below is an example of the file format:</p>
<pre><code class="json">{
"cancel": "Cancel",
"no": "No",
"ok": "OK",
"yes": "Yes"
}</pre></code>
</section>
<section>
<h2>The Service</h2>
<p>
A service will form the core of our localization engine,
providing an interface that will be responsible for checking the user's language settings
and requesting the appropriate resource based on the language.
</p>
<p>
It will also provide several methods,
a lookup method that will return a localized string for a given key from the loaded resource file,
a way to get/set the locale, and finally, a way to setup some defaults.
</p>
<p>
Lastly, it will notify us (via promises) when an individual file or a group of files
has been successfully loaded into memory and is ready for use.
</p>
</section>
<section>
<p>JavaScript:</p>
<pre><code class="javascript">$scope.strings = {};
locale.ready('common').then(function() {
$scope.strings.helloWorld = locale.getString('common.helloWorld');
});</pre></code>
<br>
<p>HTML:</p>
<pre><code class="html"><p>{{ strings.helloWorld }}</p></pre></code>
<small>
<a href="http://plnkr.co/edit/xCeADJ1LidsObWOhStjL?p=preview" target="_blank">
Edit in Plunker
<i class="fa fa-pencil"></i>
</a>
</small>
<p style="padding-top: 50px">Output:</p>
<p><code>Hello World!</code></p>
<aside class="notes">
This is naive as it requires you to manually refresh all the strings
through the controller upon a change in language invoked by the user.
Also does not take advantage of angular's excellent two-way bindings.
</aside>
</section>
<section>
<h2>Implementation: Take Two</h2>
<p>Using Fliters:</p>
<pre><code class="html"><p>{{ 'common.helloWorld' | i18n }}</p></pre></code>
<small>
<a href="http://plnkr.co/edit/mTsVW5GLdKsgMGOh6FhM?p=preview" target="_blank">
Edit in Plunker
<i class="fa fa-pencil"></i>
</a>
</small>
<p style="padding-top: 50px">Output:</p>
<p><code>Hello World!</code></p>
</section>
<section>
<h2>Performance Considerations</h2>
<p>Improvements with a Directive:</p>
<pre><code class="html"><p data-i18n="common.helloWorld"></p></pre></code>
<small>
<a href="http://plnkr.co/edit/OcsJxpOHZhvVirjjMiaJ?p=preview" target="_blank">
Edit in Plunker
<i class="fa fa-pencil"></i>
</a>
</small>
<p style="padding-top: 50px">Output:</p>
<p><code>Hello World!</code></p>
</section>
<section>
<h2>Inline Substitutions</h2>
<p>example.json</p>
<pre><code class="json">{
"nameOuput": "My name is %fullname"
}</code></pre>
<p>Filter:</p>
<pre><code class="html"><p>{{ 'example.nameOutput' | i18n:'Rahul Doshi' }}</p></pre></code>
<p>Directive:</p>
<pre><code class="html"><p data-i18n="example.nameOutput" data-fullname="Rahul Doshi"></p></pre></code>
<small>
<a href="http://plnkr.co/edit/eaFnYr8JvqTCQqBL4b24?p=preview" target="_blank">
Edit in Plunker
<i class="fa fa-pencil"></i>
</a>
</small>
</section>
<section>
<h2>Setting Localized Attributes</h2>
<p>
Good for when you want to avoid angular's interpolation
in setting certain attributes on the DOM element
such as placeholder for an input.
</p>
<pre><code class="html"><input data-i18n-attr="{placeholder: 'login.emailPrompt'}"></code></pre>
<small>
<a href="http://plnkr.co/edit/lYTww7oNvVwvEYDjpEob?p=preview" target="_blank">
Edit in Plunker
<i class="fa fa-pencil"></i>
</a>
</small>
</section>
<section>
<h2 style="margin-bottom: 0px">Pluralization</h2>
<i style="margin-bottom: 20px; display:block">
(Experimental -- using inside ng-pluralize)
</i>
<p>In your controller:</p>
<pre><code class="javascript">$scope.numCount = 1;
$scope.pluralStrings = {
nobodyIsViewing: 'common.nobodyIsViewing',
onePersonIsViewing: 'common.onePersonIsViewing',
manyPeopleAreViewing: 'common.manyPeopleAreViewing'
};
</code></pre>
<p>On the page:</p>
<pre><code class="html"><input type="number" min="0" data-ng-model="personCount">
<span
data-ng-pluralize
data-count="personCount"
data-when="{
'0': '{{ pluralStrings.nobodyIsViewing | i18n }}',
'1': '{{ pluralStrings.onePersonIsViewing | i18n }}',
'other': '{{ pluralStrings.manyPeopleAreViewing | i18n:personCount }}'
}">
</span></pre></code>
<small>
<a href="http://plnkr.co/edit/0qgrg1M5wl7UDgRPgZNm?p=preview" target="_blank">
Edit in Plunker
<i class="fa fa-pencil"></i>
</a>
</small>
</section>
<section>
<h2>Gender</h2>
<p>Experimental: using with ng-switch</p>
<pre><code class="html"><div data-ng-switch="user.gender">
<span> data-ng-switch-when="m" data-i18n="common.male"></span>
<span> data-ng-switch-when="f" data-i18n="common.female"></span>
</div></pre></code>
<p>ng-if also works with filter</p>
<pre><code class="html">Gender:
<span data-ng-if="user.gender == 'm'">{{ 'common.male' | i18n }}</span>
<span data-ng-if="user.gender == 'f'">{{ 'common.female' | i18n }}</span>
</pre></code>
<small>
<a href="http://plnkr.co/edit/8SMDBqhxl5aq2rTggBiA?p=preview" target="_blank">
Edit in Plunker
<i class="fa fa-pencil"></i>
</a>
</small>
</section>
<section>
<h2>
<a href="https://www.npmjs.org/package/grunt-angular-localization" target="_blank">
grunt-angular-localization
</a>
</h2>
<img class="screenshot" src="img/grunt-angular-localization.gif">
</section>
<section>
<h2>
<a href="http://doshprompt.github.io/angular-localization" target="_blank">
angular-localization
</a>
</h2>
<img src="img/angular-localization.png" class="screenshot">
</section>
<section>
<h1>Fin</h1>
<p>
Slides:
<a href="http://doshprompt.github.io/angular-localization-lightning-talk">
http://doshprompt.github.io/angular-localization-lightning-talk
</a>
</p>
<p>
Meetup:
<a href="http://doshprompt.github.io/angular-localization-meetup">
http://doshprompt.github.io/angular-localization-meetup
</a>
</p>
</section>
</div>
</div>
<script src="bower_components/reveal.js/lib/js/head.min.js"></script>
<script src="bower_components/reveal.js/js/reveal.min.js"></script>
<script>
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
transition: Reveal.getQueryHash().transition || 'fade', // default/cube/page/concave/zoom/linear/fade/none
// Optional libraries used to extend on reveal.js
dependencies: [
{
src: 'bower_components/reveal.js/lib/js/classList.js',
condition: function () {
return !document.body.classList;
}
},
{
src: 'bower_components/reveal.js/plugin/markdown/marked.js',
condition: function () {
return !!document.querySelector('[data-markdown]');
}
},
{
src: 'bower_components/reveal.js/plugin/markdown/markdown.js',
condition: function () {
return !!document.querySelector('[data-markdown]');
}
},
{
src: 'bower_components/reveal.js/plugin/highlight/highlight.js',
async: true,
callback: function () {
hljs.initHighlightingOnLoad();
}
},
{
src: 'bower_components/reveal.js/plugin/zoom-js/zoom.js',
async: true,
condition: function () {
return !!document.body.classList;
}
},
{
src: 'bower_components/reveal.js/plugin/notes/notes.js',
async: true,
condition: function() {
return !!document.body.classList;
}
}
]
});
</script>
</body>
</html>