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

Commit a5b8267

Browse files
ocombewardbell
authored andcommitted
docs(i18n): add internationalization (i18n) guide
1 parent 9671d99 commit a5b8267

20 files changed

+454
-3
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path='../_protractor/e2e.d.ts' />
2+
'use strict';
3+
describe('i18n E2E Tests', () => {
4+
5+
beforeEach(function () {
6+
browser.get('');
7+
});
8+
9+
it('should display i18n translated welcome: Bonjour i18n!', function () {
10+
expect(element(by.css('h1')).getText()).toEqual('Bonjour i18n!');
11+
});
12+
13+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
**/*.ngfactory.ts
2+
**/*.metadata.json
3+
**/messages.xlf
4+
dist
5+
!app/tsconfig.json
6+
!rollup.js
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!--#docregion greeting-->
2+
<h1>Hello i18n!</h1>
3+
<!--#enddocregion greeting-->
4+
5+
<!--#docregion i18n-attribute-->
6+
<h1 i18n>Hello i18n!</h1>
7+
<!--#enddocregion i18n-attribute-->
8+
9+
<!--#docregion i18n-attribute-desc-->
10+
<h1 i18n="An introduction header for this sample">Hello i18n!</h1>
11+
<!--#enddocregion i18n-attribute-desc-->
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!--#docregion-->
2+
<!--#docregion i18n-attribute-meaning-->
3+
<h1 i18n="User welcome|An introduction header for this sample">Hello i18n!</h1>
4+
<!--#enddocregion i18n-attribute-meaning-->
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// #docregion
2+
import { Component } from '@angular/core';
3+
4+
@Component({
5+
moduleId: module.id,
6+
selector: 'my-app',
7+
templateUrl: 'app.component.html'
8+
})
9+
export class AppComponent { }
10+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// #docregion
2+
import { NgModule } from '@angular/core';
3+
import { BrowserModule } from '@angular/platform-browser';
4+
5+
import { AppComponent } from './app.component';
6+
7+
@NgModule({
8+
imports: [ BrowserModule ],
9+
declarations: [ AppComponent ],
10+
bootstrap: [ AppComponent ]
11+
})
12+
13+
export class AppModule { }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// #docregion
2+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3+
4+
import { AppModule } from './app.module';
5+
6+
const platform = platformBrowserDynamic();
7+
platform.bootstrapModule(AppModule);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// #docregion
2+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3+
import { TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID } from '@angular/core';
4+
5+
import { AppModule } from './app.module';
6+
import { translation } from './messages.fr';
7+
8+
// Compile using french translations
9+
const platform = platformBrowserDynamic();
10+
platform.bootstrapModule(
11+
AppModule,
12+
{
13+
providers: [
14+
{provide: TRANSLATIONS, useValue: translation},
15+
{provide: TRANSLATIONS_FORMAT, useValue: 'xlf'},
16+
{provide: LOCALE_ID, useValue: 'fr'}
17+
]
18+
}
19+
);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// #docregion
2+
export const translation = `
3+
PASTE HERE
4+
`;
5+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// #docregion
2+
export const translation = `
3+
<?xml version="1.0" encoding="UTF-8" ?>
4+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
5+
<file source-language="en" datatype="plaintext" original="ng2.template">
6+
<body>
7+
<trans-unit id="af2ccf4b5dba59616e92cf1531505af02da8f6d2" datatype="html">
8+
<source>Hello i18n!</source>
9+
<target>Bonjour i18n!</target>
10+
<note priority="1" from="description">An introduction header for this sample</note>
11+
<note priority="1" from="meaning">User welcome</note>
12+
</trans-unit>
13+
</body>
14+
</file>
15+
</xliff>
16+
`;
17+

public/docs/_examples/i18n/ts/example-config.json

Whitespace-only changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<!-- #docregion -->
3+
<html>
4+
<head>
5+
<title>Angular i18n example</title>
6+
<meta charset="UTF-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
<link rel="stylesheet" href="styles.css">
9+
10+
<!-- 1. Load libraries -->
11+
<!-- #docregion libraries -->
12+
<!-- #docregion polyfills -->
13+
<!-- Polyfill(s) for older browsers -->
14+
<script src="node_modules/core-js/client/shim.min.js"></script>
15+
<!-- #enddocregion polyfills -->
16+
17+
<script src="node_modules/zone.js/dist/zone.js"></script>
18+
<script src="node_modules/reflect-metadata/Reflect.js"></script>
19+
<script src="node_modules/systemjs/dist/system.src.js"></script>
20+
<!-- #enddocregion libraries -->
21+
22+
<!-- 2. Configure SystemJS -->
23+
<!-- #docregion systemjs -->
24+
<script src="systemjs.config.js"></script>
25+
<script>
26+
System.import('app').catch(function(err){ console.error(err); });
27+
</script>
28+
<!-- #enddocregion systemjs -->
29+
</head>
30+
31+
<!-- 3. Display the application -->
32+
<!-- #docregion my-app -->
33+
<body>
34+
<my-app>Loading...</my-app>
35+
</body>
36+
<!-- #enddocregion my-app -->
37+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
3+
<file source-language="en" datatype="plaintext" original="ng2.template">
4+
<body>
5+
<trans-unit id="af2ccf4b5dba59616e92cf1531505af02da8f6d2" datatype="html">
6+
<source>Hello i18n!</source>
7+
<target/>
8+
<note priority="1" from="description">An introduction header for this sample</note>
9+
<note priority="1" from="meaning">User welcome</note>
10+
</trans-unit>
11+
</body>
12+
</file>
13+
</xliff>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!-- Exact copy of `messages.fr.xlf` for documentation purposes -->
2+
<!-- #docregion -->
3+
<?xml version="1.0" encoding="UTF-8" ?>
4+
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
5+
<file source-language="en" datatype="plaintext" original="ng2.template">
6+
<body>
7+
<!-- #docregion trans-unit -->
8+
<trans-unit id="af2ccf4b5dba59616e92cf1531505af02da8f6d2" datatype="html">
9+
<source>Hello i18n!</source>
10+
<target/>
11+
<note priority="1" from="description">An introduction header for this sample</note>
12+
<note priority="1" from="meaning">User welcome</note>
13+
</trans-unit>
14+
<!-- #enddocregion trans-unit -->
15+
</body>
16+
</file>
17+
</xliff>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"description": "i18n",
3+
"files": [
4+
"!**/*.d.ts",
5+
"!**/*.js",
6+
"!**/*.[1].*",
7+
"!**/*.metadata.json"
8+
],
9+
"tags": ["i18n"]
10+
}

public/docs/_examples/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"test:webpack": "karma start karma.webpack.conf.js",
2121
"build:webpack": "rimraf dist && webpack --config config/webpack.prod.js --bail",
2222
"build:cli": "ng build",
23-
"build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup.js"
23+
"build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup.js",
24+
"extract": "ng-xi18n"
2425
},
2526
"keywords": [],
2627
"author": "",
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: 7 additions & 2 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": "Translate the app 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."
@@ -147,11 +152,11 @@
147152

148153
"upgrade": {
149154
"title": "Upgrading from 1.x",
150-
"intro": "Angular 1 applications can be incrementally upgraded to Angular 2."
155+
"intro": "Incrementally upgrade an Angular 1 application to Angular 2."
151156
},
152157

153158
"webpack": {
154159
"title": "Webpack: an introduction",
155-
"intro": "Create your Angular applications with a Webpack based tooling"
160+
"intro": "Create Angular applications with a Webpack based tooling"
156161
}
157162
}

0 commit comments

Comments
 (0)