|
| 1 | +/* tslint:disable */ |
| 2 | +// #docregion i18n-directive |
| 3 | +<h1 i18n>Hello i18n</h1> |
| 4 | +// #enddocregion i18n-directive |
| 5 | +
|
| 6 | +// #docregion i18n-directive-desc |
| 7 | +<h1 i18n="An introduction header for this sample">Hello i18n</h1> |
| 8 | +// #enddocregion i18n-directive-desc |
| 9 | +
|
| 10 | +// #docregion i18n-directive-meaning |
| 11 | +<h1 i18n="User welcome|An introduction header for this sample">Hello i18n</h1> |
| 12 | +// #enddocregion i18n-directive-meaning |
| 13 | + |
| 14 | +// #docregion i18n-plural-pipe |
| 15 | +@Component({ |
| 16 | + selector: 'app', |
| 17 | + template: ` |
| 18 | + <div> |
| 19 | + {{ messages.length | i18nPlural: messageMapping }} |
| 20 | + </div> |
| 21 | + `, |
| 22 | +}) |
| 23 | +class MyApp { |
| 24 | + messages: any[]; |
| 25 | + messageMapping: {[k:string]: string} = { |
| 26 | + '=0': 'No messages.', |
| 27 | + '=1': 'One message.', |
| 28 | + 'other': '# messages.' |
| 29 | + } |
| 30 | +} |
| 31 | +// #enddocregion i18n-plural-pipe |
| 32 | + |
| 33 | +// #docregion i18n-select-pipe |
| 34 | +@Component({ |
| 35 | + selector: 'app', |
| 36 | + template: ` |
| 37 | + <div> |
| 38 | + {{ gender | i18nSelect: inviteMap }} |
| 39 | + </div> |
| 40 | + `, |
| 41 | +}) |
| 42 | +class MyApp { |
| 43 | + gender: string = 'male'; |
| 44 | + inviteMap: any = { |
| 45 | + 'male': 'Invite him.', |
| 46 | + 'female': 'Invite her.', |
| 47 | + 'other': 'Invite them.' |
| 48 | + } |
| 49 | +} |
| 50 | +// #enddocregion i18n-select-pipe |
| 51 | + |
| 52 | +// #docregion tsconfig1 |
| 53 | +{ |
| 54 | + "compilerOptions": { |
| 55 | + "emitDecoratorMetadata": true, |
| 56 | + "experimentalDecorators": true, |
| 57 | + "target": "es5", |
| 58 | + "module": "commonjs", |
| 59 | + "outDir": "./dist/out-tsc" |
| 60 | + }, |
| 61 | + "files": [ |
| 62 | + "./src/main.ts" |
| 63 | + ] |
| 64 | +} |
| 65 | +// #enddocregion tsconfig1 |
| 66 | + |
| 67 | +// #docregion tsconfig2 |
| 68 | +{ |
| 69 | + "compilerOptions": { |
| 70 | + "emitDecoratorMetadata": true, |
| 71 | + "experimentalDecorators": true, |
| 72 | + "target": "es5", |
| 73 | + "module": "commonjs", |
| 74 | + "outDir": "./dist/out-tsc" |
| 75 | + }, |
| 76 | + "files": [ |
| 77 | + "./src/main.ts" |
| 78 | + ], |
| 79 | + "angularCompilerOptions": { |
| 80 | + "genDir": "./src/i18n" |
| 81 | + } |
| 82 | +} |
| 83 | +// #enddocregion tsconfig2 |
| 84 | + |
| 85 | +// #docregion bootstrap |
| 86 | +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; |
| 87 | +import { enableProdMode } from '@angular/core'; |
| 88 | +import { environment } from './environments/environment'; |
| 89 | +import { AppModule } from './app/'; |
| 90 | + |
| 91 | +if (environment.production) { |
| 92 | + enableProdMode(); |
| 93 | +} |
| 94 | + |
| 95 | +platformBrowserDynamic().bootstrapModule(AppModule); |
| 96 | +// #enddocregion bootstrap |
| 97 | + |
| 98 | +// #docregion bootstrap-i18n |
| 99 | +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; |
| 100 | +import { enableProdMode, TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID } from '@angular/core'; |
| 101 | +import { environment } from './environments/environment'; |
| 102 | +import { AppModule } from './app/'; |
| 103 | +import { TRANSLATION } from './i18n/messages.fr'; |
| 104 | + |
| 105 | +if (environment.production) { |
| 106 | + enableProdMode(); |
| 107 | +} |
| 108 | + |
| 109 | +// Compile using french translations |
| 110 | +platformBrowserDynamic().bootstrapModule( |
| 111 | + AppModule, |
| 112 | + { |
| 113 | + providers: [ |
| 114 | + {provide: TRANSLATIONS, useValue: TRANSLATION}, |
| 115 | + {provide: TRANSLATIONS_FORMAT, useValue: 'xlf'}, |
| 116 | + {provide: LOCALE_ID, useValue: 'fr'} |
| 117 | + ] |
| 118 | + } |
| 119 | +); |
| 120 | +// #enddocregion bootstrap-i18n |
| 121 | + |
| 122 | + |
| 123 | +// #docregion messages-ts |
| 124 | +export const TRANSLATION = `<?xml version="1.0" encoding="UTF-8"?> |
| 125 | + <xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> |
| 126 | + <file source-language="en" datatype="plaintext" original="ng2.template" target-language="fr-fr"> |
| 127 | + ... |
| 128 | + </file> |
| 129 | + </xliff>`; |
| 130 | +// #enddocregion messages-ts |
0 commit comments