Skip to content

Commit

Permalink
feat(@angular-devkit/build-angular): optimize i18n localize usage in …
Browse files Browse the repository at this point in the history
…source locale
  • Loading branch information
clydin authored and vikerman committed Oct 17, 2019
1 parent cf116da commit cda57ae
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/angular_devkit/build_angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
},
"peerDependencies": {
"@angular/compiler-cli": ">=9.0.0-beta < 10",
"@angular/localize": "^9.0.0-next.10",
"@angular/localize": "^9.0.0-next.11",
"typescript": ">=3.6 < 3.7"
},
"peerDependenciesMeta": {
Expand Down
20 changes: 3 additions & 17 deletions packages/angular_devkit/build_angular/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,30 +459,15 @@ export function buildWebpackBrowser(

const diagnostics = new localizeDiag.Diagnostics();
const translationFilePaths = [];
let copySourceLocale = false;
let handleSourceLocale = false;
for (const locale of i18n.inlineLocales) {
if (locale === i18n.sourceLocale) {
copySourceLocale = true;
handleSourceLocale = true;
continue;
}
translationFilePaths.push(i18n.locales[locale].file);
}

if (copySourceLocale) {
await copyAssets(
[
{
glob: '**/*',
// tslint:disable-next-line: no-non-null-assertion
input: webpackStats.outputPath!,
output: i18n.sourceLocale,
},
],
[baseOutputPath],
'',
);
}

if (translationFilePaths.length > 0) {
const sourceFilePaths = [];
for (const result of processResults) {
Expand All @@ -503,6 +488,7 @@ export function buildWebpackBrowser(
path.join(baseOutputPath, locale, relativePath),
diagnostics,
missingTranslation: options.i18nMissingTranslation || 'warning',
sourceLocale: handleSourceLocale ? i18n.sourceLocale : undefined,
});
} catch (err) {
context.logger.error('Localized bundle generation failed: ' + err.message);
Expand Down
6 changes: 2 additions & 4 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ export default async function() {
}
await npm('install', `${localizeVersion}`);

// Temporarily add the localize "polyfill" -- release version will not need this
// TODO: Remove after next framework release
await appendToFile('src/polyfills.ts', '\nimport "@angular/localize/init";');

const baseDir = 'dist/test-project';

// Set configurations for each locale.
Expand Down Expand Up @@ -108,6 +104,8 @@ export default async function() {
for (const { lang, translation } of langTranslations) {
await expectFileToMatch(`${baseDir}/${lang}/main-es5.js`, translation);
await expectFileToMatch(`${baseDir}/${lang}/main-es2015.js`, translation);
await expectToFail(() => expectFileToMatch(`${baseDir}/${lang}/main-es5.js`, '$localize'));
await expectToFail(() => expectFileToMatch(`${baseDir}/${lang}/main-es2015.js`, '$localize'));

// Ivy i18n doesn't yet work with `ng serve` so we must use a separate server.
const app = express();
Expand Down

0 comments on commit cda57ae

Please sign in to comment.