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

Commit ed95dab

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

File tree

27 files changed

+550
-5
lines changed

27 files changed

+550
-5
lines changed

gulpfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ function runE2eTsTests(appDir, outputFile) {
297297
} catch (e) {
298298
exampleConfig = {};
299299
}
300-
300+
301301
var config = {
302302
build: exampleConfig.build || 'tsc',
303303
run: exampleConfig.run || 'http-server:e2e'
@@ -1263,7 +1263,7 @@ function apiExamplesWatch(postShredAction) {
12631263
}
12641264

12651265
function devGuideExamplesWatch(shredOptions, postShredAction, focus) {
1266-
var watchPattern = focus ? '**/' + focus + '/**/*.*' : '**/*.*';
1266+
var watchPattern = focus ? '**/{' + focus + ',cb-' + focus+ '}/**/*.*' : '**/*.*';
12671267
var includePattern = path.join(shredOptions.examplesDir, watchPattern);
12681268
// removed this version because gulp.watch has the same glob issue that dgeni has.
12691269
// var excludePattern = '!' + path.join(shredOptions.examplesDir, '**/node_modules/**/*.*');
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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// #docplaster
2+
// #docregion
3+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
4+
import { TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID } from '@angular/core';
5+
6+
import { AppModule } from '../../app.module';
7+
// #docregion translation-import
8+
import { translations } from './messages.fr';
9+
// #enddocregion translation-import
10+
11+
// #enddocregion
12+
/*
13+
// Webpack users don't need to create
14+
// They simply define `translations` here and let webpack load it:
15+
// #docregion webpack
16+
const translations = require("raw!./cb-i18n/messages.fr.xlf");
17+
// #enddocregion webpack
18+
*/
19+
20+
// #docregion
21+
// Compile using french translations
22+
const platform = platformBrowserDynamic();
23+
24+
platform.bootstrapModule(
25+
AppModule,
26+
{
27+
providers: [
28+
{provide: TRANSLATIONS, useValue: translations},
29+
{provide: TRANSLATIONS_FORMAT, useValue: 'xlf'},
30+
{provide: LOCALE_ID, useValue: 'fr'}
31+
]
32+
}
33+
);
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 translations = `
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+

0 commit comments

Comments
 (0)