-
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
feat(ivy): ICU support for Ivy (compiler side) #26794
feat(ivy): ICU support for Ivy (compiler side) #26794
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like @alxhub to have a look at the compiler details as he is more familiar with it. Left comments on the generated code.
packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things to change, see my inline comments.
And check with @mhevery if we should apply the whitespace removal, and also if we should keep empty translations or not.
packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
782184c
to
aba5e42
Compare
9699edf
to
5497d11
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First round of comments.
In general, I notice that <element>.i18n !
happens a lot - we're constantly asserting in this PR that i18n
fields are not null. I think this indicates a more fundamental issue with the typings. Can you think of any way to avoid this? I've not really studied the problem deeply but I do have one observation which might be helpful.
Part of the problem comes up at the boundary between i18n-processing code and the larger TemplateDefinitionBuilder
. We do things like:
if (element.i18n) {
// i18n field is known to be defined here.
doSomethingWithElement(element);
}
function doSomethingWithElement(element: t.Element) {
// element.i18n is not known to be defined, so assertion is required.
console.log(element.i18n !);
}
Instead of this pattern, we could make functions on the boundary to which i18n-enabled nodes are passed have signatures like:
function doSomethingWithElement(element: t.Element & {i18n: I18nType})
This way:
- we can only call the function on a
t.Element
with a validi18n
field. - we don't lose that information in the body of the function, and thus don't need the assertion.
This gets the type system working with us and not against us.
Make sense?
a93f974
to
ff4a7ba
Compare
235538b
to
a1bb4be
Compare
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) |
You can preview a1bb4be at https://pr26794-a1bb4be.ngbuilds.io/. |
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. |
The goal of this PR is to add I18n ICU support to IVY compiler. In order to satisfy the backwards (and forward) compatibility requirement, the logic of producing translation messages (
goog.getMsg
at this moment) mimics existingng xi18n
machinery output, specifically:The I18n AST (which is used to power
ng xi18n
mechanics) was employed to minimize discrepancies between theng xi18n
output and IVY compiler output. Nodes within I18n sections now have references to their canonical representation in i18n AST, which helps maintain output consistency.Update (11/8)
As a part of this PR, the following logic was implemented:
goog.getMsg
output, since the placeholders might not be unique (for ex.CLOSE_TAG_DIV
can be used multiple times, but we have to have different references/indices). Right now in such cases we put a specially-formatted string that contains these combinations (for ex.[�/#1�|�/#4:3�|�7:4�]
). The post-processing step assembles the final string at runtime, based on this information.ConstanlPool
was refactored and all i18n-related code was moved away<ng-container i18n>
)<ng-template i18n>
goog.getMsg
was improved to generate compatible translation strings and respective placeholders in appropriate formati18n
self-closing instruction (in case there are no elements betweeni18nStart
andi18nEnd
)This PR now completes the main set of features required for i18n compiler.
PR Type
What kind of change does this PR introduce?
Does this PR introduce a breaking change?