{ "id": "guide/migration-localize", "title": "$localize Global Import Migration", "contents": "\n\n\n
$localize Global Import MigrationlinkIf you're using i18n, this schematic adds an import statement for @angular/localize to polyfills.ts that will look something like this:
It also lists @angular/localize as a dependency in your app's package.json to ensure the import is found.
@angular/localize is a new package that supports i18n of messages in Ivy applications.\nThis package requires a global $localize symbol to exist.\nThe symbol is loaded by importing the @angular/localize/init module, which has the side-effect of attaching it to the global scope.
Prior to Angular version 9, Angular's internationalization (i18n) system inlined translated messages into the compiled output as part of this template compilation.\nThis approach required running the template compiler once per target locale, often leading to slow production build times.
\nIn the new i18n system, the Angular compiler tags i18n messages in the compiled code with a global $localize handler.\nThe inlining of translations then occurs as a post-compilation step for each locale.\nBecause the application does not need to be built again for each locale, this makes the process much faster.
The post-compilation inlining step is optional—for example during development or if the translations will be inlined at runtime.\nTherefore this global $localize must be available on the global scope at runtime.\nTo make $localize available on the global scope, each application must now import the @angular/localize/init module.\nThis has the side-effect of attaching a minimal implementation of $localize to the global scope.
If this import is missing, you will see an error message like this:
\nThis schematic automatically adds the @angular/localize/init import for you\nif your app uses Angular's i18n APIs.
The import of @angular/localize/init may cause a tslint error for no-import-side-effect because it adds to the global context (that is, a side effect).\nTo fix this error, add the following to your tslint.config:
The template syntax for i18n has not changed, so you will still want to use the i18n attribute as you did before.