-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
i18n with ivy breaks the injection of translated attribute #38231
Comments
Note that this involves an |
Some further analysis... the generated ivy instructions for the template look like: i0.ɵɵelement(0, "div", 0);
i0.ɵɵelementStart(1, "div", 1);
i0.ɵɵi18nAttributes(2, 2);
i0.ɵɵelementEnd(); When this code executes the i18n messages have been computed and are stored in the constants array for this view:
The call to The next call to |
The
Clearly it cannot do the second part until after the element has been created (in
|
@AndrewKushnir and I discussed this. It turns out that we can probably do even better than splitting the instruction, as described above. The point is that only attributes that hold static text can be injected into directives via the At compile time we are able to work out if i18n messages are static (i.e. ones that have no placeholders for things like interpolation, ICUs, nested elements etc). In such cases there is no need to do any runtime i18n manipulation of the value, it should just be applied as a constant directly to the attribute just like a non-i18n attribute value. This would solve this bug, but also allow us to remove invocations of i18n instructions for those cases, making the generated code smaller and the runtime faster. So to be more concrete, the generated could would now have the following constants array:
where the And the instructions for this scenario would simply be:
Obviously in cases where the i18n message has dynamic elements, we would use the current instructions, which would preclude the value from being injected via |
…butes Currently `i18n` attributes are treated the same no matter if they have data bindings or not. This both generates more code since they have to go through the `ɵɵi18nAttributes` instruction and prevents the translated attributes from being injected using the `@Attribute` decorator. These changes makes it so that static translated attributes are treated in the same way as regular static attributes and all other `i18n` attributes go through the old code path. Fixes angular#38231.
…butes (#39408) Currently `i18n` attributes are treated the same no matter if they have data bindings or not. This both generates more code since they have to go through the `ɵɵi18nAttributes` instruction and prevents the translated attributes from being injected using the `@Attribute` decorator. These changes makes it so that static translated attributes are treated in the same way as regular static attributes and all other `i18n` attributes go through the old code path. Fixes #38231. PR Close #39408
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 bug report
Affected Package
The issue is caused by package @angular/localize.
Is this a regression?
Yes, this issue is reproducible only with Ivy. With ViewEngine it works fine.
Description
Injecting the attribute to the component/directive that is translated using
i18n
is always resulting innull
.Example:
text
is a directive that reads thetext
attribute and simply adds the following text to the host element:Code:
Resulting HTML:
Observed in the result above,
text
attribute is properly set toText with i18n
, while the injected value remainsnull
.🔬 Minimal Reproduction
https://stackblitz.com/edit/angular-ivy-uzgvwe
You can observe
null
as described above.To make this example work, open settings and uncheck
Enable Ivy
. Now ViewEngine will be used to compile the application, and thenull
text will be replaced byText with i18n
.🌍 Your Environment
Angular CLI: 10.0.4
Node: 12.16.3
OS: linux x64
Angular: 10.0.5
... animations, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
@angular-devkit/architect 0.1000.4
@angular-devkit/build-angular 0.1000.4
@angular-devkit/build-optimizer 0.1000.4
@angular-devkit/build-webpack 0.1000.4
@angular-devkit/core 10.0.4
@angular-devkit/schematics 10.0.4
@angular/cli 10.0.4
@ngtools/webpack 10.0.4
@schematics/angular 10.0.4
@schematics/update 0.1000.4
rxjs 6.5.5
typescript 3.9.7
webpack 4.43.0
The text was updated successfully, but these errors were encountered: