Skip to content

Commit

Permalink
refactor(compiler): Record sub-messages as belonging to root i18n blo…
Browse files Browse the repository at this point in the history
…ck (#53209)

ICU sub-messages should be recorded as belonging to the message for the
root i18n block they are part of. This ensures that they still get
emitted even if they are nested in a child template.

PR Close #53209
  • Loading branch information
mmalerba authored and pkozlowski-opensource committed Nov 29, 2023
1 parent d121e4e commit 7873678
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
]
}
],
"skipForTemplatePipeline": true
"focusTest": true
},
{
"description": "should handle icus with interpolations",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ const LIST_DELIMITER = '|';
* used in the final output.
*/
export function extractI18nMessages(job: CompilationJob): void {
// Save the i18n context ops for later use.
// Save the i18n start and i18n context ops for later use.
const i18nContexts = new Map<ir.XrefId, ir.I18nContextOp>();
const i18nBlocks = new Map<ir.XrefId, ir.I18nStartOp>();
for (const unit of job.units) {
for (const op of unit.create) {
switch (op.kind) {
case ir.OpKind.I18nContext:
i18nContexts.set(op.xref, op);
break;
case ir.OpKind.I18nStart:
i18nBlocks.set(op.xref, op);
break;
}
}
}
Expand Down Expand Up @@ -94,7 +98,8 @@ export function extractI18nMessages(job: CompilationJob): void {
if (i18nContext.contextKind === ir.I18nContextKind.Icu) {
const subMessage = createI18nMessage(job, i18nContext, op.messagePlaceholder);
unit.create.push(subMessage);
const parentMessage = i18nBlockMessages.get(i18nContext.i18nBlock);
const rootI18nId = i18nBlocks.get(i18nContext.i18nBlock)!.root;
const parentMessage = i18nBlockMessages.get(rootI18nId);
parentMessage?.subMessages.push(subMessage.xref);
}
ir.OpList.remove<ir.CreateOp>(op);
Expand Down

0 comments on commit 7873678

Please sign in to comment.