| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 47e9c7b commit e746369
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -201,6 +201,19 @@ Note: service worker support is experimental and subject to change. | |||
| 201 | 201 | </p> | |
| 202 | 202 | </details> | |
| 203 | 203 | ||
| 204 | + <details> | ||
| 205 | + <summary>missing-translation</summary> | ||
| 206 | + <p> | ||
| 207 | + <code>--missing-translation</code> | ||
| 208 | + </p> | ||
| 209 | + <p> | ||
| 210 | + How to handle missing translations for i18n. | ||
| 211 | + </p> | ||
| 212 | + <p> | ||
| 213 | + Values: <code>error</code>, <code>warning</code>, <code>ignore</code> | ||
| 214 | + </p> | ||
| 215 | + </details> | ||
| 216 | + | ||
| 204 | 217 | <details> | |
| 205 | 218 | <summary>output-hashing</summary> | |
| 206 | 219 | <p> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -112,6 +112,19 @@ ng eject | |||
| 112 | 112 | </p> | |
| 113 | 113 | </details> | |
| 114 | 114 | ||
| 115 | + <details> | ||
| 116 | + <summary>missing-translation</summary> | ||
| 117 | + <p> | ||
| 118 | + <code>--missing-translation</code> | ||
| 119 | + </p> | ||
| 120 | + <p> | ||
| 121 | + How to handle missing translations for i18n. | ||
| 122 | + </p> | ||
| 123 | + <p> | ||
| 124 | + Values: <code>error</code>, <code>warning</code>, <code>ignore</code> | ||
| 125 | + </p> | ||
| 126 | + </details> | ||
| 127 | + | ||
| 115 | 128 | <details> | |
| 116 | 129 | <summary>output-hashing</summary> | |
| 117 | 130 | <p> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -188,6 +188,19 @@ All the build Options are available in serve, below are the additional options. | |||
| 188 | 188 | </p> | |
| 189 | 189 | </details> | |
| 190 | 190 | ||
| 191 | + <details> | ||
| 192 | + <summary>missing-translation</summary> | ||
| 193 | + <p> | ||
| 194 | + <code>--missing-translation</code> | ||
| 195 | + </p> | ||
| 196 | + <p> | ||
| 197 | + How to handle missing translations for i18n. | ||
| 198 | + </p> | ||
| 199 | + <p> | ||
| 200 | + Values: <code>error</code>, <code>warning</code>, <code>ignore</code> | ||
| 201 | + </p> | ||
| 202 | + </details> | ||
| 203 | + | ||
| 191 | 204 | <details> | |
| 192 | 205 | <summary>output-hashing</summary> | |
| 193 | 206 | <p> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,14 +25,15 @@ ng xi18n --output-path src/locale | |||
| 25 | 25 | Now that you have generated a messages bundle source file, you can translate it. | |
| 26 | 26 | Let's say that your file containing the french translations is named `messages.fr.xlf` | |
| 27 | 27 | and is located in the `src/locale` folder. | |
| 28 | - If you want to use it when you serve your application you can use the 3 following commands: | ||
| 28 | + If you want to use it when you serve your application you can use the 4 following commands: | ||
| 29 | 29 | - `--i18n-file` Localization file to use for i18n. | |
| 30 | 30 | - `--i18n-format` Format of the localization file specified with --i18n-file. | |
| 31 | 31 | - `--locale` Locale to use for i18n. | |
| 32 | + - `--missing-translation` Defines the strategy to use for missing i18n translations. | ||
| 32 | 33 | ||
| 33 | 34 | In our case we can load the french translations with the following command: | |
| 34 | 35 | ```sh | |
| 35 | - ng serve --aot --locale fr --i18n-format xlf --i18n-file src/locale/messages.fr.xlf | ||
| 36 | + ng serve --aot --locale fr --i18n-format xlf --i18n-file src/locale/messages.fr.xlf --missing-translation error | ||
| 36 | 37 | ``` | |
| 37 | 38 | ||
| 38 | 39 | Our application is exactly the same but the `LOCALE_ID` has been provided with "fr", | |
@@ -46,14 +47,14 @@ your bootstrap file yourself. | |||
| 46 | 47 | To build your application with a specific locale you can use the exact same commands | |
| 47 | 48 | that you used for `serve`: | |
| 48 | 49 | ```sh | |
| 49 | - ng build --aot --locale fr --i18n-format xlf --i18n-file src/i18n/messages.fr.xlf | ||
| 50 | + ng build --aot --locale fr --i18n-format xlf --i18n-file src/i18n/messages.fr.xlf --missing-translation error | ||
| 50 | 51 | ``` | |
| 51 | 52 | ||
| 52 | 53 | When you build your application for a specific locale, it is probably a good idea to change | |
| 53 | 54 | the output path with the command `--output-path` in order to save the files to a different location. | |
| 54 | 55 | ||
| 55 | 56 | ```sh | |
| 56 | - ng build --aot --output-path dist/fr --locale fr --i18n-format xlf --i18n-file src/i18n/messages.fr.xlf | ||
| 57 | + ng build --aot --output-path dist/fr --locale fr --i18n-format xlf --i18n-file src/i18n/messages.fr.xlf --missing-translation error | ||
| 57 | 58 | ``` | |
| 58 | 59 | ||
| 59 | 60 | If you end up serving this specific version from a subdirectory, you can also change | |
@@ -63,7 +64,7 @@ For example if the french version of your application is served from https://mya | |||
| 63 | 64 | then you would build the french version like this: | |
| 64 | 65 | ||
| 65 | 66 | ```sh | |
| 66 | - ng build --aot --output-path dist/fr --base-href fr --locale fr --i18n-format xlf --i18n-file src/i18n/messages.fr.xlf | ||
| 67 | + ng build --aot --output-path dist/fr --base-href fr --locale fr --i18n-format xlf --i18n-file src/i18n/messages.fr.xlf --missing-translation error | ||
| 67 | 68 | ``` | |
| 68 | 69 | ||
| 69 | 70 | If you need more details about how to create scripts to generate the app in multiple | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -100,6 +100,11 @@ export const baseBuildCommandOptions: any = [ | |||
| 100 | 100 | type: String, | |
| 101 | 101 | description: 'Locale to use for i18n.' | |
| 102 | 102 | }, | |
| 103 | + { | ||
| 104 | + name: 'missing-translation', | ||
| 105 | + type: String, | ||
| 106 | + description: 'How to handle missing translations for i18n.' | ||
| 107 | + }, | ||
| 103 | 108 | { | |
| 104 | 109 | name: 'extract-css', | |
| 105 | 110 | type: Boolean, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,7 @@ export interface BuildOptions { | |||
| 13 | 13 | i18nFile?: string; | |
| 14 | 14 | i18nFormat?: string; | |
| 15 | 15 | locale?: string; | |
| 16 | + missingTranslation?: string; | ||
| 16 | 17 | extractCss?: boolean; | |
| 17 | 18 | watch?: boolean; | |
| 18 | 19 | outputHashing?: string; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,6 +69,7 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any) { | |||
| 69 | 69 | i18nFormat: buildOptions.i18nFormat, | |
| 70 | 70 | locale: buildOptions.locale, | |
| 71 | 71 | replaceExport: appConfig.platform === 'server', | |
| 72 | + missingTranslation: buildOptions.missingTranslation, | ||
| 72 | 73 | hostReplacementPaths, | |
| 73 | 74 | // If we don't explicitely list excludes, it will default to `['**/*.spec.ts']`. | |
| 74 | 75 | exclude: [] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,7 @@ import * as path from 'path'; | |||
| 4 | 4 | import * as ts from 'typescript'; | |
| 5 | 5 | import * as SourceMap from 'source-map'; | |
| 6 | 6 | ||
| 7 | - const {__NGTOOLS_PRIVATE_API_2} = require('@angular/compiler-cli'); | ||
| 7 | + const {__NGTOOLS_PRIVATE_API_2, VERSION} = require('@angular/compiler-cli'); | ||
| 8 | 8 | const ContextElementDependency = require('webpack/lib/dependencies/ContextElementDependency'); | |
| 9 | 9 | ||
| 10 | 10 | import {WebpackResourceLoader} from './resource_loader'; | |
@@ -31,6 +31,7 @@ export interface AotPluginOptions { | |||
| 31 | 31 | i18nFile?: string; | |
| 32 | 32 | i18nFormat?: string; | |
| 33 | 33 | locale?: string; | |
| 34 | + missingTranslation?: string; | ||
| 34 | 35 | ||
| 35 | 36 | // Use tsconfig to include path globs. | |
| 36 | 37 | exclude?: string | string[]; | |
@@ -68,6 +69,7 @@ export class AotPlugin implements Tapable { | |||
| 68 | 69 | private _i18nFile: string; | |
| 69 | 70 | private _i18nFormat: string; | |
| 70 | 71 | private _locale: string; | |
| 72 | + private _missingTranslation: string; | ||
| 71 | 73 | ||
| 72 | 74 | private _diagnoseFiles: { [path: string]: boolean } = {}; | |
| 73 | 75 | private _firstRun = true; | |
@@ -97,6 +99,7 @@ export class AotPlugin implements Tapable { | |||
| 97 | 99 | get i18nFile() { return this._i18nFile; } | |
| 98 | 100 | get i18nFormat() { return this._i18nFormat; } | |
| 99 | 101 | get locale() { return this._locale; } | |
| 102 | + get missingTranslation() { return this._missingTranslation; } | ||
| 100 | 103 | get firstRun() { return this._firstRun; } | |
| 101 | 104 | get lazyRoutes() { return this._lazyRoutes; } | |
| 102 | 105 | get discoveredLazyRoutes() { return this._discoveredLazyRoutes; } | |
@@ -246,6 +249,15 @@ export class AotPlugin implements Tapable { | |||
| 246 | 249 | if (options.hasOwnProperty('replaceExport')) { | |
| 247 | 250 | this._replaceExport = options.replaceExport || this._replaceExport; | |
| 248 | 251 | } | |
| 252 | + if (options.hasOwnProperty('missingTranslation')) { | ||
| 253 | + const [MAJOR, MINOR, PATCH] = VERSION.full.split('.').map((x: string) => parseInt(x, 10)); | ||
| 254 | + if (MAJOR < 4 || (MINOR == 2 && PATCH < 2)) { | ||
| 255 | + console.warn((`The --missing-translation parameter will be ignored because it is only ` | ||
| 256 | + + `compatible with Angular version 4.2.0 or higher. If you want to use it, please ` | ||
| 257 | + + `upgrade your Angular version.\n`)); | ||
| 258 | + } | ||
| 259 | + this._missingTranslation = options.missingTranslation; | ||
| 260 | + } | ||
| 249 | 261 | } | |
| 250 | 262 | ||
| 251 | 263 | private _findLazyRoutesInAst(): LazyRouteMap { | |
@@ -483,6 +495,7 @@ export class AotPlugin implements Tapable { | |||
| 483 | 495 | i18nFile: this.i18nFile, | |
| 484 | 496 | i18nFormat: this.i18nFormat, | |
| 485 | 497 | locale: this.locale, | |
| 498 | + missingTranslation: this.missingTranslation, | ||
| 486 | 499 | ||
| 487 | 500 | readResource: (path: string) => this._resourceLoader.get(path) | |
| 488 | 501 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,8 @@ | |||
| 1 | 1 | import {ng} from '../../../utils/process'; | |
| 2 | - import {expectFileToMatch, writeFile, createDir, appendToFile} from '../../../utils/fs'; | ||
| 2 | + import {expectFileToMatch, writeFile, createDir, appendToFile, readFile} from '../../../utils/fs'; | ||
| 3 | 3 | import {expectToFail} from '../../../utils/utils'; | |
| 4 | + import {Version} from '../../../../../packages/@angular/cli/upgrade/version'; | ||
| 5 | + import {SemVer} from 'semver'; | ||
| 4 | 6 | ||
| 5 | 7 | export default function() { | |
| 6 | 8 | return Promise.resolve() | |
@@ -22,10 +24,35 @@ export default function() { | |||
| 22 | 24 | '<h1 i18n="An introduction header for this sample">Hello i18n!</h1>')) | |
| 23 | 25 | .then(() => ng('build', '--aot', '--i18n-file', 'src/locale/messages.fr.xlf', '--i18n-format', | |
| 24 | 26 | 'xlf', '--locale', 'fr')) | |
| 25 | - .then(() => ng('build', '--aot', '--i18nFile', 'src/locale/messages.fr.xlf', '--i18nFormat', | ||
| 26 | - 'xlf', '--locale', 'fr')) | ||
| 27 | 27 | .then(() => expectFileToMatch('dist/main.bundle.js', /Bonjour i18n!/)) | |
| 28 | 28 | .then(() => ng('build', '--aot')) | |
| 29 | 29 | .then(() => expectToFail(() => expectFileToMatch('dist/main.bundle.js', /Bonjour i18n!/))) | |
| 30 | - .then(() => expectFileToMatch('dist/main.bundle.js', /Hello i18n!/)); | ||
| 30 | + .then(() => expectFileToMatch('dist/main.bundle.js', /Hello i18n!/)) | ||
| 31 | + .then(() => appendToFile('src/app/app.component.html', | ||
| 32 | + '<p i18n>Other content</p>')) | ||
| 33 | + .then(() => readFile('node_modules/@angular/compiler-cli/package.json') | ||
| 34 | + .then((compilerCliPackage): any => { | ||
| 35 | + const version = new Version(JSON.parse(compilerCliPackage).version); | ||
| 36 | + if (version.major === 2) { | ||
| 37 | + return expectToFail(() => ng('build', '--aot', '--i18nFile', 'src/locale/messages.fr.xlf', | ||
| 38 | + '--i18nFormat', 'xlf', '--locale', 'fr', '--missingTranslation', 'ignore')); | ||
| 39 | + } else { | ||
| 40 | + return ng('build', '--aot', '--i18nFile', 'src/locale/messages.fr.xlf', '--i18nFormat', | ||
| 41 | + 'xlf', '--locale', 'fr', '--missingTranslation', 'ignore') | ||
| 42 | + .then(() => expectFileToMatch('dist/main.bundle.js', /Other content/)); | ||
| 43 | + } | ||
| 44 | + }) | ||
| 45 | + ) | ||
| 46 | + .then(() => readFile('node_modules/@angular/compiler-cli/package.json') | ||
| 47 | + .then((compilerCliPackage): any => { | ||
| 48 | + const version = new Version(JSON.parse(compilerCliPackage).version); | ||
| 49 | + if (version.isGreaterThanOrEqualTo(new SemVer('4.2.0-beta.0')) || version.major === 2) { | ||
| 50 | + return expectToFail(() => ng('build', '--aot', '--i18nFile', 'src/locale/messages.fr.xlf', | ||
| 51 | + '--i18nFormat', 'xlf', '--locale', 'fr', '--missingTranslation', 'error')); | ||
| 52 | + } else { | ||
| 53 | + return ng('build', '--aot', '--i18nFile', 'src/locale/messages.fr.xlf', | ||
| 54 | + '--i18nFormat', 'xlf', '--locale', 'fr', '--missingTranslation', 'error'); | ||
| 55 | + } | ||
| 56 | + }) | ||
| 57 | + ); | ||
| 31 | 58 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,7 @@ export default function() { | |||
| 15 | 15 | .then((output) => { | |
| 16 | 16 | if (!output.stdout.match(/starting from Angular v4/)) { | |
| 17 | 17 | expectFileToExist(join('src', 'messages.xlf')); | |
| 18 | - expectFileToMatch(join('src', 'messages.xlf'), /source-language="fr"/) | ||
| 18 | + expectFileToMatch(join('src', 'messages.xlf'), /source-language="fr"/); | ||
| 19 | 19 | } | |
| 20 | 20 | }); | |
| 21 | 21 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments