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 all 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
13 changes: 13 additions & 0 deletions public/docs/_examples/i18n/e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// <reference path='../_protractor/e2e.d.ts' />
'use strict';
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this required in TS ?

Copy link
Contributor

Choose a reason for hiding this comment

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

In our case yes, because we there's a couple of es2015 things that node requires 'use strict'; to support.

describe('i18n E2E Tests', () => {

beforeEach(function () {
browser.get('');
});

it('should display i18n translated welcome: Bonjour i18n!', function () {
expect(element(by.css('h1')).getText()).toEqual('Bonjour i18n!');
});

});
6 changes: 6 additions & 0 deletions public/docs/_examples/i18n/ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/*.ngfactory.ts
**/*.metadata.json
**/messages.xlf
dist
!app/tsconfig.json
!rollup.js
11 changes: 11 additions & 0 deletions public/docs/_examples/i18n/ts/app/app.component.1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!--#docregion greeting-->
<h1>Hello i18n!</h1>
<!--#enddocregion greeting-->

<!--#docregion i18n-attribute-->
<h1 i18n>Hello i18n!</h1>
<!--#enddocregion i18n-attribute-->

<!--#docregion i18n-attribute-desc-->
<h1 i18n="An introduction header for this sample">Hello i18n!</h1>
<!--#enddocregion i18n-attribute-desc-->
4 changes: 4 additions & 0 deletions public/docs/_examples/i18n/ts/app/app.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!--#docregion-->
<!--#docregion i18n-attribute-meaning-->
<h1 i18n="User welcome|An introduction header for this sample">Hello i18n!</h1>
<!--#enddocregion i18n-attribute-meaning-->
10 changes: 10 additions & 0 deletions public/docs/_examples/i18n/ts/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// #docregion
import { Component } from '@angular/core';

@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: './app.component.html'
})
export class AppComponent { }

13 changes: 13 additions & 0 deletions public/docs/_examples/i18n/ts/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// #docregion
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';

@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: trailing coma

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't enforce it in the examples.

})

export class AppModule { }
7 changes: 7 additions & 0 deletions public/docs/_examples/i18n/ts/app/main.1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// #docregion
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

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

const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);
19 changes: 19 additions & 0 deletions public/docs/_examples/i18n/ts/app/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// #docregion
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID } from '@angular/core';

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

// Compile using french translations
const platform = platformBrowserDynamic();
platform.bootstrapModule(
AppModule,
{
providers: [
{provide: TRANSLATIONS, useValue: TRANSLATION},
{provide: TRANSLATIONS_FORMAT, useValue: 'xlf'},
{provide: LOCALE_ID, useValue: 'fr'}
]
}
);
5 changes: 5 additions & 0 deletions public/docs/_examples/i18n/ts/app/messages.fr.1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// #docregion
export const TRANSLATION = `

Copy link
Contributor

Choose a reason for hiding this comment

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

explain what this is ?

Copy link
Contributor

Choose a reason for hiding this comment

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

A file we need for example purpose, since our docs examples come from real files. Later in the guide we insert the content of the the .xlf file.

`;

17 changes: 17 additions & 0 deletions public/docs/_examples/i18n/ts/app/messages.fr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// #docregion
export const TRANSLATION = `
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="af2ccf4b5dba59616e92cf1531505af02da8f6d2" datatype="html">
<source>Hello i18n!</source>
<target>Bonjour i18n!</target>
<note priority="1" from="description">An introduction header for this sample</note>
<note priority="1" from="meaning">User welcome</note>
</trans-unit>
</body>
</file>
</xliff>
`;

Empty file.
37 changes: 37 additions & 0 deletions public/docs/_examples/i18n/ts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<!-- #docregion -->
<html>
<head>
<title>Angular i18n example</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">

<!-- 1. Load libraries -->
<!-- #docregion libraries -->
<!-- #docregion polyfills -->
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<!-- #enddocregion polyfills -->

<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<!-- #enddocregion libraries -->

<!-- 2. Configure SystemJS -->
<!-- #docregion systemjs -->
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
<!-- #enddocregion systemjs -->
</head>

<!-- 3. Display the application -->
<!-- #docregion my-app -->
<body>
<my-app>Loading...</my-app>
</body>
<!-- #enddocregion my-app -->
</html>
13 changes: 13 additions & 0 deletions public/docs/_examples/i18n/ts/messages.fr.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="af2ccf4b5dba59616e92cf1531505af02da8f6d2" datatype="html">
<source>Hello i18n!</source>
<target/>
<note priority="1" from="description">An introduction header for this sample</note>
<note priority="1" from="meaning">User welcome</note>
</trans-unit>
</body>
</file>
</xliff>
15 changes: 15 additions & 0 deletions public/docs/_examples/i18n/ts/messages.fr.xlf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* tslint:disable */
// #docregion
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="af2ccf4b5dba59616e92cf1531505af02da8f6d2" datatype="html">
<source>Hello i18n!</source>
<target/>
<note priority="1" from="description">An introduction header for this sample</note>
<note priority="1" from="meaning">User welcome</note>
</trans-unit>
</body>
</file>
</xliff>
10 changes: 10 additions & 0 deletions public/docs/_examples/i18n/ts/plnkr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "i18n",
"files": [
"!**/*.d.ts",
"!**/*.js",
"!**/*.[1].*",
"!**/*.metadata.json"
],
"tags": ["i18n"]
}
3 changes: 2 additions & 1 deletion public/docs/_examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"test:webpack": "karma start karma.webpack.conf.js",
"build:webpack": "rimraf dist && webpack --config config/webpack.prod.js --bail",
"build:cli": "ng build",
"build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup.js"
"build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup.js",
"extract": "ng-xi18n"
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the added value of the alias ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not having to do ./node_modules/.bin/ng-xi18n.

},
"keywords": [],
"author": "",
Expand Down
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",
"intro": "Translate your application 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