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

[BACKUP] new I18n guide #2340

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions public/docs/_examples/i18n/e2e-spec.ts.disabled
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';

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);
});

});
106 changes: 106 additions & 0 deletions public/docs/_examples/i18n/ts-snippets/i18n.config.snippets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* 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: 'my-app',
template: `
<div>
{{ messages.length | i18nPlural: messageMapping }}
</div>
`
})
export class AppComponent {
messages: string[];
messageMapping: {[k:string]: string} = {
'=0': 'No messages.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use one and other which is the standard for en

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=0 remains the same?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one and other are caterogies, =x is for discrete values, works with any x

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

'=1': 'One message.',
'other': '# messages.'
}
}
// #enddocregion i18n-plural-pipe

// #docregion i18n-select-pipe
@Component({
selector: 'my-app',
template: `
<div>
{{ gender | i18nSelect: genderMap }}
</div>
`
})
export class AppComponent {
gender = 'male';
genderMap = {
'male': 'Invite him.',
'female': 'Invite her.',
'other': 'Invite them.'
}
}
// #enddocregion i18n-select-pipe

// #docregion tsconfig
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
},
"angularCompilerOptions": {
"genDir": "./app/i18n"
}
}
// #enddocregion tsconfig

// #docregion bootstrap
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app.module';

platformBrowserDynamic().bootstrapModule(AppModule);
// #enddocregion bootstrap

// #docregion bootstrap-i18n
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID } from '@angular/core';

import { AppModule } from './app.module';
import { TRANSLATION } from './i18n/messages.fr';

// Compile using french translations
platformBrowserDynamic().bootstrapModule(
AppModule,
{
providers: [
{provide: TRANSLATIONS, useValue: TRANSLATION},
{provide: TRANSLATIONS_FORMAT, useValue: 'xlf'},
{provide: LOCALE_ID, useValue: 'fr'}
]
}
);
// #enddocregion bootstrap-i18n

// #docregion messages-ts
export const TRANSLATION = `<?xml version="1.0" encoding="UTF-8"?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this will be in CompilerConfig soon, I'll try to remember to cc the doc team on the PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an ETA on that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

started working on that. probably 2.1 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I'll leave it as is for now then we'll update it.

<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
1 change: 1 addition & 0 deletions public/docs/dart/latest/guide/i18n.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!= partial("../../../_includes/_ts-temp")
1 change: 1 addition & 0 deletions public/docs/js/latest/guide/i18n.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!= partial("../../../_includes/_ts-temp")
5 changes: 5 additions & 0 deletions public/docs/ts/latest/guide/_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
"intro": "Talk to a remote server with an HTTP Client."
},

"i18n": {
"title": "Internationalization (i18n)",
"intro": "Easily translate your website into multiple languages"
},

"lifecycle-hooks": {
"title": "Lifecycle Hooks",
"intro": "Angular calls lifecycle hook methods on directives and components as it creates, changes, and destroys them."
Expand Down
Loading