-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular-devkit/build-angular): augment base HREF when localizing
All locale i18n options now support an object form which allows a base HREF to be defined for the locale. Each locale can now optionally define a custom base HREF that will be combined with the base HREF defined for the build configuration. By default if the shorthand form for the locale is used or the field is not present in the longhand form, the locale code will be used as the base HREF. To disable automatic augmentation a base HREF value of an empty string (`""`) can be used. This will prevent anything from being added to the existing base HREF. For common scenarios, the shorthand form will result in the preferred and recommended outcome of each built locale variant of the application containing a defined base HREF containing the locale code. (cherry picked from commit c37eaee)
- Loading branch information
Showing
10 changed files
with
296 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
tests/legacy-cli/e2e/tests/i18n/ivy-localize-basehref.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import { expectFileToMatch } from '../../utils/fs'; | ||
import { ng } from '../../utils/process'; | ||
import { updateJsonFile } from '../../utils/project'; | ||
import { externalServer, langTranslations, setupI18nConfig } from './legacy'; | ||
|
||
const baseHrefs = { | ||
'en-US': '/en/', | ||
fr: '/fr-FR/', | ||
de: '', | ||
}; | ||
|
||
export default async function() { | ||
// Setup i18n tests and config. | ||
await setupI18nConfig(true); | ||
|
||
// Update angular.json | ||
await updateJsonFile('angular.json', workspaceJson => { | ||
const appProject = workspaceJson.projects['test-project']; | ||
// tslint:disable-next-line: no-any | ||
const i18n: Record<string, any> = appProject.i18n; | ||
|
||
i18n.sourceLocale = { | ||
baseHref: baseHrefs['en-US'], | ||
}; | ||
|
||
i18n.locales['fr'] = { | ||
translation: i18n.locales['fr'], | ||
baseHref: baseHrefs['fr'], | ||
}; | ||
|
||
i18n.locales['de'] = { | ||
translation: i18n.locales['de'], | ||
baseHref: baseHrefs['de'], | ||
}; | ||
}); | ||
|
||
// Build each locale and verify the output. | ||
await ng('build'); | ||
for (const { lang, outputPath } of langTranslations) { | ||
if (baseHrefs[lang] === undefined) { | ||
throw new Error('Invalid E2E test setup: unexpected locale ' + lang); | ||
} | ||
|
||
// Verify the HTML lang attribute is present | ||
await expectFileToMatch(`${outputPath}/index.html`, `lang="${lang}"`); | ||
|
||
// Verify the HTML base HREF attribute is present | ||
await expectFileToMatch(`${outputPath}/index.html`, `href="${baseHrefs[lang] || '/'}"`); | ||
|
||
// Execute Application E2E tests with dev server | ||
await ng('e2e', `--configuration=${lang}`, '--port=0'); | ||
|
||
// Execute Application E2E tests for a production build without dev server | ||
const server = externalServer(outputPath, baseHrefs[lang] || '/'); | ||
try { | ||
await ng( | ||
'e2e', | ||
`--configuration=${lang}`, | ||
'--devServerTarget=', | ||
`--baseUrl=http://localhost:4200${baseHrefs[lang] || '/'}`, | ||
); | ||
} finally { | ||
server.close(); | ||
} | ||
} | ||
|
||
// Update angular.json | ||
await updateJsonFile('angular.json', workspaceJson => { | ||
const appArchitect = workspaceJson.projects['test-project'].architect; | ||
|
||
appArchitect['build'].options.baseHref = '/test/'; | ||
}); | ||
|
||
// Build each locale and verify the output. | ||
await ng('build'); | ||
for (const { lang, outputPath } of langTranslations) { | ||
// Verify the HTML base HREF attribute is present | ||
await expectFileToMatch(`${outputPath}/index.html`, `href="/test${baseHrefs[lang] || '/'}"`); | ||
|
||
// Execute Application E2E tests with dev server | ||
await ng('e2e', `--configuration=${lang}`, '--port=0'); | ||
|
||
// Execute Application E2E tests for a production build without dev server | ||
const server = externalServer(outputPath, '/test' + (baseHrefs[lang] || '/')); | ||
try { | ||
await ng( | ||
'e2e', | ||
`--configuration=${lang}`, | ||
'--devServerTarget=', | ||
`--baseUrl=http://localhost:4200/test${baseHrefs[lang] || '/'}`, | ||
); | ||
} finally { | ||
server.close(); | ||
} | ||
} | ||
} |
Oops, something went wrong.