This repository was archived by the owner on Dec 4, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 875
[WIP] docs(guide): document internationalization (i18n) #2309
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/// <reference path='../_protractor/e2e.d.ts' /> | ||
'use strict'; | ||
describe('QuickStart E2E Tests', function () { | ||
|
||
let expectedMsg = 'Hello from Angular 2 App with i18n'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const |
||
|
||
beforeEach(function () { | ||
browser.get(''); | ||
}); | ||
|
||
it(`should display: ${expectedMsg}`, function () { | ||
expect(element(by.css('h1')).getText()).toEqual(expectedMsg); | ||
}); | ||
|
||
it('should display an image', function () { | ||
expect(element(by.css('img')).isPresent()).toBe(true); | ||
}); | ||
|
||
}); |
130 changes: 130 additions & 0 deletions
130
public/docs/_examples/i18n/ts-snippets/i18n.config.snippets.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* tslint:disable */ | ||
// #docregion i18n-directive | ||
<h1 i18n>Hello i18n</h1> | ||
// #enddocregion i18n-directive | ||
|
||
// #docregion i18n-directive-desc | ||
<h1 i18n="An introduction header for this sample">Hello i18n</h1> | ||
// #enddocregion i18n-directive-desc | ||
|
||
// #docregion i18n-directive-meaning | ||
<h1 i18n="User welcome|An introduction header for this sample">Hello i18n</h1> | ||
// #enddocregion i18n-directive-meaning | ||
|
||
// #docregion i18n-plural-pipe | ||
@Component({ | ||
selector: 'app', | ||
template: ` | ||
<div> | ||
{{ messages.length | i18nPlural: messageMapping }} | ||
</div> | ||
`, | ||
}) | ||
class MyApp { | ||
messages: any[]; | ||
messageMapping: {[k:string]: string} = { | ||
'=0': 'No messages.', | ||
'=1': 'One message.', | ||
'other': '# messages.' | ||
} | ||
} | ||
// #enddocregion i18n-plural-pipe | ||
|
||
// #docregion i18n-select-pipe | ||
@Component({ | ||
selector: 'app', | ||
template: ` | ||
<div> | ||
{{ gender | i18nSelect: inviteMap }} | ||
</div> | ||
`, | ||
}) | ||
class MyApp { | ||
gender: string = 'male'; | ||
inviteMap: any = { | ||
'male': 'Invite him.', | ||
'female': 'Invite her.', | ||
'other': 'Invite them.' | ||
} | ||
} | ||
// #enddocregion i18n-select-pipe | ||
|
||
// #docregion tsconfig1 | ||
{ | ||
"compilerOptions": { | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"target": "es5", | ||
"module": "commonjs", | ||
"outDir": "./dist/out-tsc" | ||
}, | ||
"files": [ | ||
"./src/main.ts" | ||
] | ||
} | ||
// #enddocregion tsconfig1 | ||
|
||
// #docregion tsconfig2 | ||
{ | ||
"compilerOptions": { | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"target": "es5", | ||
"module": "commonjs", | ||
"outDir": "./dist/out-tsc" | ||
}, | ||
"files": [ | ||
"./src/main.ts" | ||
], | ||
"angularCompilerOptions": { | ||
"genDir": "./src/i18n" | ||
} | ||
} | ||
// #enddocregion tsconfig2 | ||
|
||
// #docregion bootstrap | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
import { enableProdMode } from '@angular/core'; | ||
import { environment } from './environments/environment'; | ||
import { AppModule } from './app/'; | ||
|
||
if (environment.production) { | ||
enableProdMode(); | ||
} | ||
|
||
platformBrowserDynamic().bootstrapModule(AppModule); | ||
// #enddocregion bootstrap | ||
|
||
// #docregion bootstrap-i18n | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
import { enableProdMode, TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID } from '@angular/core'; | ||
import { environment } from './environments/environment'; | ||
import { AppModule } from './app/'; | ||
import { TRANSLATION } from './i18n/messages.fr'; | ||
|
||
if (environment.production) { | ||
enableProdMode(); | ||
} | ||
|
||
// Compile using french translations | ||
platformBrowserDynamic().bootstrapModule( | ||
AppModule, | ||
{ | ||
providers: [ | ||
{provide: TRANSLATIONS, useValue: TRANSLATION}, | ||
{provide: TRANSLATIONS_FORMAT, useValue: 'xlf'}, | ||
{provide: LOCALE_ID, useValue: 'fr'} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trailing comma There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You want that I add a trailing comma ? |
||
] | ||
} | ||
); | ||
// #enddocregion bootstrap-i18n | ||
|
||
|
||
// #docregion messages-ts | ||
export const TRANSLATION = `<?xml version="1.0" encoding="UTF-8"?> | ||
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> | ||
<file source-language="en" datatype="plaintext" original="ng2.template" target-language="fr-fr"> | ||
... | ||
</file> | ||
</xliff>`; | ||
// #enddocregion messages-ts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!= partial("../../../_includes/_ts-temp") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!= partial("../../../_includes/_ts-temp") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using it in all examples, I think it has to do with ts-node to be able to understand a few things.