-
Notifications
You must be signed in to change notification settings - Fork 451
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
Template strings support in JS lexer #329
Comments
Entirely possible to implement! There are PRs in the pipeline to improve JSX and dotted name parsing (#310 and #298 respectively). However, a question: Are you planning to use template strings in conjunction with translation, like gettext(`Hi, ${name}!`)
// or to use the tag syntax,
i18n `Hi, ${name}!` or would you just like to see parser support for plain template strings? |
Well, I planned to use this way: new ScrollUp({
text: `▲<br><span> ${ _("back to top") } </span>`
}); But, actually, it's not the best idea to put markup directly to strings. |
Ah, that (parsing the (Mental note for implementation: Namely, before emitting a template string, find But sure, this definitely looks like something to implement along with the other JavaScript extraction improvements! :) |
@everyonesdesign If you're around, could you do code review on #332? :) |
@akx Anyway, new usecases of the translations in tests look really good, thanks for that great job. |
@everyonesdesign Yes, that support is not (yet) implemented; it could be done as further development . I just wanted to get some template string support in. :) |
Just ran into this problem as well, taking a look if I can find out how to improve the situation. |
Hmm, found out that my issues were caused by not recognizing the jsx tags themselves, the change in #396 gets it good enough for my need. While looking at this topic, I noticed that template strings can be nested:
Although this seems to produce odd results, it's probably not going to harm since the backticks come in pairs. |
I found this issue while troubleshooting extracting strings like the one below. Any updates on this? const text = `${variable} - ${gettext('some translated text')}`; |
Any updates on this? PR #332 references this as something included in that merged improvement, but this issue is still open and in my testing extraction from template strings does not work. Would be really nice to have support for this. We ended up with an untranslated string in production due to unawareness of this issue with extraction, and had to somewhat awkwardly restructure some code to ensure the gettext calls were outside template strings to make sure they got extracted. |
@fdanielsen Sorry to hear about the trouble! If I may inquire, how are you using template strings for translation at the moment? |
@akx Thanks for the quick response. In this case I was building up a string with some minor HTML formatting in addition to a translatable string: const description = `<em>${gettext('…')}</em>`; I've now changed it to simply extract the |
I've had issues with this for a while, so I decided to hack around. I got the JS template expressions working. These:
And it also works with nested expressions like:
I created a fork. You can try it out like this:
You have to enable template string extraction with an option in the
Then it should work. On this branch I also fixed another issue that I was facing. In a JS library that I use, there was regex with a Here you can see the diff of my fork: https://github.com/python-babel/babel/compare/master...gitaarik:javascript-improvements?expand=1 It works for me, and I'm very happy about it. Because now I can extract the messages from my es6 files instead of es5. That goes a lot faster, because of less clutter from polyfills in es5 files. But I'm not sure what needs to be done to merge this in the babel master. I don't know how to run the tests and if there needs to be unit tests added and how to etc. Are there people that can help me with this? Maybe @akx ? Edit:I created a PR now and all automatic checks seem to pass: #792 |
It seems that ECMAScript2015's Tempate strings breaks Babel's Javascript parsing.
That's sad, because it's supported quite well in latest browsers.
It would be great if Babel supported this feature.
The text was updated successfully, but these errors were encountered: