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

(feature/advice) Parse HTML from JS strings #21

Open
MisterTicot opened this issue Feb 11, 2019 · 4 comments
Open

(feature/advice) Parse HTML from JS strings #21

MisterTicot opened this issue Feb 11, 2019 · 4 comments

Comments

@MisterTicot
Copy link

In my softwares, I have template literals from which I generate HTML components. Example:

new Gui(`<span><i18n>Hello</i18n>, %{name}!</span>`, { name: "Lukas" })

However, this "Hello" won't get extracted. So for now I do:

new Gui(`<span>${__("Hello")}, %{name}!</span>`, { name: "Lukas" })

However, this is a bad solution as translations can now inject html & executable scripts.

Is there any other way to make those translatable string extractable?

@lukasgeiter
Copy link
Owner

Hi, that's currently not possible out of the box, but it would certainly be possible to implement such a feature. Would you expect it to just parse every string as HTML or mark the relevant ones somehow (e.g. using tagged template literals) ?

@MisterTicot
Copy link
Author

MisterTicot commented Feb 12, 2019

I think ideally every string would be parsed including quote/double quote. I'm assuming the parser fails gracefully when the content is not HTML (I think it does), and that tags such as <i18n>...</i18n> don't happen mistakenly.

@lukasgeiter
Copy link
Owner

It certainly would. I'm a bit concerned about the performance impact this might have in a larger project with lots of non-html strings. I think the best idea is probably to implement both options, parsing all strings or only those which are marked with a certain tag.
I'll try to implement this in the next feature release. Unfortunately I can't give you an estimation on when it will be ready, but I'll let you know when the release is out.

@MisterTicot
Copy link
Author

That's awesome, looking forward for it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants