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): i18n compiler - i18nStart and i18nEnd support #26442
feat(ivy): i18n compiler - i18nStart and i18nEnd support #26442
Conversation
You can preview f5a6ef5 at https://pr26442-f5a6ef5.ngbuilds.io/. |
const $r2$ = {"i":[13]}; | ||
`; | ||
const template = String.raw ` | ||
const $MSG_APP_SPEC_TS_0$ = goog.getMsg("\uFFFD#0\uFFFDMy i18n block #1\uFFFD/#0\uFFFD"); |
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.
If I'm not mistaken, the div with the i18n attribute should not be in the generated message: \uFFFD#0\uFFFDMy i18n block #1\uFFFD/#0\uFFFD
--> My i18n block #1
. We only want what's inside that element.
Same thing for all examples below.
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.
Good catch, thanks! I've updated the code and the necessary tests to handle that.
}; | ||
|
||
const template = String.raw ` | ||
const $MSG_APP_SPEC_TS_0$ = goog.getMsg("\uFFFD#0\uFFFD My i18n block #\uFFFD0\uFFFD \uFFFD#2\uFFFDPlain text in nested element\uFFFD/#2\uFFFD\uFFFD/#0\uFFFD"); |
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.
There an extra space generated at the beginning: \uFFFD#0\uFFFD My i18n block
(before My
). This might be due to the line break, but we should not generate this. I think that the messages should be extracted with the option "whitespace removal" activated.
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.
Agree, I've added the code to trim the content while assembling i18n payload.
You can preview 471f857 at https://pr26442-471f857.ngbuilds.io/. |
@JoostK thanks for your comments! 👍 I've performed the necessary updates. |
You can preview 6002c8f at https://pr26442-6002c8f.ngbuilds.io/. |
You can preview e248127 at https://pr26442-e248127.ngbuilds.io/. |
if (rf & 1) { | ||
$r3$.ɵelementStart(0, "div"); | ||
$r3$.ɵi18nStart(1, $MSG_APP_SPEC_TS_0$); | ||
$r3$.ɵelementStart(2, "span"); |
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.
$r3$.ɵelementStart(2, "span"); | |
$r3$.ɵelement(2, "span"); |
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.
also consider i18n(..)
which merges start/end
$r3$.ɵelementStart(0, "div"); | ||
$r3$.ɵi18nStart(1, $MSG_APP_SPEC_TS_0$); | ||
$r3$.ɵelementStart(2, "span"); | ||
$r3$.ɵelementEnd(); |
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.
$r3$.ɵelementEnd(); |
const $msg_1$ = goog.getMsg("Hello world"); | ||
const $msg_2$ = goog.getMsg("farewell"); | ||
/** | ||
* @desc descA |
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.
* @desc descA | |
* @desc [BACKUP_MESSAGE_ID:idA] descA |
You can preview a4cda7d at https://pr26442-a4cda7d.ngbuilds.io/. |
You can preview fe2b743 at https://pr26442-fe2b743.ngbuilds.io/. |
You can preview e58233d at https://pr26442-e58233d.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. |
PR Description
This PR introduces
i18nStart
andi18nEnd
instructions support in i18n compiler, according to the I18n Design Doc. The main idea is to maintain an instance ofI18nContext
between start and end instructions, which keeps track of all i18n-related aspects (accumulates content, bindings, etc). When we enter a nested template (for ex. as a result of *ngIf), the top-level context is being passed down to the nested component, which uses this context to generate a child instance ofI18nContext
class (to handle nested template) and at the end, reconciles it back with the parent context.Notes
<ng-template i18n>
,<ng-content i18n>
and<ng-container i18n>
are not supported yet (coming next)goog.getMsg
generation remained as is (was not changed in this PR)Next steps (in followup PRs)
<ng-*>
tags supportConstantPool
refactoring to provide API to support Translation needs. Currently (historically) Translation-related logic to generate constants, is located inConstantPool
- we can probably extract it out toi18n.ts
.i18n
instruction in case there is no other content in betweeni18nStart
andi18nEnd
, a-laelement
instructionPR Type
Does this PR introduce a breaking change?