gettext-extractor
gettext-extractor copied to clipboard
(feature/advice) Parse HTML from JS strings
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?
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) ?
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.
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.
That's awesome, looking forward for it :)