Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit cb7225e

Browse files
committed
Jesus' tweaks
1 parent 68fdbce commit cb7225e

File tree

4 files changed

+39
-67
lines changed

4 files changed

+39
-67
lines changed

public/docs/_examples/i18n/ts-snippets/i18n.config.snippets.ts

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313

1414
// #docregion i18n-plural-pipe
1515
@Component({
16-
selector: 'app',
16+
selector: 'my-app',
1717
template: `
1818
<div>
1919
{{ messages.length | i18nPlural: messageMapping }}
2020
</div>
21-
`,
21+
`
2222
})
23-
class MyApp {
24-
messages: any[];
23+
export class AppComponent {
24+
messages: string[];
2525
messageMapping: {[k:string]: string} = {
2626
'=0': 'No messages.',
2727
'=1': 'One message.',
@@ -32,79 +32,56 @@ class MyApp {
3232

3333
// #docregion i18n-select-pipe
3434
@Component({
35-
selector: 'app',
35+
selector: 'my-app',
3636
template: `
3737
<div>
38-
{{ gender | i18nSelect: inviteMap }}
38+
{{ gender | i18nSelect: genderMap }}
3939
</div>
40-
`,
40+
`
4141
})
42-
class MyApp {
43-
gender: string = 'male';
44-
inviteMap: any = {
42+
export class AppComponent {
43+
gender = 'male';
44+
genderMap = {
4545
'male': 'Invite him.',
4646
'female': 'Invite her.',
4747
'other': 'Invite them.'
4848
}
4949
}
5050
// #enddocregion i18n-select-pipe
5151

52-
// #docregion tsconfig1
52+
// #docregion tsconfig
5353
{
5454
"compilerOptions": {
55-
"emitDecoratorMetadata": true,
56-
"experimentalDecorators": true,
5755
"target": "es5",
5856
"module": "commonjs",
59-
"outDir": "./dist/out-tsc"
60-
},
61-
"files": [
62-
"./src/main.ts"
63-
]
64-
}
65-
// #enddocregion tsconfig1
66-
67-
// #docregion tsconfig2
68-
{
69-
"compilerOptions": {
57+
"moduleResolution": "node",
58+
"sourceMap": true,
7059
"emitDecoratorMetadata": true,
7160
"experimentalDecorators": true,
72-
"target": "es5",
73-
"module": "commonjs",
74-
"outDir": "./dist/out-tsc"
61+
"removeComments": false,
62+
"noImplicitAny": true,
63+
"suppressImplicitAnyIndexErrors": true
7564
},
76-
"files": [
77-
"./src/main.ts"
78-
],
7965
"angularCompilerOptions": {
80-
"genDir": "./src/i18n"
66+
"genDir": "./app/i18n"
8167
}
8268
}
83-
// #enddocregion tsconfig2
69+
// #enddocregion tsconfig
8470

8571
// #docregion bootstrap
8672
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
87-
import { enableProdMode } from '@angular/core';
88-
import { environment } from './environments/environment';
89-
import { AppModule } from './app/';
9073

91-
if (environment.production) {
92-
enableProdMode();
93-
}
74+
import { AppModule } from './app.module';
9475

9576
platformBrowserDynamic().bootstrapModule(AppModule);
9677
// #enddocregion bootstrap
9778

9879
// #docregion bootstrap-i18n
9980
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
100-
import { enableProdMode, TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID } from '@angular/core';
101-
import { environment } from './environments/environment';
102-
import { AppModule } from './app/';
103-
import { TRANSLATION } from './i18n/messages.fr';
81+
import { TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID } from '@angular/core';
10482

105-
if (environment.production) {
106-
enableProdMode();
107-
}
83+
import { AppModule } from './app.module';
84+
import { TRANSLATION } from './i18n/messages.fr';
10885

10986
// Compile using french translations
11087
platformBrowserDynamic().bootstrapModule(
@@ -119,7 +96,6 @@ platformBrowserDynamic().bootstrapModule(
11996
);
12097
// #enddocregion bootstrap-i18n
12198

122-
12399
// #docregion messages-ts
124100
export const TRANSLATION = `<?xml version="1.0" encoding="UTF-8"?>
125101
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">

public/docs/ts/latest/guide/_data.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@
105105
"intro": "Talk to a remote server with an HTTP Client."
106106
},
107107

108+
"i18n": {
109+
"title": "Internationalization (i18n)",
110+
"intro": "Easily translate your website into multiple languages"
111+
},
112+
108113
"lifecycle-hooks": {
109114
"title": "Lifecycle Hooks",
110115
"intro": "Angular calls lifecycle hook methods on directives and components as it creates, changes, and destroys them."
@@ -153,10 +158,5 @@
153158
"webpack": {
154159
"title": "Webpack: an introduction",
155160
"intro": "Create your Angular 2 applications with a Webpack based tooling"
156-
},
157-
158-
"i18n": {
159-
"title": "Internationalization (i18n)",
160-
"intro": "Easily translate your website into multiple languages"
161161
}
162162
}

public/docs/ts/latest/guide/i18n.jade

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ a(id="i18n-directive")
9191
:marked
9292
### i18n directive
9393

94-
The i18n directive is what tells Angular where it should inject the translations.
94+
The `i18n` directive is what tells Angular where it should inject the translations.
9595
It is used by both the JiT and the AoT approaches.
9696

9797
We simply add the attribute `i18n` to an element and the content string will be replaced when necessary.
@@ -128,7 +128,7 @@ a(id="i18n-plural-pipe")
128128

129129
.alert.is-important
130130
:marked
131-
The plural pipe is not yet supported by the ng-xi18n messages extractor.
131+
The ng-xi18n messages extractor doesn't support the plural pipe right now.
132132

133133

134134
a(id="i18n-select-pipe")
@@ -144,7 +144,7 @@ a(id="i18n-select-pipe")
144144
+makeExample('i18n/ts-snippets/i18n.config.snippets.ts', 'i18n-select-pipe')(format=".")
145145
.alert.is-important
146146
:marked
147-
The select pipe is not yet supported by the ng-xi18n messages extractor.
147+
The ng-xi18n messages extractor doesn't support the select pipe right now.
148148

149149

150150
a(id="extract")
@@ -163,14 +163,15 @@ a(id="ng-xi18n")
163163
To use it, the first thing that we have to do is to install it:
164164

165165
code-example(language="sh").
166-
npm install @angular/compiler-cli --save
166+
npm install @angular/compiler-cli @angular/platform-server typescript@2.0.2 --save
167167

168168
:marked
169-
Like `ngc`, `ng-xi18n` is based on `tsc`, the TypeScript compiler. It uses the file `tsconfig.json` to determine where
170-
are our files. We have to make sure that we have defined the parameter `files` so that it knows what is the entry point
171-
of our application.
169+
Like `ngc`, `ng-xi18n` is based on `tsc`, the TypeScript compiler.
172170

173-
+makeExample('i18n/ts-snippets/i18n.config.snippets.ts', 'tsconfig1')(format=".")
171+
Let's edit our `tsconfig.json` file and add the `angularCompilerOptions` with `genDir` pointing to the folder where we
172+
want `ng-xi18n` to generate the file.
173+
174+
+makeExample('i18n/ts-snippets/i18n.config.snippets.ts', 'tsconfig')(format=".")
174175

175176
:marked
176177
We can then use the `ng-xi18n` binary to generate a file named `messages.xlf` at the root of our application.
@@ -187,11 +188,6 @@ code-example(language="sh").
187188

188189
:marked
189190
If we want to generate this `messages.xlf` file somewhere in particular, `ng-xi18n` uses the same parameters as `ngc`.
190-
191-
Let's edit our `tsconfig.json` file and add the `angularCompilerOptions` with `genDir` pointing to the folder where we
192-
want `ng-xi18n` to generate the file.
193-
194-
+makeExample('i18n/ts-snippets/i18n.config.snippets.ts', 'tsconfig2')(format=".")
195191

196192
:marked
197193
The generated `messages.xlf` file uses by default the format `XML Localisation Interchange File Format` (XLIFF, version 1.2).
@@ -225,7 +221,7 @@ a(id="translate")
225221

226222
.alert.is-helpful
227223
:marked
228-
Using a versionning system such as `GIT` can help us find out easily what new translations have been generated by
224+
Using a versioning system such as `GIT` can help us find out easily what new translations have been generated by
229225
the messages extractor.
230226

231227
a(id="use-jit")
@@ -238,7 +234,7 @@ a(id="use-jit")
238234
Angular 2 understand `xlf` and `xmb` formats, but we have to provide these message into our application.
239235
To do that we will have to define a few providers at bootstrap time.
240236

241-
Let's say that we have the following bootstrap file:
237+
Having the following bootstrap file:
242238

243239
+makeExample('i18n/ts-snippets/i18n.config.snippets.ts', 'bootstrap')(format=".")
244240

@@ -291,7 +287,7 @@ a(id="use-aot")
291287
If we want to generate precompiled files for our french translations, we will use:
292288

293289
code-example(language="sh").
294-
ngc --i18nFile=./src/i18n/messages.fr.xlf --locale=fr --i18nFormat=xlf
290+
ngc --i18nFile=./app/i18n/messages.fr.xlf --locale=fr --i18nFormat=xlf
295291

296292
.alert.is-helpful
297293
:marked

0 commit comments

Comments
 (0)