Skip to content

Commit 5cf9a08

Browse files
committed
refactor(@angular-devkit/build-angular): remove deprecated i18n options from server and browser builder
BREAKING CHANGE: Removal of deprecated browser and server command options. - `i18nFile`, use `locales` object in the project metadata instead. - `i18nFormat`, No longer needed as the format will be determined automatically. - `i18nLocale`, use `localize` option instead.
1 parent 7d00221 commit 5cf9a08

24 files changed

+42
-233
lines changed

packages/angular_devkit/build_angular/src/browser/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ export function buildWebpackBrowser(
668668
const { content, warnings, errors } = await indexHtmlGenerator.process({
669669
baseHref: getLocaleBaseHref(i18n, locale) || options.baseHref,
670670
// i18nLocale is used when Ivy is disabled
671-
lang: locale || options.i18nLocale,
671+
lang: locale || undefined,
672672
outputPath,
673673
files: mapEmittedFilesToFileInfo(files),
674674
noModuleFiles: mapEmittedFilesToFileInfo(noModuleFiles),

packages/angular_devkit/build_angular/src/browser/schema.json

-15
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,6 @@
208208
"description": "Log progress to the console while building.",
209209
"default": true
210210
},
211-
"i18nFile": {
212-
"type": "string",
213-
"description": "Localization file to use for i18n.",
214-
"x-deprecated": "Use 'locales' object in the project metadata instead."
215-
},
216-
"i18nFormat": {
217-
"type": "string",
218-
"description": "Format of the localization file specified with --i18n-file.",
219-
"x-deprecated": "No longer needed as the format will be determined automatically."
220-
},
221-
"i18nLocale": {
222-
"type": "string",
223-
"description": "Locale to use for i18n.",
224-
"x-deprecated": "Use 'localize' instead."
225-
},
226211
"i18nMissingTranslation": {
227212
"type": "string",
228213
"description": "How to handle missing translations for i18n.",

packages/angular_devkit/build_angular/src/dev-server/index.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,7 @@ export function serveWebpackBrowser(
218218
}
219219

220220
let locale: string | undefined;
221-
if (browserOptions.i18nLocale) {
222-
// Deprecated VE option
223-
locale = browserOptions.i18nLocale;
224-
} else if (i18n.shouldInline) {
221+
if (i18n.shouldInline) {
225222
// Dev-server only supports one locale
226223
locale = [...i18n.inlineLocales][0];
227224
} else if (i18n.hasDefinedSourceLocale) {

packages/angular_devkit/build_angular/src/extract-i18n/index.ts

-3
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ export async function execute(
167167
vendor: true,
168168
},
169169
buildOptimizer: false,
170-
i18nLocale: i18n.sourceLocale,
171-
i18nFormat: format,
172-
i18nFile: outFile,
173170
aot: true,
174171
progress: options.progress,
175172
assets: [],

packages/angular_devkit/build_angular/src/server/schema.json

-15
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,6 @@
120120
"description": "Log progress to the console while building.",
121121
"default": true
122122
},
123-
"i18nFile": {
124-
"type": "string",
125-
"description": "Localization file to use for i18n.",
126-
"x-deprecated": "Use 'locales' object in the project metadata instead."
127-
},
128-
"i18nFormat": {
129-
"type": "string",
130-
"description": "Format of the localization file specified with --i18n-file.",
131-
"x-deprecated": "No longer needed as the format will be determined automatically."
132-
},
133-
"i18nLocale": {
134-
"type": "string",
135-
"description": "Locale to use for i18n.",
136-
"x-deprecated": "Use 'localize' instead."
137-
},
138123
"i18nMissingTranslation": {
139124
"type": "string",
140125
"description": "How to handle missing translations for i18n.",

packages/angular_devkit/build_angular/src/utils/build-options.ts

-6
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ export interface BuildOptions {
3535
deployUrl?: string;
3636
verbose?: boolean;
3737
progress?: boolean;
38-
/** @deprecated since version 9. Use 'locales' object in the project metadata instead.*/
39-
i18nFile?: string;
40-
/** @deprecated since version 9. No longer needed as the format will be determined automatically.*/
41-
i18nFormat?: string;
42-
/** @deprecated since version 9. Use 'localize' instead.*/
43-
i18nLocale?: string;
4438
localize?: Localize;
4539
i18nMissingTranslation?: I18NMissingTranslation;
4640
/** @deprecated since version 11.0. No longer required to disable CSS extraction for HMR.*/

packages/angular_devkit/build_angular/src/utils/i18n-options.ts

-95
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export interface I18nOptions {
3030
>;
3131
flatOutput?: boolean;
3232
readonly shouldInline: boolean;
33-
veCompatLocale?: string;
3433
hasDefinedSourceLocale?: boolean;
3534
}
3635

@@ -160,50 +159,9 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
160159

161160
const buildOptions = { ...options };
162161
const tsConfig = readTsconfig(buildOptions.tsConfig, context.workspaceRoot);
163-
const usingIvy = tsConfig.options.enableIvy !== false;
164162
const metadata = await context.getProjectMetadata(context.target);
165163
const i18n = createI18nOptions(metadata, buildOptions.localize);
166164

167-
// Until 11.0, support deprecated i18n options when not using new localize option
168-
// i18nFormat is automatically calculated
169-
if (buildOptions.localize === undefined && usingIvy) {
170-
mergeDeprecatedI18nOptions(i18n, buildOptions.i18nLocale, buildOptions.i18nFile);
171-
} else if (buildOptions.localize !== undefined && !usingIvy) {
172-
if (
173-
buildOptions.localize === true ||
174-
(Array.isArray(buildOptions.localize) && buildOptions.localize.length > 1)
175-
) {
176-
throw new Error(
177-
`Localization with multiple locales in one build is not supported with View Engine.`,
178-
);
179-
}
180-
181-
for (const deprecatedOption of ['i18nLocale', 'i18nFormat', 'i18nFile']) {
182-
// tslint:disable-next-line: no-any
183-
if (typeof (buildOptions as any)[deprecatedOption] !== 'undefined') {
184-
context.logger.warn(
185-
`Option 'localize' and deprecated '${deprecatedOption}' found. Using 'localize'.`,
186-
);
187-
}
188-
}
189-
190-
if (
191-
buildOptions.localize === false ||
192-
(Array.isArray(buildOptions.localize) && buildOptions.localize.length === 0)
193-
) {
194-
buildOptions.i18nFile = undefined;
195-
buildOptions.i18nLocale = undefined;
196-
buildOptions.i18nFormat = undefined;
197-
}
198-
}
199-
200-
// Clear deprecated options when using Ivy to prevent unintended behavior
201-
if (usingIvy) {
202-
buildOptions.i18nFile = undefined;
203-
buildOptions.i18nFormat = undefined;
204-
buildOptions.i18nLocale = undefined;
205-
}
206-
207165
// No additional processing needed if no inlining requested and no source locale defined.
208166
if (!i18n.shouldInline && !i18n.hasDefinedSourceLocale) {
209167
return { buildOptions, i18n };
@@ -298,31 +256,6 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
298256
desc.translation = loadResult.translations;
299257
}
300258
}
301-
302-
// Legacy message id's require the format of the translations
303-
if (usedFormats.size > 0) {
304-
buildOptions.i18nFormat = [...usedFormats][0];
305-
}
306-
307-
// Provide support for using the Ivy i18n options with VE
308-
if (!usingIvy) {
309-
i18n.veCompatLocale = buildOptions.i18nLocale = [...i18n.inlineLocales][0];
310-
311-
if (buildOptions.i18nLocale !== i18n.sourceLocale) {
312-
if (i18n.locales[buildOptions.i18nLocale].files.length > 1) {
313-
throw new Error(
314-
'Localization with View Engine only supports using a single translation file per locale.',
315-
);
316-
}
317-
buildOptions.i18nFile = i18n.locales[buildOptions.i18nLocale].files[0].path;
318-
}
319-
320-
// Clear inline locales to prevent any new i18n related processing
321-
i18n.inlineLocales.clear();
322-
323-
// Update the output path to include the locale to mimic Ivy localize behavior
324-
buildOptions.outputPath = path.join(buildOptions.outputPath, buildOptions.i18nLocale);
325-
}
326259
}
327260

328261
// If inlining store the output in a temporary location to facilitate post-processing
@@ -341,34 +274,6 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
341274
return { buildOptions, i18n };
342275
}
343276

344-
function mergeDeprecatedI18nOptions(
345-
i18n: I18nOptions,
346-
i18nLocale: string | undefined,
347-
i18nFile: string | undefined,
348-
): I18nOptions {
349-
if (i18nFile !== undefined && i18nLocale === undefined) {
350-
throw new Error(`Option 'i18nFile' cannot be used without the 'i18nLocale' option.`);
351-
}
352-
353-
if (i18nLocale !== undefined) {
354-
i18n.inlineLocales.clear();
355-
i18n.inlineLocales.add(i18nLocale);
356-
357-
if (i18nFile !== undefined) {
358-
i18n.locales[i18nLocale] = { files: [{ path: i18nFile }], baseHref: '' };
359-
} else {
360-
// If no file, treat the locale as the source locale
361-
// This mimics deprecated behavior
362-
i18n.sourceLocale = i18nLocale;
363-
i18n.locales[i18nLocale] = { files: [], baseHref: '' };
364-
}
365-
366-
i18n.flatOutput = true;
367-
}
368-
369-
return i18n;
370-
}
371-
372277
function findLocaleDataBasePath(projectRoot: string): string | null {
373278
try {
374279
const commonPath = path.dirname(

packages/angular_devkit/build_angular/src/utils/output-paths.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@ import { join } from 'path';
1010
import { I18nOptions } from './i18n-options';
1111

1212
export function ensureOutputPaths(baseOutputPath: string, i18n: I18nOptions): Map<string, string> {
13-
const outputPaths: [string, string][] =
14-
i18n.shouldInline
15-
? [...i18n.inlineLocales].map(l => [l, i18n.flatOutput ? baseOutputPath : join(baseOutputPath, l)])
16-
: [
17-
i18n.veCompatLocale
18-
? [i18n.veCompatLocale, join(baseOutputPath, i18n.veCompatLocale)]
19-
: ['', baseOutputPath],
20-
];
13+
const outputPaths: [string, string][] = i18n.shouldInline
14+
? [...i18n.inlineLocales].map(l => [l, i18n.flatOutput ? baseOutputPath : join(baseOutputPath, l)])
15+
: [['', baseOutputPath]];
2116

2217
for (const [, outputPath] of outputPaths) {
2318
if (!existsSync(outputPath)) {

tests/legacy-cli/e2e/tests/i18n/ivy-localize-basehref.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { expectFileToMatch } from '../../utils/fs';
99
import { ng } from '../../utils/process';
1010
import { updateJsonFile } from '../../utils/project';
11-
import { externalServer, langTranslations, setupI18nConfig } from './legacy';
11+
import { externalServer, langTranslations, setupI18nConfig } from './setup';
1212

1313
const baseHrefs = {
1414
'en-US': '/en/',
@@ -18,7 +18,7 @@ const baseHrefs = {
1818

1919
export default async function() {
2020
// Setup i18n tests and config.
21-
await setupI18nConfig(true);
21+
await setupI18nConfig();
2222

2323
// Update angular.json
2424
await updateJsonFile('angular.json', workspaceJson => {

tests/legacy-cli/e2e/tests/i18n/ivy-localize-dl-arb.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { executeTest } from './ivy-localize-dl-xliff2';
2-
import { setupI18nConfig } from './legacy';
2+
import { setupI18nConfig } from './setup';
33

44
export default async function() {
55
// Setup i18n tests and config.
6-
await setupI18nConfig(true, 'arb');
6+
await setupI18nConfig('arb');
77

88
// Execute the tests
99
await executeTest();

tests/legacy-cli/e2e/tests/i18n/ivy-localize-dl-json.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { executeTest } from './ivy-localize-dl-xliff2';
2-
import { setupI18nConfig } from './legacy';
2+
import { setupI18nConfig } from './setup';
33

44
export default async function() {
55
// Setup i18n tests and config.
6-
await setupI18nConfig(true, 'json');
6+
await setupI18nConfig('json');
77

88
// Execute the tests
99
await executeTest();

tests/legacy-cli/e2e/tests/i18n/ivy-localize-dl-xliff1.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { executeTest } from './ivy-localize-dl-xliff2';
2-
import { setupI18nConfig } from './legacy';
2+
import { setupI18nConfig } from './setup';
33

44
export default async function() {
55
// Setup i18n tests and config.
6-
await setupI18nConfig(true, 'xlf');
6+
await setupI18nConfig('xlf');
77

88
// Execute the tests
99
await executeTest();

tests/legacy-cli/e2e/tests/i18n/ivy-localize-dl-xliff2.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { appendToFile, expectFileToMatch, replaceInFile } from '../../utils/fs';
22
import { execAndWaitForOutputToMatch, killAllProcesses, ng } from '../../utils/process';
33
import { updateJsonFile } from '../../utils/project';
44
import { expectToFail } from '../../utils/utils';
5-
import { baseDir, externalServer, langTranslations, setupI18nConfig } from './legacy';
5+
import { baseDir, externalServer, langTranslations, setupI18nConfig } from './setup';
66

77
export default async function() {
88
// Setup i18n tests and config.
9-
await setupI18nConfig(true, 'xlf2');
9+
await setupI18nConfig('xlf2');
1010

1111
// Execute the tests
1212
await executeTest();

tests/legacy-cli/e2e/tests/i18n/ivy-localize-dl-xmb.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { executeTest } from './ivy-localize-dl-xliff2';
2-
import { setupI18nConfig } from './legacy';
2+
import { setupI18nConfig } from './setup';
33

44
export default async function() {
55
// Setup i18n tests and config.
6-
await setupI18nConfig(true, 'xmb');
6+
await setupI18nConfig('xmb');
77

88
// Execute the tests
99
await executeTest();

tests/legacy-cli/e2e/tests/i18n/ivy-localize-es2015.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expectFileNotToExist, expectFileToMatch, readFile, writeFile } from '..
22
import { ng } from '../../utils/process';
33
import { updateJsonFile } from '../../utils/project';
44
import { expectToFail } from '../../utils/utils';
5-
import { externalServer, langTranslations, setupI18nConfig } from './legacy';
5+
import { externalServer, langTranslations, setupI18nConfig } from './setup';
66

77
export default async function() {
88
// Setup i18n tests and config.

tests/legacy-cli/e2e/tests/i18n/ivy-localize-es5.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expectFileNotToExist, expectFileToMatch, readFile } from '../../utils/f
22
import { ng } from '../../utils/process';
33
import { updateJsonFile } from '../../utils/project';
44
import { expectToFail } from '../../utils/utils';
5-
import { externalServer, langTranslations, setupI18nConfig } from './legacy';
5+
import { externalServer, langTranslations, setupI18nConfig } from './setup';
66

77
export default async function() {
88
// Setup i18n tests and config.

tests/legacy-cli/e2e/tests/i18n/ivy-localize-hashes.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
import * as fs from 'fs';
99
import { appendToFile } from '../../utils/fs';
1010
import { ng } from '../../utils/process';
11-
import { langTranslations, setupI18nConfig } from './legacy';
11+
import { langTranslations, setupI18nConfig } from './setup';
1212

1313
const OUTPUT_RE = /^(?<name>(?:main|vendor|\d+))\.(?<hash>[a-z0-9]+)\.js$/i;
1414

1515
export default async function() {
1616
// Setup i18n tests and config.
17-
await setupI18nConfig(true);
17+
await setupI18nConfig();
1818

1919
// Build each locale and record output file hashes
2020
const hashes = new Map<string, string>();

tests/legacy-cli/e2e/tests/i18n/ivy-localize-locale-data-augment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expectFileToMatch, prependToFile, readFile, replaceInFile, writeFile } from '../../utils/fs';
22
import { ng } from '../../utils/process';
33
import { updateJsonFile } from '../../utils/project';
4-
import { externalServer, langTranslations, setupI18nConfig } from './legacy';
4+
import { externalServer, langTranslations, setupI18nConfig } from './setup';
55

66
export default async function() {
77
// Setup i18n tests and config.

tests/legacy-cli/e2e/tests/i18n/ivy-localize-locale-data.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*/
88
import { ng } from '../../utils/process';
99
import { updateJsonFile } from '../../utils/project';
10-
import { setupI18nConfig } from './legacy';
10+
import { setupI18nConfig } from './setup';
1111

1212
export default async function() {
1313
// Setup i18n tests and config.
14-
await setupI18nConfig(true);
14+
await setupI18nConfig();
1515

1616
// Update angular.json
1717
await updateJsonFile('angular.json', workspaceJson => {

tests/legacy-cli/e2e/tests/i18n/ivy-localize-merging.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*/
88
import { ng } from '../../utils/process';
99
import { updateJsonFile } from '../../utils/project';
10-
import { setupI18nConfig } from './legacy';
10+
import { setupI18nConfig } from './setup';
1111

1212
export default async function() {
1313
// Setup i18n tests and config.
14-
await setupI18nConfig(true);
14+
await setupI18nConfig();
1515

1616
// Update angular.json
1717
await updateJsonFile('angular.json', workspaceJson => {

tests/legacy-cli/e2e/tests/i18n/ivy-localize-server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { installWorkspacePackages } from '../../utils/packages';
66
import { ng } from '../../utils/process';
77
import { updateJsonFile } from '../../utils/project';
88
import { expectToFail } from '../../utils/utils';
9-
import { langTranslations, setupI18nConfig } from './legacy';
9+
import { langTranslations, setupI18nConfig } from './setup';
1010

1111
const snapshots = require('../../ng-snapshot/package.json');
1212

0 commit comments

Comments
 (0)