refactor(ivy): update the compiler to emit $localize
tags (#31609)
This commit changes the Angular compiler (ivy-only) to generate `$localize` tagged strings for component templates that use `i18n` attributes. BREAKING CHANGE Since `$localize` is a global function, it must be included in any applications that use i18n. This is achieved by importing the `@angular/localize` package into an appropriate bundle, where it will be executed before the renderer needs to call `$localize`. For CLI based projects, this is best done in the `polyfills.ts` file. ```ts import '@angular/localize'; ``` For non-CLI applications this could be added as a script to the index.html file or another suitable script file. PR Close #31609
This commit is contained in:

committed by
Misko Hevery

parent
b21397bde9
commit
fa79f51645
@ -37,3 +37,14 @@ export * from './core_render3_private_export';
|
||||
export {SecurityContext} from './sanitization/security';
|
||||
export {Sanitizer} from './sanitization/sanitizer';
|
||||
export * from './codegen_private_exports';
|
||||
|
||||
import {global} from './util/global';
|
||||
if (ngDevMode) {
|
||||
// This helper is to give a reasonable error message to people upgrading to v9 that have not yet
|
||||
// installed `@angular/localize` in their app.
|
||||
// tslint:disable-next-line: no-toplevel-property-access
|
||||
global.$localize = global.$localize || function() {
|
||||
throw new Error(
|
||||
'The global function `$localize` is missing. Please add `import \'@angular/localize\';` to your polyfills.ts file.');
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user