Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular-devkit/build-angular): set HTML lang attribute when serving #19090

Merged
merged 1 commit into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/angular_devkit/build_angular/src/dev-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export function serveWebpackBrowser(
webpackConfig: webpack.Configuration;
webpackDevServerConfig: WebpackDevServer.Configuration;
projectRoot: string;
locale: string | undefined;
}> {
// Get the browser configuration from the target name.
const rawBrowserOptions = await context.getTargetOptions(browserTarget);
Expand Down Expand Up @@ -151,11 +152,13 @@ export function serveWebpackBrowser(
webpackConfig,
webpackDevServerConfig,
projectRoot,
locale:
browserOptions.i18nLocale || (i18n.shouldInline ? [...i18n.inlineLocales][0] : undefined),
};
}

return from(setup()).pipe(
switchMap(({ browserOptions, webpackConfig, webpackDevServerConfig, projectRoot }) => {
switchMap(({ browserOptions, webpackConfig, webpackDevServerConfig, projectRoot, locale }) => {
// Resolve public host and client address.
let clientAddress = url.parse(`${options.ssl ? 'https' : 'http'}://0.0.0.0:0`);
if (options.publicHost) {
Expand Down Expand Up @@ -212,7 +215,7 @@ export function serveWebpackBrowser(
noModuleEntrypoints: ['polyfills-es5'],
postTransform: transforms.indexHtml,
crossOrigin: browserOptions.crossOrigin,
lang: browserOptions.i18nLocale,
lang: locale,
}),
);
}
Expand Down
38 changes: 38 additions & 0 deletions packages/angular_devkit/build_angular/src/dev-server/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,42 @@ describe('Dev Server Builder index', () => {
);
await run.stop();
});

it('sets HTML lang attribute with the active locale', async () => {
const locale = 'fr';
const { workspace } = await workspaces.readWorkspace(host.root(), workspaces.createWorkspaceHost(host));
const app = workspace.projects.get('app');
if (!app) {
fail('Test application "app" not found.');

return;
}

app.extensions['i18n'] = {
locales: {
[locale]: [],
},
};

const target = app.targets.get('build');
if (!target) {
fail('Test application "app" target "build" not found.');

return;
}
if (!target.options) {
target.options = {};
}
target.options.localize = [locale];

await workspaces.writeWorkspace(workspace, workspaces.createWorkspaceHost(host));

const architect = (await createArchitect(host.root())).architect;
const run = await architect.scheduleTarget(targetSpec);
const output = (await run.result) as DevServerBuilderOutput;
expect(output.success).toBe(true);
const response = await fetch('http://localhost:4200/index.html');
expect(await response.text()).toContain(`lang="${locale}"`);
await run.stop();
});
});