Skip to content
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

[localize] Extracting html within html in messages #2426

Closed
augustjk opened this issue Jan 20, 2022 · 0 comments · Fixed by #3674
Closed

[localize] Extracting html within html in messages #2426

augustjk opened this issue Jan 20, 2022 · 0 comments · Fixed by #3674
Assignees

Comments

@augustjk
Copy link
Member

Description

lit-localize extract does not properly handle html calls within html within msg.

Steps to Reproduce

Include the following code

msg(html`Hello <b>${html`<i>World</i>`}</b>!`, {id: "foo"});

And run lit-localize extract

Expected Results

<trans-unit id="foo">
  <source>Hello <x id="0" equiv-text="<b>${html`<i>World</i>`}</b>"/>!</source>
</trans-unit>

Actual Results

<trans-unit id="foo">
  <source>Hello <x id="0" equiv-text="&lt;b>"/>html `<x id="1" equiv-text="&lt;i>"/>World<x id="2" equiv-text="&lt;/i>${`}&lt;/b>"/>!</source>
</trans-unit>

Above results are for xliff format but similar results are seen for xlb format as well.

Workaround for now is probably not to use html within html to create a placeholder, something like

html`${msg('Hello')} <b><i>World</i></b>!`;

though that doesn't allow a translator to switch the order if that's necessary. Perhaps #1890 would allow this?

@aomarks aomarks self-assigned this Jan 20, 2022
@aomarks aomarks removed their assignment Jun 10, 2022
@aomarks aomarks self-assigned this Feb 16, 2023
aomarks added a commit that referenced this issue Feb 16, 2023
Fixes handling of nested html-tagged template expressions in lit localize analysis.

For example, the following example was analyzed incorrectly:

```ts
msg(html`Hello <b>${html`<i>World</i>`}</b>!`);
```

We combine runs of HTML markup and expressions so that we have fewer placeholders during translation, so we pass the template through an HTML parser, nested expressions and all. The problem was that if the nested expressions contained HTML, those would get parsed as part of the outer message, which would corrupt the analyzed template. The fix was to replace nested expressions with placeholders (the index) during HTML parsing (because we don't need the HTML parser to see the contents of expressions at all) and then substitute the original expression back after HTML parsing.

Fixes #2426
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants