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

Commit 4578cda

Browse files
committed
docs(guide): document internationalization (i18n)
1 parent 215733e commit 4578cda

File tree

6 files changed

+457
-0
lines changed

6 files changed

+457
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='../_protractor/e2e.d.ts' />
2+
'use strict';
3+
describe('QuickStart E2E Tests', function () {
4+
5+
let expectedMsg = 'Hello from Angular 2 App with i18n';
6+
7+
beforeEach(function () {
8+
browser.get('');
9+
});
10+
11+
it(`should display: ${expectedMsg}`, function () {
12+
expect(element(by.css('h1')).getText()).toEqual(expectedMsg);
13+
});
14+
15+
it('should display an image', function () {
16+
expect(element(by.css('img')).isPresent()).toBe(true);
17+
});
18+
19+
});
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/* tslint:disable */
2+
// #docregion i18n-directive
3+
<h1 i18n>Hello i18n</h1>
4+
// #enddocregion i18n-directive
5+
6+
// #docregion i18n-directive-desc
7+
<h1 i18n="An introduction header for this sample">Hello i18n</h1>
8+
// #enddocregion i18n-directive-desc
9+
10+
// #docregion i18n-directive-meaning
11+
<h1 i18n="User welcome|An introduction header for this sample">Hello i18n</h1>
12+
// #enddocregion i18n-directive-meaning
13+
14+
// #docregion i18n-plural-pipe
15+
@Component({
16+
selector: 'app',
17+
template: `
18+
<div>
19+
{{ messages.length | i18nPlural: messageMapping }}
20+
</div>
21+
`,
22+
})
23+
class MyApp {
24+
messages: any[];
25+
messageMapping: {[k:string]: string} = {
26+
'=0': 'No messages.',
27+
'=1': 'One message.',
28+
'other': '# messages.'
29+
}
30+
}
31+
// #enddocregion i18n-plural-pipe
32+
33+
// #docregion i18n-select-pipe
34+
@Component({
35+
selector: 'app',
36+
template: `
37+
<div>
38+
{{ gender | i18nSelect: inviteMap }}
39+
</div>
40+
`,
41+
})
42+
class MyApp {
43+
gender: string = 'male';
44+
inviteMap: any = {
45+
'male': 'Invite him.',
46+
'female': 'Invite her.',
47+
'other': 'Invite them.'
48+
}
49+
}
50+
// #enddocregion i18n-select-pipe
51+
52+
// #docregion tsconfig1
53+
{
54+
"compilerOptions": {
55+
"emitDecoratorMetadata": true,
56+
"experimentalDecorators": true,
57+
"target": "es5",
58+
"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": {
70+
"emitDecoratorMetadata": true,
71+
"experimentalDecorators": true,
72+
"target": "es5",
73+
"module": "commonjs",
74+
"outDir": "./dist/out-tsc"
75+
},
76+
"files": [
77+
"./src/main.ts"
78+
],
79+
"angularCompilerOptions": {
80+
"genDir": "./src/i18n"
81+
}
82+
}
83+
// #enddocregion tsconfig2
84+
85+
// #docregion bootstrap
86+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
87+
import { enableProdMode } from '@angular/core';
88+
import { environment } from './environments/environment';
89+
import { AppModule } from './app/';
90+
91+
if (environment.production) {
92+
enableProdMode();
93+
}
94+
95+
platformBrowserDynamic().bootstrapModule(AppModule);
96+
// #enddocregion bootstrap
97+
98+
// #docregion bootstrap-i18n
99+
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';
104+
105+
if (environment.production) {
106+
enableProdMode();
107+
}
108+
109+
// Compile using french translations
110+
platformBrowserDynamic().bootstrapModule(
111+
AppModule,
112+
{
113+
providers: [
114+
{provide: TRANSLATIONS, useValue: TRANSLATION},
115+
{provide: TRANSLATIONS_FORMAT, useValue: 'xlf'},
116+
{provide: LOCALE_ID, useValue: 'fr'}
117+
]
118+
}
119+
);
120+
// #enddocregion bootstrap-i18n
121+
122+
123+
// #docregion messages-ts
124+
export const TRANSLATION = `<?xml version="1.0" encoding="UTF-8"?>
125+
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
126+
<file source-language="en" datatype="plaintext" original="ng2.template" target-language="fr-fr">
127+
...
128+
</file>
129+
</xliff>`;
130+
// #enddocregion messages-ts
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!= partial("../../../_includes/_ts-temp")

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!= partial("../../../_includes/_ts-temp")

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,10 @@
167167
"webpack": {
168168
"title": "Webpack: an introduction",
169169
"intro": "Create your Angular 2 applications with a Webpack based tooling"
170+
},
171+
172+
"i18n": {
173+
"title": "Internationalization (i18n)",
174+
"intro": "Easily translate your website into multiple languages"
170175
}
171176
}

0 commit comments

Comments
 (0)