-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(aio): updated i18n guide and example
- Loading branch information
Showing
31 changed files
with
819 additions
and
782 deletions.
There are no files selected for viewing
This file contains 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
File renamed without changes.
This file contains 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,7 @@ | ||
// #docregion import-locale-extra | ||
import { registerLocaleData } from '@angular/common'; | ||
import localeFrCa from '@angular/common/locales/fr-CA'; | ||
import localeFrCaExtra from '@angular/common/locales/extra/fr-CA'; | ||
|
||
registerLocaleData(localeFrCa, localeFrCaExtra); | ||
// #enddocregion import-locale-extra |
This file contains 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,13 @@ | ||
// #docregion | ||
import { LOCALE_ID, NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
|
||
import { AppComponent } from '../src/app/app.component'; | ||
|
||
@NgModule({ | ||
imports: [ BrowserModule ], | ||
declarations: [ AppComponent ], | ||
providers: [ { provide: LOCALE_ID, useValue: 'fr' } ], | ||
bootstrap: [ AppComponent ] | ||
}) | ||
export class AppModule { } |
6 changes: 6 additions & 0 deletions
6
aio/content/examples/i18n/src/main.1.ts → ...content/examples/i18n/doc-files/main.1.ts
This file contains 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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
// #docregion | ||
import { enableProdMode } from '@angular/core'; | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
|
||
import { AppModule } from './app/app.module'; | ||
import { environment } from './environments/environment'; | ||
|
||
if (environment.production) { | ||
enableProdMode(); | ||
} | ||
|
||
platformBrowserDynamic().bootstrapModule(AppModule); |
This file contains 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,22 @@ | ||
// #docregion | ||
import { enableProdMode, TRANSLATIONS, TRANSLATIONS_FORMAT } from '@angular/core'; | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
|
||
import { AppModule } from './app/app.module'; | ||
import { environment } from './environments/environment'; | ||
|
||
if (environment.production) { | ||
enableProdMode(); | ||
} | ||
|
||
// use the require method provided by webpack | ||
declare const require; | ||
// we use the webpack raw-loader to return the content as a string | ||
const translations = require(`raw-loader!./locale/messages.fr.xlf`); | ||
|
||
platformBrowserDynamic().bootstrapModule(AppModule, { | ||
providers: [ | ||
{provide: TRANSLATIONS, useValue: translations}, | ||
{provide: TRANSLATIONS_FORMAT, useValue: 'xlf'} | ||
] | ||
}); |
This file contains 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,13 @@ | ||
// #docregion | ||
import { MissingTranslationStrategy } from '@angular/core'; | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
import { AppModule } from './app/app.module'; | ||
|
||
// ... | ||
|
||
platformBrowserDynamic().bootstrapModule(AppModule, { | ||
missingTranslation: MissingTranslationStrategy.Error, | ||
providers: [ | ||
// ... | ||
] | ||
}); |
This file contains 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,73 @@ | ||
<!-- The `messages.fr.xlf` after translation for documentation purposes --> | ||
<!-- #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> | ||
<!-- #docregion translated-hello-before --> | ||
<trans-unit id="introductionHeader" datatype="html"> | ||
<source>Hello i18n!</source> | ||
<note priority="1" from="description">An introduction header for this sample</note> | ||
<note priority="1" from="meaning">User welcome</note> | ||
</trans-unit> | ||
<!-- #enddocregion translated-hello-before --> | ||
<!-- #docregion translated-hello --> | ||
<!-- #docregion custom-id --> | ||
<trans-unit id="introductionHeader" datatype="html"> | ||
<!-- #enddocregion custom-id --> | ||
<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> | ||
<!-- #enddocregion translated-hello --> | ||
<!-- #docregion translated-other-nodes --> | ||
<!-- #docregion generated-id --> | ||
<trans-unit id="ba0cc104d3d69bf669f97b8d96a4c5d8d9559aa3" datatype="html"> | ||
<!-- #enddocregion generated-id --> | ||
<source>I don't output any element</source> | ||
<target>Je n'affiche aucun élément</target> | ||
</trans-unit> | ||
<trans-unit id="701174153757adf13e7c24a248c8a873ac9f5193" datatype="html"> | ||
<source>Angular logo</source> | ||
<target>Logo d'Angular</target> | ||
</trans-unit> | ||
<!-- #enddocregion translated-other-nodes --> | ||
<!-- #docregion translated-plural --> | ||
<trans-unit id="5a134dee893586d02bffc9611056b9cadf9abfad" datatype="html"> | ||
<source>{VAR_PLURAL, plural, =0 {just now} =1 {one minute ago} other {<x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes ago} }</source> | ||
<target>{VAR_PLURAL, plural, =0 {à l'instant} =1 {il y a une minute} other {il y a <x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes} }</target> | ||
</trans-unit> | ||
<!-- #enddocregion translated-plural --> | ||
<!-- #docregion translated-select --> | ||
<!-- #docregion translate-select-1 --> | ||
<trans-unit id="52515023fc70c216ef291086c1962ff135a9fe13" datatype="html"> | ||
<source>The author is <x id="ICU" equiv-text="{gender, select, m {...} f {...} o {...}}"/></source> | ||
<target>L'auteur est <x id="ICU" equiv-text="{gender, select, m {...} f {...} o {...}}"/></target> | ||
</trans-unit> | ||
<!-- #enddocregion translate-select-1 --> | ||
<!-- #docregion translate-select-2 --> | ||
<trans-unit id="4e6fd3f2bb3477e8ad2088f03257f6e1b8b515a5" datatype="html"> | ||
<source>{VAR_SELECT, select, m {male} f {female} o {other} }</source> | ||
<target>{VAR_SELECT, select, m {un homme} f {une femme} o {autre} }</target> | ||
</trans-unit> | ||
<!-- #enddocregion translate-select-2 --> | ||
<!-- #enddocregion translated-select --> | ||
<!-- #docregion translate-nested --> | ||
<!-- #docregion translate-nested-1 --> | ||
<trans-unit id="f7a55c9ef7c5b37147825a9041263305063e63e9" datatype="html"> | ||
<source>Updated: <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/></source> | ||
<target>Mis à jour: <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/></target> | ||
</trans-unit> | ||
<!-- #enddocregion translate-nested-1 --> | ||
<!-- #docregion translate-nested-2 --> | ||
<trans-unit id="80b5ac44661751e191225c0b1e000bceeeccb52c" datatype="html"> | ||
<source>{VAR_PLURAL, plural, =0 {just now} =1 {one minute ago} other {<x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes ago by {VAR_SELECT, select, m {male} f {female} o {other} }} }</source> | ||
<target>{VAR_PLURAL, plural, =0 {à l'instant} =1 {il y a une minute} other {il y a <x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes par {VAR_SELECT, select, m {un homme} f {une femme} o {autre} }} }</target> | ||
</trans-unit> | ||
<!-- #enddocregion translate-nested-2 --> | ||
<!-- #enddocregion translate-nested --> | ||
</body> | ||
</file> | ||
</xliff> | ||
|
This file was deleted.
Oops, something went wrong.
This file contains 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,48 @@ | ||
'use strict'; // necessary for es6 output in node | ||
|
||
import { browser, element, by } from 'protractor'; | ||
|
||
// disable until we get cli 1.5+ and angular 5+ to be able to run this | ||
describe('i18n E2E Tests', () => { | ||
|
||
beforeEach(function () { | ||
browser.get(''); | ||
}); | ||
|
||
it('should display i18n translated welcome: Bonjour !', function () { | ||
expect(element(by.css('h1')).getText()).toEqual('Bonjour i18n !'); | ||
}); | ||
|
||
it('should display the node texts without elements', function () { | ||
expect(element(by.css('app-root')).getText()).toContain(`Je n'affiche aucun élément`); | ||
}); | ||
|
||
it('should display the translated title attribute', function () { | ||
const title = element(by.css('img')).getAttribute('title'); | ||
expect(title).toBe(`Logo d'Angular`); | ||
}); | ||
|
||
it('should display the ICU plural expression', function () { | ||
expect(element.all(by.css('span')).get(0).getText()).toBe(`Mis à jour à l'instant`); | ||
}); | ||
|
||
it('should display the ICU select expression', function () { | ||
const selectIcuExp = element.all(by.css('span')).get(1); | ||
expect(selectIcuExp.getText()).toBe(`L'auteur est une femme`); | ||
element.all(by.css('button')).get(2).click(); | ||
expect(selectIcuExp.getText()).toBe(`L'auteur est un homme`); | ||
}); | ||
|
||
it('should display the nested expression', function() { | ||
const nestedExp = element.all(by.css('span')).get(2); | ||
const incBtn = element.all(by.css('button')).get(0); | ||
expect(nestedExp.getText()).toBe(`Mis à jour: à l'instant`); | ||
incBtn.click(); | ||
expect(nestedExp.getText()).toBe(`Mis à jour: il y a une minute`); | ||
incBtn.click(); | ||
incBtn.click(); | ||
element.all(by.css('button')).get(4).click(); | ||
expect(nestedExp.getText()).toBe(`Mis à jour: il y a 3 minutes par autre`); | ||
}); | ||
|
||
}); |
This file contains 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,3 @@ | ||
{ | ||
"projectType": "i18n" | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,13 +1,12 @@ | ||
// #docregion | ||
import { NgModule } from '@angular/core'; | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
|
||
import { AppComponent } from './app.component'; | ||
import { AppComponent } from './app.component'; | ||
|
||
@NgModule({ | ||
imports: [ BrowserModule ], | ||
imports: [ BrowserModule ], | ||
declarations: [ AppComponent ], | ||
bootstrap: [ AppComponent ] | ||
bootstrap: [ AppComponent ] | ||
}) | ||
|
||
export class AppModule { } |
Oops, something went wrong.