-
Notifications
You must be signed in to change notification settings - Fork 875
[BACKUP] new I18n guide #2340
[BACKUP] new I18n guide #2340
Changes from all commits
68fdbce
cb7225e
3552db7
b3e44c8
17ed3ca
f727149
dc9bd4d
586f47e
76848c4
1576c08
c48eff3
a726076
c3e219c
e413ae9
94b6ea2
ce1de16
89e45d7
8b8ccf2
635b4e4
3373fad
e842200
6ff5c74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/// <reference path='../_protractor/e2e.d.ts' /> | ||
'use strict'; | ||
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!'); | ||
}); | ||
|
||
}); |
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 |
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--> |
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--> |
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 { } | ||
|
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 ] | ||
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. nit: trailing coma 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. We don't enforce it in the examples. |
||
}) | ||
|
||
export class AppModule { } |
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); |
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'} | ||
] | ||
} | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// #docregion | ||
export const TRANSLATION = ` | ||
|
||
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. explain what this is ? 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. 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 |
||
`; | ||
|
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> | ||
`; | ||
|
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> |
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> |
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> |
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"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
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. what is the added value of the alias ? 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. Not having to do |
||
}, | ||
"keywords": [], | ||
"author": "", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!= partial("../../../_includes/_ts-temp") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!= partial("../../../_includes/_ts-temp") |
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.
Is this required in TS ?
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.
In our case yes, because we there's a couple of es2015 things that node requires
'use strict';
to support.