Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): temporarily disable localize for …
Browse files Browse the repository at this point in the history
…multiple locales

Related to angular#15974
  • Loading branch information
filipesilva authored and vikerman committed Oct 30, 2019
1 parent b9aad55 commit 1812c82
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 27 deletions.
21 changes: 16 additions & 5 deletions packages/angular_devkit/build_angular/src/utils/i18n-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,21 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
context: BuilderContext,
options: T,
): Promise<{
buildOptions: T,
i18n: I18nOptions,
buildOptions: T;
i18n: I18nOptions;
}> {
if (!context.target) {
throw new Error('The builder requires a target.');
}

const buildOptions = { ... options };
const buildOptions = { ...options };

if (
buildOptions.localize === true ||
(Array.isArray(buildOptions.localize) && buildOptions.localize.length > 1)
) {
throw new Error('Using the localize option for multiple locales is temporarily disabled.');
}

const tsConfig = readTsconfig(buildOptions.tsConfig, context.workspaceRoot);
const usingIvy = tsConfig.options.enableIvy !== false;
Expand Down Expand Up @@ -162,14 +169,18 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
process.on('exit', () => {
try {
rimraf.sync(tempPath);
} catch { }
} catch {}
});
}

return { buildOptions, i18n };
}

function mergeDeprecatedI18nOptions(i18n: I18nOptions, i18nLocale: string | undefined, i18nFile: string | undefined): I18nOptions {
function mergeDeprecatedI18nOptions(
i18n: I18nOptions,
i18nLocale: string | undefined,
i18nFile: string | undefined,
): I18nOptions {
if (i18nFile !== undefined && i18nLocale === undefined) {
throw new Error(`Option 'i18nFile' cannot be used without the 'i18nLocale' option.`);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/legacy-cli/e2e/tests/build/aot/aot-i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export default async function () {
},
];

await replaceInFile('src/app/app.component.ts', `title = 'test-project';`, `title = 'test-project';minutes=3;`);

await updateJsonFile('angular.json', workspaceJson => {
const appArchitect = workspaceJson.projects['test-project'].architect;
const browserConfigs = appArchitect['build'].configurations;
Expand Down
3 changes: 3 additions & 0 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-app-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { readNgVersion } from '../../utils/version';
const snapshots = require('../../ng-snapshot/package.json');

export default async function () {
// TEMP: disable pending i18n updates
return;

const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];

await updateJsonFile('package.json', packageJson => {
Expand Down
16 changes: 12 additions & 4 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-dl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export default async function() {

// Set configurations for each locale.
const langTranslations = [
{ lang: 'en-US', translation: 'Hello i18n!' },
// TODO: re-enable all locales once localeData support is added.
// { lang: 'en-US', translation: 'Hello i18n!' },
{ lang: 'fr', translation: 'Bonjour i18n!' },
];

Expand All @@ -53,7 +54,11 @@ export default async function() {
];

// Enable localization for all locales
appArchitect['build'].options.localize = true;
// TODO: re-enable all locales once localeData support is added.
// appArchitect['build'].options.localize = true;
appArchitect['build'].options.localize = ['fr'];
// Always error on missing translations.
appArchitect['build'].options.i18nMissingTranslation = 'error';

// Add locale definitions to the project
// tslint:disable-next-line: no-any
Expand Down Expand Up @@ -103,7 +108,10 @@ export default async function() {
}

// Build each locale and verify the output.
await ng('build', '--i18n-missing-translation', 'error');
// NOTE: this should not fail in general, but multi-locale translation is currently disabled.
// TODO: remove expectToFail once localeData support is added.
await expectToFail(() => ng('build', '--localize', 'true'));
await ng('build');
for (const { lang, translation } of langTranslations) {
await expectFileToMatch(`${baseDir}/${lang}/main-es5.js`, translation);
await expectFileToMatch(`${baseDir}/${lang}/main-es2015.js`, translation);
Expand Down Expand Up @@ -155,5 +163,5 @@ export default async function() {
await ng('build', '--i18n-missing-translation', 'ignore');
await expectFileToMatch(`${baseDir}/fr/main-es5.js`, /Other content/);
await expectFileToMatch(`${baseDir}/fr/main-es2015.js`, /Other content/);
await expectToFail(() => ng('build', '--i18n-missing-translation', 'error'));
await expectToFail(() => ng('build'));
}
16 changes: 10 additions & 6 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-es2015.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ export default async function() {

// Set configurations for each locale.
const langTranslations = [
{ lang: 'en-US', translation: 'Hello i18n!' },
// TODO: re-enable all locales once localeData support is added.
// { lang: 'en-US', translation: 'Hello i18n!' },
// { lang: 'de', translation: 'Hallo i18n!' },
{ lang: 'fr', translation: 'Bonjour i18n!' },
{ lang: 'de', translation: 'Hallo i18n!' },
];

await updateJsonFile('angular.json', workspaceJson => {
Expand All @@ -55,7 +56,11 @@ export default async function() {
];

// Enable localization for all locales
appArchitect['build'].options.localize = true;
// TODO: re-enable all locales once localeData support is added.
// appArchitect['build'].options.localize = true;
appArchitect['build'].options.localize = ['fr'];
// Always error on missing translations.
appArchitect['build'].options.i18nMissingTranslation = 'error';

// Add locale definitions to the project
// tslint:disable-next-line: no-any
Expand Down Expand Up @@ -102,8 +107,7 @@ export default async function() {
}
}

// Build each locale and verify the output.
await ng('build', '--i18n-missing-translation', 'error');
await ng('build');
for (const { lang, translation } of langTranslations) {
await expectFileToMatch(`${baseDir}/${lang}/main.js`, translation);
await expectToFail(() => expectFileToMatch(`${baseDir}/${lang}/main.js`, '$localize`'));
Expand Down Expand Up @@ -147,5 +151,5 @@ export default async function() {
await appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
await ng('build', '--i18n-missing-translation', 'ignore');
await expectFileToMatch(`${baseDir}/fr/main.js`, /Other content/);
await expectToFail(() => ng('build', '--i18n-missing-translation', 'error'));
await expectToFail(() => ng('build'));
}
19 changes: 14 additions & 5 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-es5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ export default async function() {

// Set configurations for each locale.
const langTranslations = [
{ lang: 'en-US', translation: 'Hello i18n!' },
// TODO: re-enable all locales once localeData support is added.
// { lang: 'en-US', translation: 'Hello i18n!' },
// { lang: 'de', translation: 'Hallo i18n!' },
{ lang: 'fr', translation: 'Bonjour i18n!' },
{ lang: 'de', translation: 'Hallo i18n!' },
];

await updateJsonFile('angular.json', workspaceJson => {
Expand All @@ -54,7 +55,11 @@ export default async function() {
];

// Enable localization for all locales
appArchitect['build'].options.localize = true;
// TODO: re-enable all locales once localeData support is added.
// appArchitect['build'].options.localize = true;
appArchitect['build'].options.localize = ['fr'];
// Always error on missing translations.
appArchitect['build'].options.i18nMissingTranslation = 'error';

// Add locale definitions to the project
// tslint:disable-next-line: no-any
Expand Down Expand Up @@ -102,7 +107,7 @@ export default async function() {
}

// Build each locale and verify the output.
await ng('build', '--i18n-missing-translation', 'error');
await ng('build');
for (const { lang, translation } of langTranslations) {
await expectFileToMatch(`${baseDir}/${lang}/main.js`, translation);
await expectToFail(() => expectFileToMatch(`${baseDir}/${lang}/main.js`, '$localize`'));
Expand Down Expand Up @@ -142,9 +147,13 @@ export default async function() {
}
}

// Verify locale data registration (currently only for single locale builds)
await ng('build', '--optimization', 'false', '--i18n-missing-translation', 'error');
await expectFileToMatch(`${baseDir}/fr/main.js`, 'registerLocaleData');

// Verify missing translation behaviour.
await appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
await ng('build', '--i18n-missing-translation', 'ignore');
await expectFileToMatch(`${baseDir}/fr/main.js`, /Other content/);
await expectToFail(() => ng('build', '--i18n-missing-translation', 'error'));
await expectToFail(() => ng('build'));
}
19 changes: 13 additions & 6 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export default async function () {

// Set configurations for each locale.
const langTranslations = [
{ lang: 'en-US', translation: 'Hello i18n!' },
// TODO: re-enable all locales once localeData support is added.
// { lang: 'en-US', translation: 'Hello i18n!' },
{ lang: 'fr', translation: 'Bonjour i18n!' },
];

Expand Down Expand Up @@ -72,8 +73,14 @@ export default async function () {
];

// Enable localization for all locales
buildOptions.localize = true;
serverOptions.localize = true;
// TODO: re-enable all locales once localeData support is added.
// buildOptions.localize = true;
// serverOptions.localize = true;
buildOptions.localize = ['fr'];
serverOptions.localize = ['fr'];
// Always error on missing translations.
buildOptions.i18nMissingTranslation = 'error';
serverOptions.i18nMissingTranslation = 'error';

// Add locale definitions to the project
// tslint:disable-next-line: no-any
Expand Down Expand Up @@ -158,8 +165,8 @@ export default async function () {
}

// Build each locale and verify the output.
await ng('build', '--i18n-missing-translation', 'error');
await ng(...serverBuildArgs, '--i18n-missing-translation', 'error');
await ng('build');
await ng(...serverBuildArgs);

for (const { lang, translation } of langTranslations) {
await expectFileToMatch(`${serverbaseDir}/${lang}/main.js`, translation);
Expand Down Expand Up @@ -205,5 +212,5 @@ export default async function () {
await appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
await ng(...serverBuildArgs, '--i18n-missing-translation', 'ignore');
await expectFileToMatch(`${serverbaseDir}/fr/main.js`, /Other content/);
await expectToFail(() => ng(...serverBuildArgs, '--i18n-missing-translation', 'error'));
await expectToFail(() => ng(...serverBuildArgs));
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { expectToFail } from '../../utils/utils';
import { readNgVersion } from '../../utils/version';

export default async function() {
// TEMP: disable pending i18n updates
return;

let localizeVersion = '@angular/localize@' + readNgVersion();
if (getGlobalVariable('argv')['ng-snapshots']) {
localizeVersion = require('../../ng-snapshot/package.json').dependencies['@angular/localize'];
Expand Down Expand Up @@ -62,7 +65,7 @@ export default async function() {
appArchitect['build'].options.serviceWorker = true;

// Enable localization for all locales
appArchitect['build'].options.localize = true;
// appArchitect['build'].options.localize = true;

// Add locale definitions to the project
// tslint:disable-next-line: no-any
Expand Down

0 comments on commit 1812c82

Please sign in to comment.